The Referee Box Interface is designed to allow the AI to easily implement an interface with the Referee Box. The Referee Box Interface is responsible for initializing the serial connection to the Referee Box, receiving incoming commands from the Referee Box, and processing such commands into a form easily interpreted by the AI.
The serial connection portion uses the Serial Port Interface, which creates an entry point for the console application. It is implemented using Block IO, which means that a thread is blocked during a read and write until the operation is completed. The baud rate, parity, flow control and other properties can be easily set.
The processing loop is the main component of this interface. When an instance of the Referee Box Interface is initialized within a program, the serial connection is established. Furthermore, when the start() method is called, a new thread is created to handle the processing of commands that are received from the Referee Box through the serial connection. Within the thread, a while loop is run indefinitely until end() is called. Within the loop, a command is taken from the serial connection, and the corresponding command is matched to one of the recognized commands. When a recognized command is received, it is stored within a FIFO queue so that the order in which the commands are received remains intact.
Next, run the start() method, which creates the thread and begins the processing loop. This will start storing the commands in the queue. The stop() method stops the processing loop and terminates the thread. Running start() again will resume the process.
To retrieve the command, run the getEvent() method. This will return a command of type refBoxCommand, which is also an enumeration of all the possible commands received from the Referee Box. The commands are relative to the team color that was specified in the initialize() method. For example, suppose that there is a penalty against yellow. If yellow was initialized, then the refBoxCommand will be PENALTY_US. If blue was specified, then the refBoxCommand will be PENALTY_THEM. An EMPTY command is returned when queue is empty. A CONNECTED command is returned if nothing is received from Referee Box, but the connection is still active. To easily decipher the refBoxCommand, use a case statement for each of the desired commands.