/**************************************************************************** Module SMSensors.c Description Integration of Beacon detection state machine and other sensors module. ****************************************************************************/ /*----------------------------- Include Files -----------------------------*/ #include "GlobalHeader.h" #include "SMSensors.h" /*----------------------------- Module Defines ----------------------------*/ /*---------------------------- Module Functions ---------------------------*/ static Event_t DuringRunning( Event_t Event); /*---------------------------- Module Variables ---------------------------*/ static SensorsState_t CurrentState; /*------------------------------ Module Code ------------------------------*/ /**************************************************************************** Function RunSensorsSM Parameters Event_t Returns Event_t Description Runs Sensors SM. ****************************************************************************/ Event_t RunSensorsSM( Event_t CurrentEvent ) { unsigned char MakeTransition = FALSE;/* are we making a state transition? */ SensorsState_t NextState = CurrentState; switch ( CurrentState ) { case Sensors_Running : CurrentEvent = DuringRunning(CurrentEvent); //process any events if ( CurrentEvent != EV_NO_EVENT ) //If an event is active { switch (CurrentEvent) { } } break; } // If we are making a state transition if (MakeTransition == TRUE) { // Execute exit function for current state (void)RunSensorsSM(EV_EXIT); CurrentState = NextState; //Modify state variable // Execute entry function for new state (void)RunSensorsSM(EV_ENTRY); } return(CurrentEvent); } /**************************************************************************** Function StartSensorsSM Parameters Event_t Returns none Description Start Sensors SM, initialize other sensors module, BumpTapeInit ****************************************************************************/ void StartSensorsSM ( Event_t CurrentEvent ) { CurrentState = Sensors_Running; BumpTapeInit(); // call the entry function (if any) for the ENTRY_STATE printf("SensorsStarted\r\n"); (void)RunSensorsSM(EV_ENTRY); } /**************************************************************************** Function QuerySensorsSM Parameters none Returns SensorsState_t current state Description returns current state machine state. ****************************************************************************/ SensorsState_t QuerySensorsSM ( void ) { return(CurrentState); } /*************************************************************************** private functions ***************************************************************************/ /**************************************************************************** Function DuringRunning Parameters Event_t Returns Event_t Description Runs lower level state machines ****************************************************************************/ static Event_t DuringRunning( Event_t Event) { // process EV_ENTRY & EV_EXIT events if ( Event == EV_ENTRY) { (void)StartBeaconDetectionSM(Event); }else if ( Event == EV_EXIT) { (void)RunBeaconDetectionSM(Event); }else // do the 'during' function for this state { Event = RunBeaconDetectionSM(Event); } return(Event); }