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:
@@ -60,13 +60,13 @@ public class RaceStatusDecoder {
|
|||||||
for (int i=0; i < numberOfBoats; i++) {
|
for (int i=0; i < numberOfBoats; i++) {
|
||||||
byte[] boatBytes = Arrays.copyOfRange(boatsBytes, boatLoopIndex, boatLoopIndex+20);
|
byte[] boatBytes = Arrays.copyOfRange(boatsBytes, boatLoopIndex, boatLoopIndex+20);
|
||||||
|
|
||||||
byte[] sourceID = Arrays.copyOfRange(boatBytes, 1, 5);
|
byte[] sourceID = Arrays.copyOfRange(boatBytes, 0, 3);
|
||||||
byte boatStatus = boatBytes[5];
|
byte boatStatus = boatBytes[4];
|
||||||
byte legNumber = boatBytes[6];
|
byte legNumber = boatBytes[5];
|
||||||
byte numPenaltiesAwarded = boatBytes[7];
|
byte numPenaltiesAwarded = boatBytes[6];
|
||||||
byte numPenaltiesServed = boatBytes[8];
|
byte numPenaltiesServed = boatBytes[7];
|
||||||
byte[] estTimeAtNextMark = Arrays.copyOfRange(boatBytes, 9, 15);
|
byte[] estTimeAtNextMark = Arrays.copyOfRange(boatBytes, 8, 14);
|
||||||
byte[] estTimeAtFinish = Arrays.copyOfRange(boatBytes, 15, 20);
|
byte[] estTimeAtFinish = Arrays.copyOfRange(boatBytes, 14, 20);
|
||||||
|
|
||||||
BoatStatus boat = new BoatStatus(bytesToInt(sourceID),boatStatus,
|
BoatStatus boat = new BoatStatus(bytesToInt(sourceID),boatStatus,
|
||||||
legNumber, numPenaltiesAwarded, numPenaltiesServed,
|
legNumber, numPenaltiesAwarded, numPenaltiesServed,
|
||||||
|
|||||||
@@ -15,9 +15,14 @@ import static seng302.Networking.Utils.ByteConverter.*;
|
|||||||
*/
|
*/
|
||||||
public class RaceVisionByteEncoder {
|
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);
|
ByteBuffer heartBeat = ByteBuffer.allocate(4);
|
||||||
heartBeat.put(intToBytes(seq));
|
heartBeat.put(longToBytes(seq, 4));
|
||||||
byte [] result = heartBeat.array();
|
byte [] result = heartBeat.array();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -27,7 +32,7 @@ public class RaceVisionByteEncoder {
|
|||||||
* @param raceStatus Message to serialize.
|
* @param raceStatus Message to serialize.
|
||||||
* @return Serialized (byte array) message, ready to be written to a socket.
|
* @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();
|
ArrayList<BoatStatus> boatStatuses = raceStatus.getBoatStatuses();
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -60,9 +60,16 @@ public class RaceStatusDecoderTest {
|
|||||||
Assert.assertEquals(windDirection, decoderTest.getRaceWindDir());
|
Assert.assertEquals(windDirection, decoderTest.getRaceWindDir());
|
||||||
Assert.assertEquals(windSpeed, decoderTest.getRaceWindSpeed());
|
Assert.assertEquals(windSpeed, decoderTest.getRaceWindSpeed());
|
||||||
|
|
||||||
Assert.assertEquals(boat1Status, decoderTest.getBoats().get(0).getBoatStatus());
|
|
||||||
Assert.assertEquals(boat1LegNumber, decoderTest.getBoats().get(0).getLegNumber());
|
BoatStatus boat1 = decoderTest.getBoats().get(0);
|
||||||
Assert.assertEquals(boat1PenaltiesAwarded, decoderTest.getBoats().get(0).getNumPenaltiesAwarded());
|
|
||||||
|
Assert.assertEquals(boat1SourceID, boat1.getSourceID());
|
||||||
|
Assert.assertEquals(boat1Status, boat1.getBoatStatus());
|
||||||
|
Assert.assertEquals(boat1LegNumber, boat1.getLegNumber());
|
||||||
|
Assert.assertEquals(boat1PenaltiesAwarded, boat1.getNumPenaltiesAwarded());
|
||||||
|
Assert.assertEquals(boat1PenaltiesServed, boat1.getNumPenaltiesServed());
|
||||||
|
Assert.assertEquals(boat1TimeAtNextMark, boat1.getEstTimeAtNextMark());
|
||||||
|
Assert.assertEquals(boat1TimeAtFinish, boat1.getEstTimeAtFinish());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user