Pseudocode for FARMER_FSM.c Description Manages high-level information passing for the FARMER controller InitFARMER_FSM Set MyPriority equal to Priority parameter Set CurrentState to WaitingToPair Initialize UART, for communication via XBee Initialize DOG select input pins Initialize LED output pins Initialize IMU LED Display Post the initial transition event end InitFARMER_FSM RunFARMER_FSM Switch on the current state case WaitingToPair state switch on event type case ES_PAIR_EVENT Start LOST_CONN_TIMER for 1s = 1000 ms Determine which DOG has been chosen to pair with (by umbrella mechanism) Post ES_BEGIN_TXMIT with event param of REQ_2_PAIR to FARMERTXmitSM Set CurrentState to WaitingForPairResponse break on this case break on this case case WaitingForPairResponse state switch on event type case ES_PACKET_RX if the event param is PAIR_ACK Start LOST_CONN_TIMER for 1s Post ES_BEGIN_TXMIT with event param of ENCR_KEY to FARMERTXmitSM Start INTER_MSG_TIMER Pulse Active Comm LED Turn on RGB LEDs indicating pairing (depends on which DOG is chosen) Set CurrentState to Paired end if break on this case case ES_TIMEOUT if the event param is LOST_CONN_TIMER Turn off the Active Communication LED Set CurrentState to WaitingToPair else if the event param is LED_TIMER Turn off the Active Communication LED end if break on this case break on this case case Paired state switch on event type case ES_PACKET_RX Start LOST_CONN_TIMER for 1s = 1000 ms Pulse Active Comm LED if the event param is STATUS Update the IMU display using the relevant bits from the STATUS packet else if the event parameter (the header) is ENCR_RESET Set encryption index to 0 end if break on this case case ES_TIMEOUT if the event param is LOST_CONN_TIMER Turn off the RGB LEDs indicating paired Set CurrentState to WaitingToPair else if the event param is INTER_MSG_TIMER using data from IMUService, Post ES_BEGIN_TXMIT with event param... ...of CTRL to FARMERTXmitSM Start INTER_MSG_TIMER else if the event param is LED_TIMER Turn off the Active Communication LED end if break on this case end switch on event type end switch on CurrentState return ReturnEvent end RunFARMFER_FSM DetermineDOGSelected Updates module-level variable: uint8_t DOGSelected. Determines which of the 3 DOGs the user wants to control, based on 3 input switches. Since there is only one physical selection mechanism (the umbrella), only one switch should be on at a time. If no DOG is selected, DOGSelected is set to NO_DOG which will be handled by other functions (for instance, if NO_DOG, then trying to pair will be unsuccessful). if if bit 4 on port C is low Set DOGSelected equal to DOG_1 else if if bit 5 on port C is low Set DOGSelected equal to DOG_2 else if bit 6 on port C is low Set DOGSelected equal to DOG_3 else Set DOGSelected equal to NO_DOG end if end DetermineDOGSelected