This module monitors the pairing status of the BOAT. It processes ES_PAIR and ES_UNPAIR events from the UART service to move between two states: Trying to Pair and Paired. State transition events are leveraged to update the paired status indicator flag and turn off the DC motor drive signal. Since this module is also the first file to be called during the initialization routine of the project, this is where I/O pins and peripherals (timers, OC) are configured.
The PairedSM is actually handled within the Paired state of Boat Top HSM. This accompanying diagram simply for visualization of the mechanism that determined HNTR or PREI status. Upon entry to the Paired state, Boat Top HSM reads the state of the BAYT limit switch to determine whether it is carrying a balloon, thus signifying HNTR or PREI status. Tracking this distinction allows for separation of functionality. In other words, the BOAT can only chomp whilst a HNTR.
This module keeps track of the timer logic required to properly implement the BYT(ER), as per the competition rules. It receives ES_TOGGLE_CHOMP events from the UART service and determines whether it is permitted to chomp. Timers and state transitions enforce the 3 second cooldown period since the last chomp. Meanwhile, a circular buffer with timestamps of the last three chomps enforces the 3 chomps in 24 seconds rule. Given the timescale of this competition (several minutes), it was necessary to account for rollovers in the 16-bit timer when storing timestamps of each chomp event.
The UART service houses all XBee communication protocol mechanisms including service event transition, receive and transmit UART interrupt service routine, decoding function for received message, transmitting frame message function, etc.