removed all putInt and putShort methods for byte buffers to fix tests

#story[778]
main
hba56 9 years ago
parent 7dd07b470a
commit 538f1bd6ba

@ -28,7 +28,7 @@ public class RaceStatusDecoder {
private int race; private int race;
private int raceState; private int raceState;
private long startTime; private long startTime;
private short raceWindDir; private int raceWindDir;
private short raceWindSpeed; private short raceWindSpeed;
private int numberOfBoats; private int numberOfBoats;
private int raceType; private int raceType;
@ -51,7 +51,7 @@ public class RaceStatusDecoder {
race = bytesToInt(raceID); race = bytesToInt(raceID);
raceState = bytesToInt(raceStatus); raceState = bytesToInt(raceStatus);
startTime = bytesToLong(expectedStart); startTime = bytesToLong(expectedStart);
raceWindDir = bytesToShort(raceWind); raceWindDir = bytesToInt(raceWind);
raceWindSpeed = bytesToShort(windSpeed); raceWindSpeed = bytesToShort(windSpeed);
numberOfBoats = bytesToInt(numBoats); numberOfBoats = bytesToInt(numBoats);
@ -97,7 +97,7 @@ public class RaceStatusDecoder {
return startTime; return startTime;
} }
public short getRaceWindDir() { public int getRaceWindDir() {
return raceWindDir; return raceWindDir;
} }

@ -19,7 +19,7 @@ public class RaceVisionByteEncoder {
public byte[] heartBeat(int seq){ public byte[] heartBeat(int seq){
ByteBuffer heartBeat = ByteBuffer.allocate(4); ByteBuffer heartBeat = ByteBuffer.allocate(4);
heartBeat.putInt(seq); heartBeat.put(intToBytes(seq));
byte [] result = heartBeat.array(); byte [] result = heartBeat.array();
return result; return result;
} }
@ -29,11 +29,11 @@ public class RaceVisionByteEncoder {
//Version Number 1 bytes //Version Number 1 bytes
byte versionNum = 0b10; //this changes with the pdf. (2) byte versionNum = 0b10; //this changes with the pdf. (2)
byte[] timeBytes = longToBytes(time, 6);//time (6 bytes) byte[] timeBytes = longToBytes(time, 6);//time (6 bytes)
byte[] raceID = ByteBuffer.allocate(4).putInt(race).array();//race identifier incase multiple races are going at once. byte[] raceID = ByteBuffer.allocate(4).put(intToBytes(race)).array();//race identifier incase multiple races are going at once.
byte[] raceStatus = intToBytes(raceState, 1);//race status 0 - 10 byte[] raceStatus = intToBytes(raceState, 1);//race status 0 - 10
byte[] expectedStart = longToBytes(startTime, 6);//number of milliseconds from Jan 1, 1970 for when the data is valid byte[] expectedStart = longToBytes(startTime, 6);//number of milliseconds from Jan 1, 1970 for when the data is valid
byte[] raceWind = ByteBuffer.allocate(2).putShort(raceWindDir).array();//North = 0x0000 East = 0x4000 South = 0x8000 byte[] raceWind = ByteBuffer.allocate(2).put(shortToBytes(raceWindDir)).array();//North = 0x0000 East = 0x4000 South = 0x8000
byte[] windSpeed = ByteBuffer.allocate(2).putShort(raceWindSpeed).array();//mm/sec byte[] windSpeed = ByteBuffer.allocate(2).put(shortToBytes(raceWindSpeed)).array();//mm/sec
byte[] numBoats = intToBytes(boats.size(), 1); byte[] numBoats = intToBytes(boats.size(), 1);
byte[] bytesRaceType = intToBytes(raceType, 1);//1 match race, 2 fleet race byte[] bytesRaceType = intToBytes(raceType, 1);//1 match race, 2 fleet race
@ -55,7 +55,7 @@ public class RaceVisionByteEncoder {
byte[] estNextMarkTime = longToBytes((long)0, 6);//TODO use boats estimated time to next mark. byte[] estNextMarkTime = longToBytes((long)0, 6);//TODO use boats estimated time to next mark.
byte[] estFinishTime = longToBytes((long) 0, 6);//TODO use boats estimated time to the finish. byte[] estFinishTime = longToBytes((long) 0, 6);//TODO use boats estimated time to the finish.
raceStatusMessage.putInt(sourceID); raceStatusMessage.put(intToBytes(sourceID));
raceStatusMessage.put(legNum); raceStatusMessage.put(legNum);
raceStatusMessage.put(numPenalties); raceStatusMessage.put(numPenalties);
raceStatusMessage.put(numPenaltiesServed); raceStatusMessage.put(numPenaltiesServed);
@ -120,7 +120,7 @@ public class RaceVisionByteEncoder {
result.put(timestamp); result.put(timestamp);
result.put(ackNumber); result.put(ackNumber);
result.put(raceStartTime); result.put(raceStartTime);
result.putInt(raceIdentifier); result.put(intToBytes(raceIdentifier));
result.put(notificationType); result.put(notificationType);
return result.array(); return result.array();
@ -140,9 +140,9 @@ public class RaceVisionByteEncoder {
result.put(intToBytes(messageVersion, 1)); result.put(intToBytes(messageVersion, 1));
result.put(encodeTime); result.put(encodeTime);
result.putShort(ackNum); result.putShort(ackNum);
result.putInt(raceUID); result.put(intToBytes(raceUID));
result.putInt(destSource); result.put(intToBytes(destSource));
result.putInt(incident); result.put(intToBytes(incident));
result.put(event); result.put(event);
return result.array(); return result.array();
} }

@ -38,7 +38,7 @@ public class RaceStatusDecoderTest {
Assert.assertEquals(1, decoderTest.getRace()); Assert.assertEquals(1, decoderTest.getRace());
Assert.assertEquals(2, decoderTest.getRaceState()); Assert.assertEquals(2, decoderTest.getRaceState());
Assert.assertEquals(time2, decoderTest.getStartTime()); Assert.assertEquals(time2, decoderTest.getStartTime());
Assert.assertEquals((short)2, decoderTest.getRaceWindDir()); Assert.assertEquals(2, decoderTest.getRaceWindDir());
Assert.assertEquals((short)3, decoderTest.getRaceWindSpeed()); Assert.assertEquals((short)3, decoderTest.getRaceWindSpeed());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getBoatStatus()); Assert.assertEquals(0, decoderTest.getBoats().get(0).getBoatStatus());

Loading…
Cancel
Save