Merge remote-tracking branch 'origin/networkingTest' into networkingTest

main
hba56 9 years ago
commit ee24ecaadc

@ -0,0 +1,345 @@
package seng302.Networking;
/**
* Created by f123 on 21-Apr-17.
*/
/**
* Represents the information in a boat location message (AC streaming spec: 4.9).
*/
public class BoatLocationMessage
{
///Version number of the message - is always 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 long sequenceNumber;
///Device type of the message (physical source of the message).
private byte deviceType;
///Latitude of the boat.
private int latitude;
///Longitude of the boat.
private int longitude;
///Altitude of the boat.
private int altitude;
///Heading of the boat. Clockwise, 0 = north. Proper type is unsigned 2 byte int.
private int heading;
///Pitch of the boat.
private short pitch;
///Roll of the boat.
private short roll;
///Speed of the boat. Proper type is unsigned 2 byte int. millimeters per second.
private int boatSpeed;
///Course over ground (COG) of the boat. Proper type is unsigned 2 byte int.
private int boatCOG;
///Speed over ground (SOG) of the boat. Proper type is unsigned 2 byte int. millimeters per second.
private int boatSOG;
///Apparent wind speed at time of event. Proper type is unsigned 2 byte int. millimeters per second.
private int apparentWindSpeed;
///Apparent wind angle at time of the event. Wind over starboard = positive.
private short apparentWindAngle;
///True wind speed. Proper type is unsigned 2 byte int. millimeters per second.
private int trueWindSpeed;
///True wind angle. Clockwise compass direction, 0 = north.
private short trueWindAngle;
///Current drift. Proper type is unsigned 2 byte int. millimeters per second.
private int currentDrift;
///Current set. Proper type is unsigned 2 byte int. Clockwise compass direction, 0 = north.
private int currentSet;
///Rudder angle. Positive is rudder set to turn yacht to port.
private short rudderAngle;
/**
* Ctor.
*/
public BoatLocationMessage()
{
}
/**
* Ctor, with all parameters.
* @param messageVersionNumber
* @param time
* @param sourceID
* @param sequenceNumber
* @param deviceType
* @param latitude
* @param longitude
* @param altitude
* @param heading
* @param pitch
* @param roll
* @param boatSpeed
* @param boatCOG
* @param boatSOG
* @param apparentWindSpeed
* @param apparentWindAngle
* @param trueWindSpeed
* @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)
{
this.messageVersionNumber = messageVersionNumber;
this.time = time;
this.sourceID = sourceID;
this.sequenceNumber = sequenceNumber;
this.deviceType = deviceType;
this.latitude = latitude;
this.longitude = longitude;
this.altitude = altitude;
this.heading = heading;
this.pitch = pitch;
this.roll = roll;
this.boatSpeed = boatSpeed;
this.boatCOG = boatCOG;
this.boatSOG = boatSOG;
this.apparentWindSpeed = apparentWindSpeed;
this.apparentWindAngle = apparentWindAngle;
this.trueWindSpeed = trueWindSpeed;
this.trueWindAngle = trueWindAngle;
this.currentDrift = currentDrift;
this.currentSet = currentSet;
this.rudderAngle = rudderAngle;
}
//Getters and setters for message properties.
public byte getMessageVersionNumber()
{
return messageVersionNumber;
}
public void setMessageVersionNumber(byte messageVersionNumber)
{
this.messageVersionNumber = messageVersionNumber;
}
public long getTime()
{
return time;
}
public void setTime(long time)
{
this.time = time;
}
public int getSourceID()
{
return sourceID;
}
public void setSourceID(int sourceID)
{
this.sourceID = sourceID;
}
public long getSequenceNumber()
{
return sequenceNumber;
}
public void setSequenceNumber(long sequenceNumber)
{
this.sequenceNumber = sequenceNumber;
}
public byte getDeviceType()
{
return deviceType;
}
public void setDeviceType(byte deviceType)
{
this.deviceType = deviceType;
}
public int getLatitude()
{
return latitude;
}
public void setLatitude(int latitude)
{
this.latitude = latitude;
}
public int getLongitude()
{
return longitude;
}
public void setLongitude(int longitude)
{
this.longitude = longitude;
}
public int getAltitude()
{
return altitude;
}
public void setAltitude(int altitude)
{
this.altitude = altitude;
}
public int getHeading()
{
return heading;
}
public void setHeading(int heading)
{
this.heading = heading;
}
public short getPitch()
{
return pitch;
}
public void setPitch(short pitch)
{
this.pitch = pitch;
}
public short getRoll()
{
return roll;
}
public void setRoll(short roll)
{
this.roll = roll;
}
public int getBoatSpeed()
{
return boatSpeed;
}
public void setBoatSpeed(int boatSpeed)
{
this.boatSpeed = boatSpeed;
}
public int getBoatCOG()
{
return boatCOG;
}
public void setBoatCOG(int boatCOG)
{
this.boatCOG = boatCOG;
}
public int getBoatSOG()
{
return boatSOG;
}
public void setBoatSOG(int boatSOG)
{
this.boatSOG = boatSOG;
}
public int getApparentWindSpeed()
{
return apparentWindSpeed;
}
public void setApparentWindSpeed(int apparentWindSpeed)
{
this.apparentWindSpeed = apparentWindSpeed;
}
public short getApparentWindAngle()
{
return apparentWindAngle;
}
public void setApparentWindAngle(short apparentWindAngle)
{
this.apparentWindAngle = apparentWindAngle;
}
public int getTrueWindSpeed()
{
return trueWindSpeed;
}
public void setTrueWindSpeed(int trueWindSpeed)
{
this.trueWindSpeed = trueWindSpeed;
}
public short getTrueWindAngle()
{
return trueWindAngle;
}
public void setTrueWindAngle(short trueWindAngle)
{
this.trueWindAngle = trueWindAngle;
}
public int getCurrentDrift()
{
return currentDrift;
}
public void setCurrentDrift(int currentDrift)
{
this.currentDrift = currentDrift;
}
public int getCurrentSet()
{
return currentSet;
}
public void setCurrentSet(int currentSet)
{
this.currentSet = currentSet;
}
public short getRudderAngle()
{
return rudderAngle;
}
public void setRudderAngle(short rudderAngle)
{
this.rudderAngle = rudderAngle;
}
}

@ -0,0 +1,54 @@
package seng302.Networking;
/**
* Created by fwy13 on 21/04/17.
*/
public class CourseWind {
private int ID, raceID, windDirection, windSpeed, bestUpwindAngle, bestDownwindAngle, flags;
private long time;
public CourseWind(int ID, long time, int raceID, int windDirection, int windSpeed, int bestUpwindAngle, int bestDownwindAngle,
int flags){
this.ID = ID;
this.time = time;
this.raceID = raceID;
this.windDirection = windDirection;
this.windSpeed = windSpeed;
this.bestUpwindAngle = bestUpwindAngle;
this.bestDownwindAngle = bestDownwindAngle;
this.flags = flags;
}
public int getID() {
return ID;
}
public int getRaceID() {
return raceID;
}
public int getWindDirection() {
return windDirection;
}
public int getWindSpeed() {
return windSpeed;
}
public int getBestUpwindAngle() {
return bestUpwindAngle;
}
public int getBestDownwindAngle() {
return bestDownwindAngle;
}
public int getFlags() {
return flags;
}
public long getTime() {
return time;
}
}

@ -156,10 +156,126 @@ public class RaceVisionByteEncoder {
return result.array();
}
/*
public byte[] boatLocation(){
}*/
public byte[] boatLocation(BoatLocationMessage boatLocationMessage){
int messageVersionNumber = 0b1;
byte[] time = convert(boatLocationMessage.getTime(), 6);
byte[] sourceID = convert(boatLocationMessage.getSourceID(), 4);
byte[] seqNum = convert(boatLocationMessage.getSequenceNumber(), 4);
byte[] deviceType = convert(boatLocationMessage.getDeviceType(), 1);
byte[] latitude = convert(boatLocationMessage.getLatitude(), 4);
byte[] longitude = convert(boatLocationMessage.getLongitude(), 4);
byte[] altitude = convert(boatLocationMessage.getAltitude(), 4);
byte[] heading = convert(boatLocationMessage.getHeading(), 2);
byte[] pitch = convert(boatLocationMessage.getPitch(), 2);
byte[] roll = convert(boatLocationMessage.getRoll(), 2);
byte[] boatSpeed = convert(boatLocationMessage.getBoatSpeed(), 2);
byte[] cog = convert(boatLocationMessage.getBoatCOG(), 2);
byte[] sog = convert(boatLocationMessage.getBoatSOG(), 2);
byte[] apparentWindSpeed = convert(boatLocationMessage.getApparentWindSpeed(), 2);
byte[] apparentWindAngle = convert(boatLocationMessage.getApparentWindAngle(), 2);
byte[] trueWindSpeed = convert(boatLocationMessage.getTrueWindSpeed(), 2);
byte[] trueWindAngle = convert(boatLocationMessage.getTrueWindAngle(), 2);
byte[] currentDrift = convert(boatLocationMessage.getCurrentDrift(), 2);
byte[] currentSet = convert(boatLocationMessage.getCurrentSet(), 2);
byte[] rudderAngle = convert(boatLocationMessage.getRudderAngle(), 2);
ByteBuffer result = ByteBuffer.allocate(56);
result.put(convert(messageVersionNumber, 1));
result.put(time);
result.put(sourceID);
result.put(seqNum);
result.put(deviceType);
result.put(latitude);
result.put(longitude);
result.put(altitude);
result.put(heading);
result.put(pitch);
result.put(roll);
result.put(boatSpeed);
result.put(cog);
result.put(sog);
result.put(apparentWindSpeed);
result.put(apparentWindAngle);
result.put(trueWindSpeed);
result.put(trueWindAngle);
result.put(currentDrift);
result.put(currentSet);
result.put(rudderAngle);
return result.array();
}
public byte[] markRounding(int time, int ackNumber, int raceID, int sourceID, int boatStatus, int roundingSide, int markType, int markID){
int messageVersionNumber = 0b1;
byte[] byteTime = convert(time, 6);
byte[] byteAck = convert(ackNumber, 2);
byte[] byteRaceID = convert(raceID, 4);
byte[] byteSourceID = convert(sourceID, 4);
byte[] byteBoatStatus = convert(boatStatus, 1);
byte[] byteRoundingSide = convert(roundingSide, 1);
byte[] byteMarkType = convert(markType, 1);
byte[] byteMarkID = convert(markID, 1);
ByteBuffer result = ByteBuffer.allocate(21);
result.put(convert(messageVersionNumber, 1));
result.put(byteTime);
result.put(byteAck);
result.put(byteRaceID);
result.put(byteSourceID);
result.put(byteBoatStatus);
result.put(byteRoundingSide);
result.put(byteMarkType);
result.put(byteMarkID);
return result.array();
}
public byte[] courseWind(char windID, CourseWind[] courseWinds){
int messageVersionNumber = 0b1;
char byteWindID = windID;
byte[] loopcount = convert(courseWinds.length, 1);
ByteBuffer result = ByteBuffer.allocate(3 + 20 * courseWinds.length);
result.put(convert(messageVersionNumber, 1));
result.putChar(byteWindID);
result.put(loopcount);
for (CourseWind wind: courseWinds){
result.put(convert(wind.getID(), 1));
result.put(convert(wind.getTime(), 6));
result.put(convert(wind.getRaceID(), 4));
result.put(convert(wind.getWindDirection(), 2));
result.put(convert(wind.getWindSpeed(), 2));
result.put(convert(wind.getBestUpwindAngle(), 2));
result.put(convert(wind.getBestDownwindAngle(), 2));
result.put(convert(wind.getFlags(), 1));
}
return result.array();
}
public byte[] averageWind(int time, int rawPeriod, int rawSampleSpeed, int period2, int speed2, int period3, int speed3, int period4, int speed4){
int messageVersionNumber = 0b1;
byte[] byteTime = convert(time,6);
byte[] byteRawPeriod = convert(rawPeriod, 2);
byte[] byteRawSpeed = convert(rawSampleSpeed, 2);
byte[] bytePeriod2 = convert(period2, 2);
byte[] byteSpeed2 = convert(speed2, 2);
byte[] bytePeriod3 = convert(period3, 2);
byte[] byteSpeed3 = convert(speed3, 2);
byte[] bytePeriod4 = convert(period4, 2);
byte[] byteSpeed4 = convert(speed4, 2);
ByteBuffer result = ByteBuffer.allocate(23);
result.put(convert(messageVersionNumber, 1));
result.put(byteTime);
result.put(byteRawPeriod);
result.put(byteRawSpeed);
result.put(bytePeriod2);
result.put(byteSpeed2);
result.put(bytePeriod3);
result.put(byteSpeed3);
result.put(bytePeriod4);
result.put(byteSpeed4);
return result.array();
}
public byte[] convert(String s, int size){
byte[] m = s.getBytes(Charset.forName("UTF-8"));

Loading…
Cancel
Save