## Referee Box

### Description:

The Referee Box is a PC program designed to allow referees to send serial commands to the two competing teams during a match. The program, developed by Carnegie Mellon University, keeps track of the game details, such as score, time remaining, number of penalties assessed, etc.

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.

### Design_Overview:

The Referee Box Interface is designed as a flexible and adaptable utility. It is comprised of two main parts - the serial connection and the processing loop.

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.

### Implementation:

To implement this Referee Box Interface, you first have to create an instance of the RefBoxInterface, and run the initialize() method. The required arguments are color (teamColor - enumeration. either yellow or blue) and port name (name of the serial port through which the Referee Box commands are received). The other arguments allow one to adjust the serial port parameters. The default values correspond with the Referee Box Settings as specified on the official web site (1). "The protocol consists of single ASCII characters sent at 9600 baud (a faster rate may be chosen for the next release), with no parity, 8 data bits and no flow control." This initializes the serial connection. The return value for initialize() is the error code of the serial connection. A value of 0 means that there was no error.

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.

### Additional Resources:

- Official RoboCup 2002 Referee Box Site - http://www-2.cs.cmu.edu/~brettb/robocup/referee.html