-refactered networking test file structure -added average wind decoder -added course wind decoder -added mark rounding decoder -updated boat location decoder -added true wind direction to the boatLocationMessage class -added true wind direction to raceVisionByteEncoder method for boat location #story[778, 782]main
parent
43d087c764
commit
615115160d
@ -0,0 +1,32 @@
|
|||||||
|
package seng302.Networking.MessageDecoders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hba56 on 23/04/17.
|
||||||
|
*/
|
||||||
|
public class AverageWindDecoder {
|
||||||
|
byte messageVersionNumber;
|
||||||
|
byte[] byteTime;
|
||||||
|
byte[] byteRawPeriod;
|
||||||
|
byte[] byteRawSpeed;
|
||||||
|
byte[] bytePeriod2;
|
||||||
|
byte[] byteSpeed2;
|
||||||
|
byte[] bytePeriod3;
|
||||||
|
byte[] byteSpeed3;
|
||||||
|
byte[] bytePeriod4;
|
||||||
|
byte[] byteSpeed4;
|
||||||
|
|
||||||
|
public AverageWindDecoder(byte[] encodedAverageWind) {
|
||||||
|
messageVersionNumber = encodedAverageWind[0];
|
||||||
|
byteTime = Arrays.copyOfRange(encodedAverageWind, 1, 7);
|
||||||
|
byteRawPeriod = Arrays.copyOfRange(encodedAverageWind, 7, 9);
|
||||||
|
byteRawSpeed = Arrays.copyOfRange(encodedAverageWind, 9, 11);
|
||||||
|
bytePeriod2 = Arrays.copyOfRange(encodedAverageWind, 11, 13);
|
||||||
|
byteSpeed2 = Arrays.copyOfRange(encodedAverageWind, 13, 15);
|
||||||
|
bytePeriod3 = Arrays.copyOfRange(encodedAverageWind, 15, 17);
|
||||||
|
byteSpeed3 = Arrays.copyOfRange(encodedAverageWind, 17, 19);
|
||||||
|
bytePeriod4 = Arrays.copyOfRange(encodedAverageWind, 19, 21);
|
||||||
|
byteSpeed4 = Arrays.copyOfRange(encodedAverageWind, 21, 23);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +1,56 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package seng302.Networking.MessageDecoders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 21/04/17.
|
* Created by hba56 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
public class BoatLocationDecoder {
|
public class BoatLocationDecoder {
|
||||||
int messageVersionNumber;
|
private byte messageVersionNumber;
|
||||||
byte[] time;
|
private byte[] time;
|
||||||
byte[] sourceID;
|
private byte[] sourceID;
|
||||||
byte[] seqNum;
|
private byte[] seqNum;
|
||||||
byte[] deviceType;
|
private byte deviceType;
|
||||||
byte[] latitude;
|
private byte[] latitude;
|
||||||
byte[] longitude;
|
private byte[] longitude;
|
||||||
byte[] altitude;
|
private byte[] altitude;
|
||||||
byte[] heading;
|
private byte[] heading;
|
||||||
byte[] pitch;
|
private byte[] pitch;
|
||||||
byte[] roll;
|
private byte[] roll;
|
||||||
byte[] boatSpeed;
|
private byte[] boatSpeed;
|
||||||
byte[] cog;
|
private byte[] cog;
|
||||||
byte[] sog;
|
private byte[] sog;
|
||||||
byte[] apparentWindSpeed;
|
private byte[] apparentWindSpeed;
|
||||||
byte[] apparentWindAngle;
|
private byte[] apparentWindAngle;
|
||||||
byte[] trueWindSpeed;
|
private byte[] trueWindSpeed;
|
||||||
byte[] trueWindAngle;
|
private byte[] trueWindDirection;
|
||||||
byte[] currentDrift;
|
private byte[] trueWindAngle;
|
||||||
byte[] currentSet;
|
private byte[] currentDrift;
|
||||||
byte[] rudderAngle;
|
private byte[] currentSet;
|
||||||
|
private byte[] rudderAngle;
|
||||||
|
|
||||||
|
public BoatLocationDecoder(byte[] encodedBoatLocation) {
|
||||||
|
messageVersionNumber = encodedBoatLocation[0];
|
||||||
|
time = Arrays.copyOfRange(encodedBoatLocation, 1, 7);
|
||||||
|
sourceID = Arrays.copyOfRange(encodedBoatLocation, 7, 11);
|
||||||
|
seqNum = Arrays.copyOfRange(encodedBoatLocation, 11, 15);
|
||||||
|
deviceType = encodedBoatLocation[15];
|
||||||
|
latitude = Arrays.copyOfRange(encodedBoatLocation, 16, 20);
|
||||||
|
longitude = Arrays.copyOfRange(encodedBoatLocation,20, 24);
|
||||||
|
altitude = Arrays.copyOfRange(encodedBoatLocation, 24, 28);
|
||||||
|
heading = Arrays.copyOfRange(encodedBoatLocation,28, 30);
|
||||||
|
pitch =Arrays.copyOfRange(encodedBoatLocation,30,32);
|
||||||
|
roll = Arrays.copyOfRange(encodedBoatLocation,32,34);
|
||||||
|
boatSpeed = Arrays.copyOfRange(encodedBoatLocation,34,36);
|
||||||
|
cog = Arrays.copyOfRange(encodedBoatLocation,36,38);
|
||||||
|
sog = Arrays.copyOfRange(encodedBoatLocation,38, 40);
|
||||||
|
apparentWindSpeed = Arrays.copyOfRange(encodedBoatLocation, 40, 42);
|
||||||
|
apparentWindAngle = Arrays.copyOfRange(encodedBoatLocation, 42, 44);
|
||||||
|
trueWindSpeed = Arrays.copyOfRange(encodedBoatLocation,44, 46);
|
||||||
|
trueWindDirection = Arrays.copyOfRange(encodedBoatLocation, 46, 48);
|
||||||
|
trueWindAngle = Arrays.copyOfRange(encodedBoatLocation, 48, 50);
|
||||||
|
currentDrift = Arrays.copyOfRange(encodedBoatLocation,50,52);
|
||||||
|
currentSet = Arrays.copyOfRange(encodedBoatLocation,52, 54);
|
||||||
|
rudderAngle = Arrays.copyOfRange(encodedBoatLocation,54, 56);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,69 @@
|
|||||||
|
package seng302.Networking.MessageDecoders;
|
||||||
|
|
||||||
|
import seng302.Networking.CourseWind;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hba56 on 23/04/17.
|
||||||
|
*/
|
||||||
|
public class CourseWindDecoder {
|
||||||
|
byte messageVersionNumber;
|
||||||
|
byte byteWindID;
|
||||||
|
byte loopCount;
|
||||||
|
ArrayList<CourseWind> loopMessages;
|
||||||
|
|
||||||
|
public CourseWindDecoder(byte[] encodedCourseWind) {
|
||||||
|
final int lengthInBytesOfMessages = 20;
|
||||||
|
|
||||||
|
messageVersionNumber = encodedCourseWind[0];
|
||||||
|
byteWindID = encodedCourseWind[1];
|
||||||
|
loopCount = encodedCourseWind[2];
|
||||||
|
byte[] loopMessagesBytes = Arrays.copyOfRange(encodedCourseWind, 3, lengthInBytesOfMessages*loopCount);
|
||||||
|
int messageLoopIndex = 0;
|
||||||
|
for (int i=0; i < loopCount; i++) {
|
||||||
|
byte[] messageBytes = Arrays.copyOfRange(loopMessagesBytes, messageLoopIndex, messageLoopIndex+20);
|
||||||
|
|
||||||
|
byte[] windId = Arrays.copyOfRange(messageBytes, 0, 1);
|
||||||
|
byte[] time = Arrays.copyOfRange(messageBytes, 1, 7);
|
||||||
|
byte[] raceID = Arrays.copyOfRange(messageBytes, 7, 11);
|
||||||
|
byte[] windDirection = Arrays.copyOfRange(messageBytes, 11, 13);
|
||||||
|
byte[] windSpeed = Arrays.copyOfRange(messageBytes, 13, 15);
|
||||||
|
byte[] bestUpwindAngle = Arrays.copyOfRange(messageBytes, 15, 17);
|
||||||
|
byte[] bestDownwindAngle = Arrays.copyOfRange(messageBytes, 17, 19);
|
||||||
|
byte[] flags = Arrays.copyOfRange(messageBytes, 19, 20);
|
||||||
|
|
||||||
|
CourseWind message = new CourseWind(bytesToInt(windId), bytesToLong(time),
|
||||||
|
bytesToInt(raceID), bytesToInt(windDirection),
|
||||||
|
bytesToInt(windSpeed), bytesToInt(bestUpwindAngle),
|
||||||
|
bytesToInt(bestDownwindAngle), bytesToInt(flags));
|
||||||
|
|
||||||
|
loopMessages.add(message);
|
||||||
|
messageLoopIndex += 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int bytesToInt(byte[] bytesInt){
|
||||||
|
ByteBuffer wrapped = ByteBuffer.wrap(bytesInt);
|
||||||
|
int num = wrapped.getInt();
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long bytesToLong(byte[] bytesLong){
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.allocate(8);
|
||||||
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
byteBuffer.put((byte)0);
|
||||||
|
byteBuffer.put((byte)0);
|
||||||
|
byteBuffer.put(bytesLong[0]);
|
||||||
|
byteBuffer.put(bytesLong[1]);
|
||||||
|
byteBuffer.put(bytesLong[2]);
|
||||||
|
byteBuffer.put(bytesLong[3]);
|
||||||
|
byteBuffer.put(bytesLong[4]);
|
||||||
|
byteBuffer.put(bytesLong[5]);
|
||||||
|
long longVal = byteBuffer.getLong(0);
|
||||||
|
return longVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package seng302.Networking.MessageDecoders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hba56 on 23/04/17.
|
||||||
|
*/
|
||||||
|
public class MarkRoundingDecoder {
|
||||||
|
byte messageVersionNumber;
|
||||||
|
byte[] byteTime;
|
||||||
|
byte[] byteAck;
|
||||||
|
byte[] byteRaceID;
|
||||||
|
byte[] byteSourceID;
|
||||||
|
byte byteBoatStatus;
|
||||||
|
byte byteRoundingSide;
|
||||||
|
byte byteMarkType;
|
||||||
|
byte byteMarkID;
|
||||||
|
|
||||||
|
public MarkRoundingDecoder(byte[] encodedMarkRounding) {
|
||||||
|
messageVersionNumber = encodedMarkRounding[0];
|
||||||
|
byteTime = Arrays.copyOfRange(encodedMarkRounding, 1, 7);
|
||||||
|
byteAck = Arrays.copyOfRange(encodedMarkRounding, 7, 9);
|
||||||
|
byteRaceID = Arrays.copyOfRange(encodedMarkRounding, 9, 13);
|
||||||
|
byteSourceID = Arrays.copyOfRange(encodedMarkRounding, 13, 18);
|
||||||
|
byteBoatStatus = encodedMarkRounding[18];
|
||||||
|
byteRoundingSide = encodedMarkRounding[19];
|
||||||
|
byteMarkType = encodedMarkRounding[20];
|
||||||
|
byteMarkID = encodedMarkRounding[21];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue