CheckNewMessage: Takes Nothing, Returns an unsigned char If NewMessageReceived Flag is Set Clear NewMessageReceived Flag Return 1 Otherwise, No Message was Received Return 0 CheckTransmit: Takes nothing, Returns an unsigned char If TransmitFlag is set Reset Transmit Flag Return 1 Otherwise Return 0 ReturnDataSize: Takes Nothing, Returns an unsigned char Return byteCounter QueryMesssage: Takes an integer Index, Returns an unsigned char Return messageArray at appropriate index number InitComm: Takes Nothing, Returns nothing For Transmission: Enable asynchronous serial transmission port Enable Transmissions Enable High Data Rate 8-bit Transmit For Receiving: Enable asynchronous serial reception port Enable Receptions 8-bit receive Disable Address Detection Baud Rate = 9600 bps (0x81) Set all state flags and Counters to 0 EnableInterrupt: Takes Nothing, Returns Nothing Set Interrupts On ReceiveMessageSM: Takes Nothing, Returns Nothing If current State is WAITING_FOR_START_BYTE If Byte Read is 7E Message Received, Wait for the MSB Start Timeout Timer If currentState is WAITING_FOR_MSB If Timeout Timer has Timed Out Return to WAITING_FOR_START_BYTE State If we received a byte If we received a 0 Start Timeout Timer set nextState to WAITING_FOR_LSB otherwise message was corrupted return to WAITING_FOR_START_BYTE State If currentState is WAITING_FOR_LSB If Timeout Timer has Timed Out Return to WAITING_FOR_START_BYTE State If we received a byte Set Next State to WAITING_FOR_DATA Restart Timeout Timer Initialize the CheckSum and Save the Size of Message Initialize the byteCounter If currentState is WAITING_FOR_DATA If Timeout Timer has Timed Out Return to WAITING_FOR_START_BYTE State If message was received Restart Timeout Timer If messageLength is 0 Set nextState to WAITING_FOR_CHECKSUM Else Set nextState to WAITING_FOR_DATA Decrement messageLength Add the ReceivedMessage to the running checksum Counter Store the ReceivedMessage into the messageArray Increment the byteCounter If currentState is WAITING_FOR_CHECKSUM If Timeout Timer has Timed Out Return to WAITING_FOR_START_BYTE State If message was received nextState is WAITING_FOR_START_BYTE If 0xFF - Checksum is equal to the received message Good CheckSum Received, set checksumError flag to 0 Set NewMessagedReceived Flag to 1 Otherwise Message was bad, set checkSumError flag to 1 Set currentState equal to nextState CreatePacket: This function puts together a packet to send Input Bytes(unsigned char): To Address MSB/LSB, Length, Options, Command Type, and Data Array set Packet 0 byte to START_MESSAGE Set Packet 1 byte to 0x00 Set Packet 2 byte to Data_Length + 6 set Packet 3 byte to API_TRANSMIT value Set Packet 4 byte to 0x01 Set Packet 5 byte to MessageAddress MSB Set Packet 6 byte to MessageAddress LSB set Packet 7 byte to Options set Packet 8 byte to CommandType Initialize Checksum byte to the sum of bytes 3 to 8 For the amount of bytes in the data message Store the appropriate bytes into packet Add the byte to the running checksum counter After the end of the Packet Data, the Checksum byte is 0xFF - Running Checksum Counter Save the Data_Length Set the NewMessageFlag HI TransmitSM: Takes Nothing, Returns Nothing If CurrentState is WAITING_FOR_PACKET If transmit Timer has expired Turn off Send Debug LED If NewMessageFlag is True Clear NewMessageFlag Reset Counter to 0 Set CurrentState to WAITING_FOR_TRANSMIT Reinitialize the SEND_LED_TIMEOUT Turn on Send Debug LED Reinitialize Send Timer If CurrentState is WAITING_FOR_TRANSMIT If Counter is less than Data Length + 10 If Transmission is Ready Set the transmit register to the current Packet Byte Increment the Counter Set SendCounter to Counter Otherwise If Transmission is done sending Set Transmit Flag to 1 Set Next State to WAITING_FOR_PACKET ProcessMSG: Takes Nothing, Returns Message_t If API Byte was API_RECEIVE If Receive Option is 0 If Command Type is a Atoll Reply If Message was ATOLL_SUCCESS Set ReceivedMessage to AtollSuccess Otherwise if Message was ATOLL_FAILURE Set ReceivedMessage to AtollFailure If Command Type was FIND_TEAM Set Message to TeammateACK Else if Command Type was COMMAND_C2B Set ReceivedMessage to DriveCommand Otherwise message was Broadcast If Message Command was BROADCAST_CAPTURE Set Received Message to AtollCaptured Otherwise if Command was FIND_TEAM Set Received Message to ColorBroadcast Otherwise Message was a Transmit Status If message was a succesful reception Set Received message to ModemAck Return the ReceivedMessage type