The Platform controller uses an ASCII protocol for communication with the host. Using this form of protocol allows better cross communication with varying host platforms.
The protocol consists of sending text packets in the form:
<CMD ARG1 ARG2 ARG3 ... ARGx>
Packet enclosed with ‘<’ and ‘>’
The instruction to the platform is issued with CMD (must be first)
Any number of arguments delimited by a space character
For example the ping instruction looks like:
<P>
‘P’ command
No arguments
Creating the Packets
Creating these packets is pretty trival in a high level language like Java or C++.
In my implementations I used a Builder design pattern to hide the underlying protocol details and also prevent arbitrary data from being sent to the platform.
Pretty simple. The actual data is stored in a string and is accessed with a getter.
So why the private constructor? This is used so that the packet cannot be directly instantiated preventing random data from being used in the packet.
So how is the packet created? I used a Packet Builder class, which is a nested class in the packet (therefore has access to its private constructor) to build the packets.
Ok, so now we have a builder class. Notice that setCommand() and addArgument() return a reference to this object for chaining. This is just for convience.
For example:
But we have a problem. The point of the builder is to prevent random data from being added to the packet. The String argument to setCommand() can be anything so it’s not safe!