using System; using Microsoft.SPOT; using System.Text; using System.Threading; namespace abstractState { public class Program { public enum CPFStates : int { initMission = 0, initProfile, descend, ascend, cpfStatesLength } public static CPFStates currentState; private static StateBase[] cpfState = new StateBase[(int)CPFStates.cpfStatesLength]; private static StringBuilder sbTemp = new StringBuilder(128); public static void Main() { Debug.Print("Program Started"); cpfState[0] = new InitMission("Init Mission"); cpfState[1] = new InitProfile("Init Profile"); cpfState[2] = new Descend("Descend"); cpfState[3] = new Ascend("Ascend"); BuoyancyControl.init(); currentState = CPFStates.initMission; CPFStates nextState = currentState; int currentStateIndex = (int)currentState; while (true) { try { ExecutionConstraint.Install(cpfState[currentStateIndex].ECTimeout, 0); Debug.Print("Current state num = " + currentState.ToString() + " " + cpfState[currentStateIndex].stateName.ToString()); do { cpfState[currentStateIndex].doStateActions(); nextState = cpfState[currentStateIndex].checkEvents(); processSQ(); Thread.Sleep(2500); } while (nextState == currentState); } catch (Exception currentException) { Debug.Print("Need to handle this exception: " + currentException.ToString()); if (currentException is ConstraintException) cpfState[currentStateIndex].doTimeoutAction(); //Need to handle other exceptions here } ExecutionConstraint.Install(-1, 0); currentState = nextState; currentStateIndex = (int)currentState; } } private static void processSQ() { //Debug.Print("Processing Queue"); } } }