using System; using Microsoft.SPOT; using System.Text; using System.Threading; namespace abstractState { public class InitMission : StateBase { private enum Action : int { stateEntry = 0, moveBellowsInsideLimits, checkBellowsMovement, sendSBE41_DS, sendOptodeGetAll, initFLBB, lastAction } private Action currentAction = Action.stateEntry; public InitMission(string name) { stateName.Clear(); stateName.Append(name); ECTimeout = 50000; } public override int doStateActions() { int returnValue = 0; //It would be nice to figure out a way to make this a loop. Delegates would work but they require a new. switch (currentAction) { case(Action.stateEntry): Debug.Print("InitMission State Entry"); basicStateEntry(); //These should probably be inside class constructor //sbConsoleCommand.Clear(); //sbConsoleCommand.Append("NONE"); returnValue = 0; currentAction = Action.moveBellowsInsideLimits; break; case (Action.moveBellowsInsideLimits): returnValue = moveBellowsInsideLimits(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission moveBellowsInsideLimits"); break; case (Action.checkBellowsMovement): returnValue = checkBellowsMovement(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission checkBellowsMovement"); break; case (Action.sendSBE41_DS): returnValue = sendSBE41_DS(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission sendSBE41_DS"); break; case (Action.sendOptodeGetAll): returnValue = sendOptodeGetAll(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission sendOptodeGetAll"); break; case (Action.initFLBB): returnValue = initFLBB(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission initFLBB"); break; case (Action.lastAction): break; } return (returnValue); } public override Program.CPFStates checkEvents() { if (currentAction == Action.lastAction) return (Program.CPFStates.initProfile); else return (Program.CPFStates.initMission); } public override Program.CPFStates doTimeoutAction() { return (Program.CPFStates.initProfile); } private static int moveBellowsInsideLimits() { //Just in case the bellows was outside the limits, put it inside the limits if (SV.bellowsPosition > (BuoyancyControl.bellowsUpperLimit - 2.0)) { sbTemp.Clear(); sbTemp.Append("Retracting bellows inside limits"); //EngrLogger.writeToColumns(sbTemp); if (!Elmo.retracting) Elmo.retractBellows(10000); return ((int)Action.moveBellowsInsideLimits); } else if (SV.bellowsPosition < (BuoyancyControl.bellowsLowerLimit + 2.0)) { sbTemp.Clear(); sbTemp.Append("Extending bellows inside limits"); //EngrLogger.writeToColumns(sbTemp); if (!Elmo.extending) Elmo.extendBellows(10000); return ((int)Action.moveBellowsInsideLimits); } else { Elmo.stopMotor(); Debug.Print("Bellows inside limits"); return ((int)Action.checkBellowsMovement); } } //this is just for initial testing private static int callCount = 0; private static int checkBellowsMovement() { Debug.Print("Checking bellows movement."); if(callCount > 10) { callCount = 0; return ((int)Action.sendSBE41_DS); } else { callCount++; return((int)Action.checkBellowsMovement); } } private static int sendSBE41_DS() { Debug.Print("Sending SBE41 ds command."); return ((int)Action.sendOptodeGetAll); } private static int sendOptodeGetAll() { Debug.Print("Sending Optode GetALL command."); return ((int)Action.initFLBB); } private static int initFLBB() { Debug.Print("Initializing FLBB."); return ((int)Action.lastAction); } } }