Moved several classes from seng302.model to its own module - sharedModel (this is supposed to contain any shared data model code between mock and visualiser). Specifically, Regatta, Boat, BoatInRace, Constants, GPSCoordinate, Leg, Marker.

Updated RaceVisionByteEncoder.raceStatus to accept a Racestatus object rather than a bunch of parameters.
Added getters to RaceStatus class.
Updated some tests.
Removed Network tests from Mock, as they were duplicated.
This commit is contained in:
fjc40
2017-04-28 01:27:45 +12:00
parent 50cb31b85f
commit 90f8bec415
56 changed files with 624 additions and 2749 deletions
+8
View File
@@ -13,6 +13,14 @@
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>seng302</groupId>
<artifactId>sharedModel</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -1,6 +1,6 @@
package seng302.Networking.MessageDecoders;
import seng302.Model.BoatInRace;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -1,9 +1,7 @@
package seng302.Networking.MessageEncoders;
import seng302.Model.BoatInRace;
import seng302.Networking.Utils.BoatLocationMessage;
import seng302.Networking.Utils.CourseWind;
import seng302.Networking.Utils.RaceMessage;
import seng302.Networking.Utils.*;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -24,38 +22,48 @@ public class RaceVisionByteEncoder {
return result;
}
public byte[] raceStatus(long time, int race, int raceState, long startTime, short raceWindDir, short raceWindSpeed, int raceType, ArrayList<BoatInRace> boats){
ByteBuffer raceStatusMessage = ByteBuffer.allocate(24 + 20*boats.size());
/**
* Serializes a RaceStatus message.
* @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*/){
ArrayList<BoatStatus> boatStatuses = raceStatus.getBoatStatuses();
ByteBuffer raceStatusMessage = ByteBuffer.allocate(24 + 20*boatStatuses.size());
//Version Number 1 bytes
byte versionNum = 0b10; //this changes with the pdf. (2)
byte[] timeBytes = longToBytes(time, 6);//time (6 bytes)
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[] expectedStart = longToBytes(startTime, 6);//number of milliseconds from Jan 1, 1970 for when the data is valid
byte[] raceWind = ByteBuffer.allocate(2).put(shortToBytes(raceWindDir)).array();//North = 0x0000 East = 0x4000 South = 0x8000
byte[] windSpeed = ByteBuffer.allocate(2).put(shortToBytes(raceWindSpeed)).array();//mm/sec
byte[] numBoats = intToBytes(boats.size(), 1);
byte[] bytesRaceType = intToBytes(raceType, 1);//1 match race, 2 fleet race
byte[] timeBytes = longToBytes(raceStatus.getCurrentTime(), 6);//time (6 bytes)
byte[] raceID = ByteBuffer.allocate(4).put(intToBytes(raceStatus.getRaceID())).array();//race identifier incase multiple races are going at once.
byte[] raceStatusByte = intToBytes(raceStatus.getRaceStatus(), 1);//race status 0 - 10
byte[] expectedStart = longToBytes(raceStatus.getExpectedStartTime(), 6);//number of milliseconds from Jan 1, 1970 for when the data is valid
byte[] raceWind = ByteBuffer.allocate(2).put(intToBytes(raceStatus.getWindDirection(), 2)).array();//North = 0x0000 East = 0x4000 South = 0x8000.
byte[] windSpeed = ByteBuffer.allocate(2).put(intToBytes(raceStatus.getWindSpeed(), 2)).array();//mm/sec
byte[] numBoats = intToBytes(boatStatuses.size(), 1);
byte[] bytesRaceType = intToBytes(raceStatus.getRaceType(), 1);//1 match race, 2 fleet race
raceStatusMessage.put(versionNum);
raceStatusMessage.put(timeBytes);
raceStatusMessage.put(raceID);
raceStatusMessage.put(raceStatus);
raceStatusMessage.put(raceStatusByte);
raceStatusMessage.put(expectedStart);
raceStatusMessage.put(raceWind);
raceStatusMessage.put(windSpeed);
raceStatusMessage.put(numBoats);
raceStatusMessage.put(bytesRaceType);
for (int i = 0; i < boats.size(); i++){
int sourceID = 0; //TODO use boats source id.
byte[] legNum = intToBytes(boats.get(i).getCurrentLeg().getLegNumber(), 1);
byte[] numPenalties = intToBytes(0, 1); //TODO use boats in race penalties class
byte[] numPenaltiesServed = intToBytes(0, 1);//TODO use boats in race penalites served.
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.
for (int i = 0; i < boatStatuses.size(); i++){
byte[] sourceID = intToBytes(boatStatuses.get(i).getSourceID());
byte[] boatStatus = intToBytes(boatStatuses.get(i).getBoatStatus(), 1);
byte[] legNum = intToBytes(boatStatuses.get(i).getLegNumber(), 1);
byte[] numPenalties = intToBytes(boatStatuses.get(i).getNumPenaltiesAwarded(), 1);
byte[] numPenaltiesServed = intToBytes(boatStatuses.get(i).getNumPenaltiesServed(), 1);
byte[] estNextMarkTime = longToBytes(boatStatuses.get(i).getEstTimeAtNextMark(), 6);
byte[] estFinishTime = longToBytes( boatStatuses.get(i).getEstTimeAtFinish(), 6);
raceStatusMessage.put(intToBytes(sourceID));
raceStatusMessage.put(sourceID);
raceStatusMessage.put(boatStatus);
raceStatusMessage.put(legNum);
raceStatusMessage.put(numPenalties);
raceStatusMessage.put(numPenaltiesServed);
@@ -162,11 +170,11 @@ public class RaceVisionByteEncoder {
return result.array();
}
public byte[] boatLocation(BoatLocationMessage boatLocationMessage){
public static byte[] boatLocation(BoatLocationMessage boatLocationMessage){
int messageVersionNumber = 0b1;
byte[] time = longToBytes(boatLocationMessage.getTime(), 6);
byte[] sourceID = intToBytes(boatLocationMessage.getSourceID(), 4);
byte[] seqNum = intToBytes(boatLocationMessage.getSequenceNumber(), 4);
byte[] seqNum = longToBytes(boatLocationMessage.getSequenceNumber(), 4);
byte[] deviceType = intToBytes(boatLocationMessage.getDeviceType(), 1);
byte[] latitude = intToBytes(boatLocationMessage.getLatitude(), 4);
byte[] longitude = intToBytes(boatLocationMessage.getLongitude(), 4);
@@ -20,13 +20,13 @@ public class XMLMessageEncoder {
private short xmlMsgLength;
private String xmlMessage;
public XMLMessageEncoder(short ackNumber, long timeStamp, int xmlMsgSubType, short sequenceNumber, short xmlMsgLenght, String xmlMessage) {
public XMLMessageEncoder(short ackNumber, long timeStamp, int xmlMsgSubType, short sequenceNumber, short xmlMsgLength, String xmlMessage) {
this.messageVersionNumber = intToBytes(1, 1);
this.ackNumber = ackNumber;
this.timeStamp = timeStamp;
this.xmlMsgSubType = intToBytes(xmlMsgSubType, 1);
this.sequenceNumber = sequenceNumber;
this.xmlMsgLength = xmlMsgLenght;
this.xmlMsgLength = xmlMsgLength;
this.xmlMessage = xmlMessage;
}
@@ -4,26 +4,37 @@ package seng302.Networking.Utils;
* Created by f123 on 21-Apr-17.
*/
import SharedModel.Constants;
/**
* Represents the information in a boat location message (AC streaming spec: 4.9).
*/
public class BoatLocationMessage extends AC35Data
{
public static final byte Unknown = 0;
public static final byte RacingYacht = 1;
public static final byte CommitteeBoat = 2;
public static final byte Mark = 3;
public static final byte Pin = 4;
public static final byte ChaseBoat = 5;
public static final byte MedicalBoat = 6;
public static final byte MarshallBoat = 7;
public static final byte UmpireBoat = 8;
public static final byte UmpireSoftwareApplication = 9;
public static final byte PrincipalRaceOfficerApplication = 10;
public static final byte WeatherStation = 11;
public static final byte Helicopter = 12;
public static final byte DataProcessingApplication = 13;
///Version number of the message - is always 1.
private int messageVersionNumber = 1;
private byte messageVersionNumber = 1;
///Time of the event - milliseconds since jan 1 1970. Proper type is 6 byte int.
private long time;
///Source ID of the boat.
private int sourceID;
///Sequence number of the message.
private int sequenceNumber;
private long sequenceNumber;
///Device type of the message (physical source of the message).
private int deviceType;
private byte deviceType;
///Latitude of the boat.
private int latitude;
@@ -37,10 +48,10 @@ public class BoatLocationMessage extends AC35Data
private int heading;
///Pitch of the boat.
private int pitch;
private short pitch;
///Roll of the boat.
private int roll;
private short roll;
///Speed of the boat. Proper type is unsigned 2 byte int. millimeters per second.
private int boatSpeed;
@@ -55,15 +66,16 @@ public class BoatLocationMessage extends AC35Data
private int apparentWindSpeed;
///Apparent wind angle at time of the event. Wind over starboard = positive.
private int apparentWindAngle;
private short apparentWindAngle;
///True wind speed. Proper type is unsigned 2 byte int. millimeters per second.
private int trueWindSpeed;
///True wind direction. Proper type is unsigned 2 byte int. 0x0000 = North, etc..
private int trueWindDirection;
///True wind angle. Clockwise compass direction, 0 = north.
private int trueWindAngle;
private short trueWindAngle;
///Current drift. Proper type is unsigned 2 byte int. millimeters per second.
private int currentDrift;
@@ -72,19 +84,19 @@ public class BoatLocationMessage extends AC35Data
private int currentSet;
///Rudder angle. Positive is rudder set to turn yacht to port.
private int rudderAngle;
private short rudderAngle;
/**
* Ctor.
* Ctor. Default.
*/
public BoatLocationMessage(MessageType type)
{
super(type);
public BoatLocationMessage() {
super(MessageType.BOATLOCATION);
}
/**
* Ctor, with all parameters.
*
* @param messageVersionNumber
* @param time
* @param sourceID
@@ -108,9 +120,9 @@ public class BoatLocationMessage extends AC35Data
* @param currentSet
* @param rudderAngle
*/
public BoatLocationMessage(int messageVersionNumber, long time, int sourceID, int sequenceNumber, int deviceType, int latitude, int longitude, int altitude, int heading, int pitch, int roll, int boatSpeed, int boatCOG, int boatSOG, int apparentWindSpeed, int apparentWindAngle, int trueWindSpeed, int trueWindDirection, int trueWindAngle, int currentDrift, int currentSet, int 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, int trueWindDirection, short trueWindAngle, int currentDrift, int currentSet, short rudderAngle) {
super(MessageType.BOATLOCATION);
this.messageVersionNumber = messageVersionNumber;
this.time = time;
this.sourceID = sourceID;
@@ -138,222 +150,364 @@ public class BoatLocationMessage extends AC35Data
//Getters and setters for message properties.
public int getMessageVersionNumber()
{
/**
* Converts a double representing a latitude or longitude coordinate to an int, as required by the streaming spec format.
*
* @param coordinate Latitude or longitude to convert. Double.
* @return int representation of coordinate.
*/
public static int convertCoordinateDoubleToInt(double coordinate) {
int coordinateInt = (int) ((coordinate / 180.0) * 2147483648.0);
return coordinateInt;
}
/**
* Converts an int representing a latitude or longitude coordinate to a double, as required by the streaming spec format.
*
* @param coordinate Latitude or longitude to convert. int.
* @return double representation of coordinate.
*/
public static double convertCoordinateIntToDouble(int coordinate) {
double coordinateDouble = (double) ((coordinate * 180.0) / 2147483648.0);
return coordinateDouble;
}
/**
* Converts an int representing a heading to a double, as required by the streaming spec format.
*
* @param heading Heading to convert. int.
* @return double representation of heading.
*/
public static double convertHeadingIntToDouble(int heading) {
double headingDouble = (double) ((heading * 360.0) / 65536.0);
return headingDouble;
}
/**
* Converts a double representing a heading to an int, as required by the streaming spec format.
*
* @param heading Heading to convert. double.
* @return int representation of heading.
*/
public static int convertHeadingDoubleToInt(double heading) {
int headingInt = (int) ((heading / 360.0) * 65536.0);
return headingInt;
}
/**
* Converts a short representing the wind's true angle to a double, as required by the streaming spec format.
*
* @param angle Angle to convert. short.
* @return double representation of heading.
*/
public static double convertTrueWindAngleShortToDouble(short angle) {
double angleDouble = (double) ((angle * 180.0) / 32768.0);
return angleDouble;
}
/**
* Converts a double representing the wind's true angle to a short, as required by the streaming spec format.
*
* @param angle Angle to convert. double.
* @return short representation of heading.
*/
public static short convertTrueWindAngleShortToDouble(double angle) {
short angleShort = (short) ((angle / 180.0) * 32768.0);
return angleShort;
}
/**
* Converts a double representing the speed of a boat in knots to an int in millimeters per second, as required by the streaming spec format.
*
* @param speed Speed in knots, stored as a double.
* @return Speed in millimeters per second, stored as an int (using only the two least significant bytes).
*/
public static int convertBoatSpeedDoubleToInt(double speed) {
//Calculate meters per second.
double metersPerSecond = speed * Constants.KnotsToMetersPerSecondConversionFactor;
//Calculate millimeters per second.
double millimetersPerSecond = metersPerSecond * 1000.0;
//Convert to an int.
int millimetersPerSecondInt = (int) Math.round(millimetersPerSecond);
return millimetersPerSecondInt;
}
/**
* Converts an int representing the speed of a boat in millimeters per second to a double in knots, as required by the streaming spec format.
*
* @param speed Speed in millimeters per second, stored as an int.
* @return Speed in knots, stored as a double.
*/
public static double convertBoatSpeedIntToDouble(int speed) {
//Calculate meters per second.
double metersPerSecond = speed / 1000.0;
//Calculate knots.
double knots = metersPerSecond / Constants.KnotsToMetersPerSecondConversionFactor;
return knots;
}
public byte getMessageVersionNumber() {
return messageVersionNumber;
}
public void setMessageVersionNumber(int messageVersionNumber)
{
public void setMessageVersionNumber(byte messageVersionNumber) {
this.messageVersionNumber = messageVersionNumber;
}
public long getTime()
{
public long getTime() {
return time;
}
public void setTime(long time)
{
public void setTime(long time) {
this.time = time;
}
public int getSourceID()
{
public int getSourceID() {
return sourceID;
}
public void setSourceID(int sourceID)
{
public void setSourceID(int sourceID) {
this.sourceID = sourceID;
}
public int getSequenceNumber()
{
public long getSequenceNumber() {
return sequenceNumber;
}
public void setSequenceNumber(int sequenceNumber)
{
public void setSequenceNumber(long sequenceNumber) {
this.sequenceNumber = sequenceNumber;
}
public int getDeviceType()
{
public byte getDeviceType() {
return deviceType;
}
public void setDeviceType(int deviceType)
{
public void setDeviceType(byte deviceType) {
this.deviceType = deviceType;
}
public int getLatitude()
{
public int getLatitude() {
return latitude;
}
public void setLatitude(int latitude)
{
public void setLatitude(int latitude) {
this.latitude = latitude;
}
public int getLongitude()
{
public int getLongitude() {
return longitude;
}
public void setLongitude(int longitude)
{
public void setLongitude(int longitude) {
this.longitude = longitude;
}
public int getAltitude()
{
public int getAltitude() {
return altitude;
}
public void setAltitude(int altitude)
{
public void setAltitude(int altitude) {
this.altitude = altitude;
}
public int getHeading()
{
public int getHeading() {
return heading;
}
public void setHeading(int heading)
{
public void setHeading(int heading) {
this.heading = heading;
}
public int getPitch()
{
public short getPitch() {
return pitch;
}
public void setPitch(int pitch)
{
public void setPitch(short pitch) {
this.pitch = pitch;
}
public int getRoll()
{
public short getRoll() {
return roll;
}
public void setRoll(int roll)
{
public void setRoll(short roll) {
this.roll = roll;
}
public int getBoatSpeed()
{
public int getBoatSpeed() {
return boatSpeed;
}
public void setBoatSpeed(int boatSpeed)
{
public void setBoatSpeed(int boatSpeed) {
this.boatSpeed = boatSpeed;
}
public int getBoatCOG()
{
public int getBoatCOG() {
return boatCOG;
}
public void setBoatCOG(int boatCOG)
{
public void setBoatCOG(int boatCOG) {
this.boatCOG = boatCOG;
}
public int getBoatSOG()
{
public int getBoatSOG() {
return boatSOG;
}
public void setBoatSOG(int boatSOG)
{
public void setBoatSOG(int boatSOG) {
this.boatSOG = boatSOG;
}
public int getApparentWindSpeed()
{
public int getApparentWindSpeed() {
return apparentWindSpeed;
}
public void setApparentWindSpeed(int apparentWindSpeed)
{
public void setApparentWindSpeed(int apparentWindSpeed) {
this.apparentWindSpeed = apparentWindSpeed;
}
public int getApparentWindAngle()
{
public short getApparentWindAngle() {
return apparentWindAngle;
}
public void setApparentWindAngle(int apparentWindAngle)
{
public void setApparentWindAngle(short apparentWindAngle) {
this.apparentWindAngle = apparentWindAngle;
}
public int getTrueWindSpeed()
{
public int getTrueWindSpeed() {
return trueWindSpeed;
}
public void setTrueWindSpeed(int trueWindSpeed)
{
public void setTrueWindSpeed(int trueWindSpeed) {
this.trueWindSpeed = trueWindSpeed;
}
public int getTrueWindDirection() {
public int getTrueWindDirection()
{
return trueWindDirection;
}
public void setTrueWindDirection(int trueWindDirection) {
public void setTrueWindDirection(int trueWindDirection)
{
this.trueWindDirection = trueWindDirection;
}
public int getTrueWindAngle()
{
public short getTrueWindAngle() {
return trueWindAngle;
}
public void setTrueWindAngle(int trueWindAngle)
{
public void setTrueWindAngle(short trueWindAngle) {
this.trueWindAngle = trueWindAngle;
}
public int getCurrentDrift()
{
public int getCurrentDrift() {
return currentDrift;
}
public void setCurrentDrift(int currentDrift)
{
public void setCurrentDrift(int currentDrift) {
this.currentDrift = currentDrift;
}
public int getCurrentSet()
{
public int getCurrentSet() {
return currentSet;
}
public void setCurrentSet(int currentSet)
{
public void setCurrentSet(int currentSet) {
this.currentSet = currentSet;
}
public int getRudderAngle()
{
public short getRudderAngle() {
return rudderAngle;
}
public void setRudderAngle(int rudderAngle)
{
public void setRudderAngle(short rudderAngle) {
this.rudderAngle = rudderAngle;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Message version number: ");
builder.append(this.getMessageVersionNumber());
builder.append("\nTime: ");
builder.append(this.getTime());
builder.append("\nSource ID: ");
builder.append(this.getSourceID());
builder.append("\nSequence number: ");
builder.append(this.getSequenceNumber());
builder.append("\nDevice type: ");
builder.append(this.getDeviceType());
builder.append("\nLatitude: ");
builder.append(this.getLatitude());
builder.append("\nLongitude: ");
builder.append(this.getLongitude());
builder.append("\nAltitude: ");
builder.append(this.getAltitude());
builder.append("\nHeading: ");
builder.append(this.getHeading());
builder.append("\nPitch: ");
builder.append(this.getPitch());
builder.append("\nRoll: ");
builder.append(this.getRoll());
builder.append("\nBoat speed (mm/sec): ");
builder.append(this.getBoatSpeed());
builder.append("\nBoat COG: ");
builder.append(this.getBoatCOG());
builder.append("\nBoat SOG: ");
builder.append(this.getBoatSOG());
builder.append("\nApparent wind speed: ");
builder.append(this.getApparentWindSpeed());
builder.append("\nApparent wind angle: ");
builder.append(this.getApparentWindAngle());
builder.append("\nTrue wind speed: ");
builder.append(this.getTrueWindSpeed());
builder.append("\nTrue wind angle: ");
builder.append(this.getTrueWindAngle());
builder.append("\nCurrent drift: ");
builder.append(this.getCurrentDrift());
builder.append("\nCurrent set: ");
builder.append(this.getCurrentSet());
builder.append("\nRudder angle: ");
builder.append(this.getRudderAngle());
return builder.toString();
}
}
@@ -6,14 +6,14 @@ import java.util.ArrayList;
* Created by fwy13 on 25/04/17.
*/
public class RaceStatus extends AC35Data{
long currentTime;
int raceID;
int raceStatus;
long expectedStartTime;
int windDirection;
int windSpeed;
int raceType;
ArrayList<BoatStatus> boatStatuses;
private long currentTime;
private int raceID;
private int raceStatus;
private long expectedStartTime;
private int windDirection;
private int windSpeed;
private int raceType;
private ArrayList<BoatStatus> boatStatuses;
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList<BoatStatus> boatStatuses){
super(MessageType.RACESTATUS);
@@ -27,4 +27,46 @@ public class RaceStatus extends AC35Data{
this.boatStatuses = boatStatuses;//note this is a copy so any alterations to the parent will affect this.
}
}
///Getters.
public long getCurrentTime()
{
return currentTime;
}
public int getRaceID()
{
return raceID;
}
public int getRaceStatus()
{
return raceStatus;
}
public long getExpectedStartTime()
{
return expectedStartTime;
}
public int getWindDirection()
{
return windDirection;
}
public int getWindSpeed()
{
return windSpeed;
}
public int getRaceType()
{
return raceType;
}
public ArrayList<BoatStatus> getBoatStatuses()
{
return boatStatuses;
}
}
@@ -13,11 +13,11 @@ public class BoatLocationDecoderTest {
@Test
public void getByteArrayTest(){
long time = System.currentTimeMillis();
BoatLocationMessage testMessage = new BoatLocationMessage(1, time, 2,
3, 1, 180, -180, 4, 5,
6, 7, 8, 9, 10, 11,
12, 13, 14 , 15,
16, 17, 18);
BoatLocationMessage testMessage = new BoatLocationMessage((byte) 1, time, 2,
3, (byte) 1, 180, -180, 4, 5,
(short) 6, (short) 7, 8, 9, 10, 11,
(short) 12, 13, 14 , (short) 15,
16, 17, (short) 18);
RaceVisionByteEncoder raceVisionByteEncoder = new RaceVisionByteEncoder();
byte [] testEncodedMessage = raceVisionByteEncoder.boatLocation(testMessage);
@@ -1,11 +1,10 @@
package seng302.Networking.MessageDecoders;
import javafx.scene.paint.Color;
import org.junit.Assert;
import org.junit.Test;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
import seng302.Networking.Utils.BoatStatus;
import seng302.Networking.Utils.RaceStatus;
import java.util.ArrayList;
@@ -16,34 +15,54 @@ public class RaceStatusDecoderTest {
@Test
public void getByteArrayTest(){
long time = System.currentTimeMillis();
BoatInRace boat1 = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
Leg testLeg = new Leg("test leg", 1);
boat1.setCurrentLeg(testLeg);
BoatInRace boat2 = new BoatInRace("Test2", 1, Color.ALICEBLUE, "tt");
boat2.setCurrentLeg(testLeg);
ArrayList boats = new ArrayList();
boats.add(boat1);
boats.add(boat2);
long time2 = System.currentTimeMillis();
RaceVisionByteEncoder raceVisionByteEncoder = new RaceVisionByteEncoder();
//Create data to serialize.
int boat1SourceID = 5;
int boat2SourceID = 8;
byte boat1Status = 2;
byte boat2Status = 2;
byte boat1LegNumber = 5;
byte boat2LegNumber = 3;
byte boat1PenaltiesAwarded = 4;
byte boat2PenaltiesAwarded = 0;
byte boat1PenaltiesServed = 2;
byte boat2PenaltiesServed = 0;
long boat1TimeAtNextMark = time + (1000 * 3);
long boat2TimeAtNextMark = time + (1000 * 2);
long boat1TimeAtFinish = boat1TimeAtNextMark + (1000 * 15);
long boat2TimeAtFinish = boat2TimeAtNextMark + (1000 * 7);
byte[] encodedRaceStatus = raceVisionByteEncoder.raceStatus(time, 1, 2, time2,
(short)2, (short)3,4, boats);
BoatStatus boatStatus1 = new BoatStatus(boat1SourceID, boat1Status, boat1LegNumber, boat1PenaltiesAwarded, boat1PenaltiesServed, boat1TimeAtNextMark, boat1TimeAtFinish);
BoatStatus boatStatus2 = new BoatStatus(boat2SourceID, boat2Status, boat2LegNumber, boat2PenaltiesAwarded, boat2PenaltiesServed, boat2TimeAtNextMark, boat2TimeAtFinish);
int raceID = 585;
int raceStatus = 3;
long raceStartTime = time - (1000 * 31);
int windDirection = 2341;
int windSpeed = 10201;
int raceType = 1;
ArrayList<BoatStatus> boatStatuses = new ArrayList<>(2);
boatStatuses.add(boatStatus1);
boatStatuses.add(boatStatus2);
RaceStatus raceStatusObject = new RaceStatus(time, raceID, raceStatus, raceStartTime, windDirection, windSpeed, raceType, boatStatuses);
byte[] encodedRaceStatus = RaceVisionByteEncoder.raceStatus(raceStatusObject);
RaceStatusDecoder decoderTest = new RaceStatusDecoder(encodedRaceStatus);
Assert.assertEquals(0b10, decoderTest.getVersionNum());
Assert.assertEquals(time, decoderTest.getTime());
Assert.assertEquals(1, decoderTest.getRace());
Assert.assertEquals(2, decoderTest.getRaceState());
Assert.assertEquals(time2, decoderTest.getStartTime());
Assert.assertEquals(2, decoderTest.getRaceWindDir());
Assert.assertEquals((short)3, decoderTest.getRaceWindSpeed());
Assert.assertEquals(raceID, decoderTest.getRace());
Assert.assertEquals(raceStatus, decoderTest.getRaceState());
Assert.assertEquals(raceStartTime, decoderTest.getStartTime());
Assert.assertEquals(windDirection, decoderTest.getRaceWindDir());
Assert.assertEquals(windSpeed, decoderTest.getRaceWindSpeed());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getBoatStatus());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getLegNumber());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getNumPenaltiesAwarded());
Assert.assertEquals(boat1Status, decoderTest.getBoats().get(0).getBoatStatus());
Assert.assertEquals(boat1LegNumber, decoderTest.getBoats().get(0).getLegNumber());
Assert.assertEquals(boat1PenaltiesAwarded, decoderTest.getBoats().get(0).getNumPenaltiesAwarded());
}
}