added decoders for avg wind, course wind and mark rounding

-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
hba56 9 years ago
parent 43d087c764
commit 615115160d

@ -60,6 +60,8 @@ public class BoatLocationMessage
///True wind speed. Proper type is unsigned 2 byte int. millimeters per second.
private int trueWindSpeed;
private short trueWindDirection;
///True wind angle. Clockwise compass direction, 0 = north.
private short trueWindAngle;
@ -99,12 +101,13 @@ public class BoatLocationMessage
* @param apparentWindSpeed
* @param apparentWindAngle
* @param trueWindSpeed
* @param trueWindDirection
* @param trueWindAngle
* @param currentDrift
* @param currentSet
* @param rudderAngle
*/
public BoatLocationMessage(byte messageVersionNumber, long time, int sourceID, long sequenceNumber, byte deviceType, int latitude, int longitude, int altitude, int heading, short pitch, short roll, int boatSpeed, int boatCOG, int boatSOG, int apparentWindSpeed, short apparentWindAngle, int trueWindSpeed, short trueWindAngle, int currentDrift, int currentSet, short rudderAngle)
public BoatLocationMessage(byte messageVersionNumber, long time, int sourceID, long sequenceNumber, byte deviceType, int latitude, int longitude, int altitude, int heading, short pitch, short roll, int boatSpeed, int boatCOG, int boatSOG, int apparentWindSpeed, short apparentWindAngle, int trueWindSpeed, short trueWindDirection, short trueWindAngle, int currentDrift, int currentSet, short rudderAngle)
{
this.messageVersionNumber = messageVersionNumber;
this.time = time;
@ -123,6 +126,7 @@ public class BoatLocationMessage
this.apparentWindSpeed = apparentWindSpeed;
this.apparentWindAngle = apparentWindAngle;
this.trueWindSpeed = trueWindSpeed;
this.trueWindDirection = trueWindDirection;
this.trueWindAngle = trueWindAngle;
this.currentDrift = currentDrift;
this.currentSet = currentSet;
@ -303,6 +307,14 @@ public class BoatLocationMessage
this.trueWindSpeed = trueWindSpeed;
}
public short getTrueWindDirection() {
return trueWindDirection;
}
public void setTrueWindDirection(short trueWindDirection) {
this.trueWindDirection = trueWindDirection;
}
public short getTrueWindAngle()
{
return trueWindAngle;

@ -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;
import java.util.Arrays;
/**
* Created by hba56 on 21/04/17.
*/
public class BoatLocationDecoder {
int messageVersionNumber;
byte[] time;
byte[] sourceID;
byte[] seqNum;
byte[] deviceType;
byte[] latitude;
byte[] longitude;
byte[] altitude;
byte[] heading;
byte[] pitch;
byte[] roll;
byte[] boatSpeed;
byte[] cog;
byte[] sog;
byte[] apparentWindSpeed;
byte[] apparentWindAngle;
byte[] trueWindSpeed;
byte[] trueWindAngle;
byte[] currentDrift;
byte[] currentSet;
byte[] rudderAngle;
private byte messageVersionNumber;
private byte[] time;
private byte[] sourceID;
private byte[] seqNum;
private byte deviceType;
private byte[] latitude;
private byte[] longitude;
private byte[] altitude;
private byte[] heading;
private byte[] pitch;
private byte[] roll;
private byte[] boatSpeed;
private byte[] cog;
private byte[] sog;
private byte[] apparentWindSpeed;
private byte[] apparentWindAngle;
private byte[] trueWindSpeed;
private byte[] trueWindDirection;
private byte[] trueWindAngle;
private byte[] currentDrift;
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];
}
}

@ -175,6 +175,7 @@ public class RaceVisionByteEncoder {
byte[] apparentWindSpeed = convert(boatLocationMessage.getApparentWindSpeed(), 2);
byte[] apparentWindAngle = convert(boatLocationMessage.getApparentWindAngle(), 2);
byte[] trueWindSpeed = convert(boatLocationMessage.getTrueWindSpeed(), 2);
byte[] trueWindDirection = convert(boatLocationMessage.getTrueWindDirection(), 2);
byte[] trueWindAngle = convert(boatLocationMessage.getTrueWindAngle(), 2);
byte[] currentDrift = convert(boatLocationMessage.getCurrentDrift(), 2);
byte[] currentSet = convert(boatLocationMessage.getCurrentSet(), 2);
@ -198,6 +199,7 @@ public class RaceVisionByteEncoder {
result.put(apparentWindSpeed);
result.put(apparentWindAngle);
result.put(trueWindSpeed);
result.put(trueWindDirection);
result.put(trueWindAngle);
result.put(currentDrift);
result.put(currentSet);

@ -1,3 +1,5 @@
package seng302.Networking;
import org.junit.Assert;
import org.junit.Test;
import seng302.Networking.*;
@ -16,7 +18,7 @@ public class BinaryMessageDecoderTest {
try{
StringBuilder xmlString;
BufferedReader br = new BufferedReader(new InputStreamReader(
this.getClass().getResourceAsStream(("raceXML/Regatta.xml"))));
this.getClass().getResourceAsStream(("../../raceXML/Regatta.xml"))));
String line;
xmlString = new StringBuilder();
while((line=br.readLine())!= null){
@ -44,7 +46,7 @@ public class BinaryMessageDecoderTest {
XMLMessageDecoder decoderXML = new XMLMessageDecoder(testDecoder.getMessage());
decoderXML.decode();
//tests from XMLMessageDecoderTest to make sure the file is still good
//tests from seng302.Networking.MessageDecoders.XMLMessageDecoderTest to make sure the file is still good
Assert.assertEquals((byte)1, decoderXML.getMessageVersionNumber());
Assert.assertEquals((short)1, decoderXML.getAckNumber());
Assert.assertEquals(time, decoderXML.getTimeStamp());

@ -1,3 +1,5 @@
package seng302.Networking.MessageDecoders;
import org.junit.Assert;
import org.junit.Test;
import seng302.Networking.MessageDecoders.XMLMessageDecoder;
@ -16,7 +18,7 @@ public class XMLMessageDecoderTest {
try{
StringBuilder xmlString;
BufferedReader br = new BufferedReader(new InputStreamReader(
this.getClass().getResourceAsStream(("raceXML/Regatta.xml"))));
this.getClass().getResourceAsStream(("../../../raceXML/Regatta.xml"))));
String line;
xmlString = new StringBuilder();
while((line=br.readLine())!= null){

@ -1,3 +1,5 @@
package seng302.Networking;
import org.junit.Assert;
import org.junit.Test;
import seng302.Networking.XMLMessageEncoder;
@ -13,7 +15,7 @@ public class XMLMessageEncoderTest {
StringBuilder xmlString;
try{
BufferedReader br = new BufferedReader(new InputStreamReader(
this.getClass().getResourceAsStream(("raceXML/Regatta.xml"))));
this.getClass().getResourceAsStream(("../../raceXML/Regatta.xml"))));
String line;
xmlString = new StringBuilder();
while((line=br.readLine())!= null){
@ -35,7 +37,7 @@ public class XMLMessageEncoderTest {
StringBuilder xmlString;
try{
BufferedReader br = new BufferedReader(new InputStreamReader(
this.getClass().getResourceAsStream(("raceXML/Regatta.xml"))));
this.getClass().getResourceAsStream(("../../raceXML/Regatta.xml"))));
String line;
xmlString = new StringBuilder();
while((line=br.readLine())!= null){
Loading…
Cancel
Save