V4 Protocol Specification
From SoftwarePractice.org
The Digital Broadcasting system uses a TCP based protocol to communicate between Clients and the main Server. This page documents the protocol used. The protocol is strictly Client-Server. This means the server will never send a message unless the client sends one first.
Contents |
Messages
Each message consists of a command, as well as parameters. Each command is assigned a unique ID, and each parameter is also assigned a unique ID. Parameters can have any of the following basic types:
- Byte, Short integer (2 bytes), or Integer (4 bytes)
- Float or Double
- String
- Binary Data
- Array of Type
Each type is assigned a unique ID.
Commands
A command is written to the TCP stream as a series of parameter (described later) followed by 0xFF and then the command ID (as a byte). The command IDs will be decided upon once coding has begun.
Parameters
Each parameter is written as 0xEE, followed by the parameter ID as a byte. This is followed by the type's ID, then the data. The length and format of the data will depend on its type.
Responses
Responses to commands will take the same format as commands; usually there will be no parameters, and the command ID will represent 'OK'. Errors will results in a command ID representing 'ERROR' and the parameters will contain information about the type of error.
Access from Java
Classes and interfaces exist within src/protocol for connecting to the server and sending messages. The following code fragments illustrate the proposed interface:
import protocol.*;
Session s = new Session(ipaddress);
Command c = new Command(CommandID.SET_VOLUME);
c.addParameter(new Parameter(ParameterID.SOURCE, 1)); //set the volume of source 1
c.addParameter(new Parameter(ParameterID.LEVEL, 0.5)); //set it to 50%
Command resp = s.send(c);
if(resp.getCommand() != CommandID.OK)
{
//an error occured
System.err.println("Error " + resp.getParameter(ParameterID.DESCRIPTION));
}
