Fixed the RaceStatusDecoder not deserializing BoatStatus (a subobject of RaceStatus) properly.

RaceVisionByteEncoder.heartBeat now uses a long (and grabs the low 4 bytes from it), as the streaming spec requires a 4 byte unsigned int.
#story[778] #story[782]
This commit is contained in:
fjc40
2017-04-28 01:32:39 +12:00
parent d29c0a9439
commit 873089707d
3 changed files with 25 additions and 13 deletions
@@ -60,13 +60,13 @@ public class RaceStatusDecoder {
for (int i=0; i < numberOfBoats; i++) {
byte[] boatBytes = Arrays.copyOfRange(boatsBytes, boatLoopIndex, boatLoopIndex+20);
byte[] sourceID = Arrays.copyOfRange(boatBytes, 1, 5);
byte boatStatus = boatBytes[5];
byte legNumber = boatBytes[6];
byte numPenaltiesAwarded = boatBytes[7];
byte numPenaltiesServed = boatBytes[8];
byte[] estTimeAtNextMark = Arrays.copyOfRange(boatBytes, 9, 15);
byte[] estTimeAtFinish = Arrays.copyOfRange(boatBytes, 15, 20);
byte[] sourceID = Arrays.copyOfRange(boatBytes, 0, 3);
byte boatStatus = boatBytes[4];
byte legNumber = boatBytes[5];
byte numPenaltiesAwarded = boatBytes[6];
byte numPenaltiesServed = boatBytes[7];
byte[] estTimeAtNextMark = Arrays.copyOfRange(boatBytes, 8, 14);
byte[] estTimeAtFinish = Arrays.copyOfRange(boatBytes, 14, 20);
BoatStatus boat = new BoatStatus(bytesToInt(sourceID),boatStatus,
legNumber, numPenaltiesAwarded, numPenaltiesServed,
@@ -15,9 +15,14 @@ import static seng302.Networking.Utils.ByteConverter.*;
*/
public class RaceVisionByteEncoder {
public byte[] heartBeat(int seq){
/**
* Serializes a heartbeat message.
* @param seq Heartbeat value.
* @return Serialized message.
*/
public static byte[] heartBeat(long seq){
ByteBuffer heartBeat = ByteBuffer.allocate(4);
heartBeat.put(intToBytes(seq));
heartBeat.put(longToBytes(seq, 4));
byte [] result = heartBeat.array();
return result;
}
@@ -27,7 +32,7 @@ public class RaceVisionByteEncoder {
* @param raceStatus Message to serialize.
* @return Serialized (byte array) message, ready to be written to a socket.
*/
public static byte[] raceStatus(RaceStatus raceStatus/*long time, int race, int raceState, long startTime, short raceWindDir, short raceWindSpeed, int raceType, ArrayList<BoatInRace> boats*/){
public static byte[] raceStatus(RaceStatus raceStatus){
ArrayList<BoatStatus> boatStatuses = raceStatus.getBoatStatuses();