"The Hunt for Red Mithuna" is written under the Gen2 Events and Services framework. In terms of functionalities, the system should be able to generate audio tones by frequency modulation, interpret audio tones by demodulation, encode and decode messages. In addition, a Graphical User Interface (GUI) is made to improve the overall gaming experience.
FSM: GamePlay
This is where the main game play being implemented. It is a flat state machine consists of four states: WaitForSync, Sync, CommTime, and HumanTime. The game enters the WaitForSync state as it initializes. Transition from WaitForSync to Sync happens when either a SYNC message is heard or one full TDMA cycle has passed. During the Sync state, the device listens to SYNC messages. Only when all devices are synchronized over the internet, the actual game starts. CommTime is when the communication across all submarine stations takes place. The messages sent in the CommTime are input by the players during the HumanTime. CommTime and HumanTime alternates in the game play as the turn increments.
FSM: Encoding
This state machine implements the message encoding process. Encoding SM stays in AutoTime when the GamePlay SM is in CommTime state, where user input is disabled. As the GamePlay SM transits from CommTime to HumanTime, Encoding SM will move into one of the three states: CONNTime, SONARTime, or TORPEDOTime based on the roles that the device is currently taking. In any of the three states, the player should load actions for the next turn. Messages will be encoded and loaded into the corresponding message buffers when the state changes.
Service: Decoding
Whenever there is a new message received, it will get decoded here. Since all messages are broadcasted in the same audio channel during the game, the device can receive all of them. However, not all messages are supposed to be directed to this station. Therefore, every message is analyzed to check whether the information can be released to the player or not, if so, then the information will be displayed through the GUI. CONN station will also decide whether it should construct either a ECHO or a HIT response to the received message based on the current coordinates of the submarine.
Service: TDMA
TDMA (Time_division Multiple Access) service takes care of the timing in the game. Each station has its own timer to track the time left until its next transmission. One additional timer is used to track the end of every TDMA cycle. In total, TDMA service controls four timers. Whenever a new message received, it re-computes the timing and re-initializes the four timers by decoding the team and station information from the message.
Service: Message Transmission
The transmission service sends messages out through the speaker to other submarines. It uses a framework timer that expires at 10 baud rate and sets the output frequency of the speaker to match the desired message.
Service: Message Reception
The receive service demodulates the audio tones being received over the microphone. Whenever the start bit is detected in the event checker, this service starts. It averages the current frequency 10 times in the middle of each bit being transmitted and determines the dibit associated with it. If the checksum received is correct, the message is posted to the other services as a valid message.
Library: GUI
Library: Servo Motor
This library contains three public functions to be called in the game play, they are: servo motor hardware initialization, move servo arm to push-to-talk position, and move servo arm to release position.
Library: Audio Hardware
This library initializes all the speaker and microphone components. This includes a DAC with timer interrupts and a sine lookup table that allows it to generate sine waves of different frequencies and the ADC input for the microphone. The ADC input is set to read and store a new value at a rate of 16.67 kHz and stores the last 200 elements. This is so the current frequency can be measured by looking through this 200 element array, finding the number of zero crossings over this set period, and thus returning the frequency of the incoming wave.
Library: Message Hardware
This library initializes the remaining physical components which includes the the LED indicator and the three DIP switch inputs.