HZV
The HZV initializes into a state in which it is disconnected and is searching for a LUC request to control it. When the request it receives, the HZV builds an acknowledgement message to send back to the LUC and then goes into a state where it is receiving commands from the LUC. If it ever receives a command, the HZV must determine whether it is a LUC command or a Necromancer command (if it is a zombie) and process the command accordingly. If the HZV does not receive a command for over a second or it's balloon pops it will return to waiting for a LUC request for control.
LUC
The LUC initializes into a state where it is waiting for the connect buttons to be pressed. In the mean time, it reads the value of the boat select knob and updates the 7-segment displays if necessary. When the buttons are pressed, the LUC goes into a state where it waits for the next timeout. This is to ensure that the LUC does not send messages faster than 5 Hz. Once the next timeout occurs, the LUC sends out a request for control to the HZV selected. It then goes into a state where it waits for the acknowledgement from the HZV. If it does not received an acknowledgement within one second, the LUC will return to a state of waiting for the button presses. If it does receive it, the 7-segment display is blinked five times, and the LUC goes into a state of sending commands. In this state, every 200 ms a new data packet is built up and sent to the HZV. If at any point the LUC does not receive an acknowledgement within 1 second, it will return to its initial state.
XBee Transmit
The XBeeTransmit state machine initializes into a state in which it is waiting for there to be a message to send, which is determined by polling a flag. When the flag is set, the state machine brings in a copy of the message and initiates a send by sending the start bit (0x7E). It then proceeds through states in which it sends the length of the message being sent and then sends the actual message. Finally, it calculates a checksum to be used on the receive side to ensure the message is valid.
XBee Receive
The XBeeReceive state machine initializes into a state in which it waiting for a start bit (0x7E). Once it has received this, it goes into a state in which it gets the length of the message and stores it away. It then goes to a state where it reads in and stores bytes until the number of bytes equals the length of the message that was stored away previously. At this point, the checksum is checked to make sure the message is valid. If it is, a flag is set. If not, the state machine simply returns to waiting for the start bit. If at any point, the state machine does not receive a new byte within a byte time, it returns to the initial state.