1 Dogsm: Pseudo-Code For The Dogsm State Machine
1 Dogsm: Pseudo-Code For The Dogsm State Machine
1 Dogsm: Pseudo-Code For The Dogsm State Machine
************************************************************************************
Pseudo-code for the DogSM state machine
This is the state machine that handles the overarching logic for the hovercraft.
InitDogSM
Takes a priority number, returns true
PostDogSM
Create PostDogSM
RunDogSM
The parameter it takes in will be ThisEvent and the parameter field of
ThisEvent will be the time that the event occurred. Returns ES_NO_Event.
1
// Turn off Pokemon LEDs
// Set the next state to go back to WaitingToPair
// Endif
// If case is WaitingForControl
// If event type is EV_ControlReceived
// Post to DogXBeeTransmitService to send a STATUS packet to the FARMER
// Start the unpair timer again
// If event type is EV_EncryptionReset
// Start the unpair tier again
// Post to DogXBeeTransmitService to send an ENCR_RESET packet to the FARMER
// Else if event type is EV_RetryXmit2Xbee
// (If the transmit status packet indicates the packet was a NACK or a CCA)
// Resend the previous packet
// Else if unpair timer timesout
// Reset the pair status to be unpaired (0)
// Reset the encrypt status to be inactive (0)
// Turn off lift and thrust fans
// Turn pokeball servo back on
// Turn off Pokemon LEDs
// Set the next state to go back to WaitingToPair
// Endif
// Endif
// Set CurrentState to NextState
// Return ES_NO_EVENT
End of RunDogSM
InitUART1
Initializes UART module 1 in order to use asynchronous wired communication with the
on board Xbee
GetDestAddress
// Return the destination address
GetPairStatus
// Return the current pair status
GetEncryptStatus
// Return the encryption status (a formality, since should be the same as the pair
status)
2
GetDogTag
A getter function which reads an analog input pin and computes dog tag number based
on the computed voltage.
FansOff
A function for turning both lift and thrust fans off.
// Turn lift fan off by posting an EV_ToggleLIft event to PIC_UARTService with the
// fan off parameter
// Set thrust fan duty cycles to zero
// Mask thrust fan interrupt
End of FansOff
UART1_ISR
An interrupt service routine which responds to both transmits and receive events
having to do with the Xbee.
// Check which flag caused the UART interrupt to fire (TX or RX):
// If it was transmit:
// Clear the transmit interrupt flag
// Call the UART1 transmit ISR
// Else if it was receive:
// Clear the receive interrupt flag
// Call the UART1 receive ISR
// Endif
End of UART1_ISR
End of DogSM