Added boat location, and race start messages to the mock data interface

- Added proper support for signed and unsigned types. This includes automatic conversion to the correct data type (long to int, short, or byte).

- Moved code related to adding values into the byte buffer into the abstract Message class

Tags: #story[29]
This commit is contained in:
Michael Rausch
2017-04-25 21:49:51 +12:00
parent 6874f288ee
commit 1f8f1f0f86
12 changed files with 573 additions and 121 deletions
@@ -26,24 +26,15 @@ public class Heartbeat extends Message {
public void send(DataOutputStream outputStream) {
setHeader(new Header(MessageType.HEARTBEAT, 0x01, (short) getSize()));
ByteBuffer buff = ByteBuffer.allocate(Header.getSize() + getSize() + getSize());
allocateBuffer();
writeHeaderToBuffer();
// Write header
buff.put(getHeader().getByteBuffer());
buff.position(Header.getSize());
putUnsignedInt(seqNo, 4);
// Write seq num
buff.put(ByteBuffer.allocate(4).putInt(seqNo).array());
buff.position(Header.getSize()+4);
// Write CRC
CRC32 crc = new CRC32();
crc.update(buff.array());
buff.put(ByteBuffer.allocate(4).putInt((short)crc.getValue()).array());
writeCRC();
try {
outputStream.write(buff.array());
outputStream.write(getBuffer().array());
} catch (IOException e) {
e.printStackTrace();
}