@ -1,130 +1,188 @@
package network.Messages ;
import network.Messages.Enums.BoatLocationDeviceEnum ;
import network.Messages.Enums.MessageType ;
import network.Utils.AC35UnitConverter ;
import shared.model.Constants ;
import shared.model.Azimuth ;
import shared.model.Bearing ;
import static network.Utils.AC35UnitConverter.unpackGPS ;
import static network.Utils.AC35UnitConverter.packGPS ;
/ * *
* Represents the information in a boat location message ( AC streaming spec : 4.9 ) .
* /
public class BoatLocation extends AC35Data {
//TODO move these to an enum.
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 ;
/ * *
* The current messageVersionNumber according to the API spec .
* /
public static final byte currentMessageVersionNumber = 1 ;
///Version number of the message.
/ * *
* Version number of the message .
* /
private byte messageVersionNumber ;
///Time of the event - milliseconds since jan 1 1970. Proper type is 6 byte int.
/ * *
* Time of the event - milliseconds since jan 1 1970. Proper type is 6 byte int .
* /
private long time ;
///Source ID of the boat.
/ * *
* Source ID of the boat .
* /
private int sourceID ;
///Sequence number of the message.
/ * *
* 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 ;
/ * *
* Device type of the message ( physical source of the message ) .
* /
private BoatLocationDeviceEnum deviceType ;
///Altitude of the boat.
/ * *
* Latitude of the boat .
* /
private double latitude ;
/ * *
* Longitude of the boat .
* /
private double 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 ;
/ * *
* Heading of the boat . Clockwise , 0 = north . Proper type is unsigned 2 byte int .
* /
private Bearing heading ;
///Pitch of the boat.
/ * *
* Pitch of the boat .
* /
private short pitch ;
///Roll of the boat.
/ * *
* Roll of the boat .
* /
private short roll ;
///Speed of the boat. Proper type is unsigned 2 byte int. millimeters per second.
private int boatSpeed ;
/ * *
* Speed of the boat , in knots .
* /
private double boatSpeedKnots ;
///Course over ground (COG) of the boat. Proper type is unsigned 2 byte int.
private int boatCOG ;
/ * *
* Course over ground ( COG ) of the boat .
* /
private Bearing boatCOG ;
///Speed over ground (SOG) of the boat. Proper type is unsigned 2 byte int. millimeters per second.
private int boatSOG ;
/ * *
* Speed over ground ( SOG ) of the boat , in knots .
* /
private double boatSOGKnots ;
///Apparent wind speed at time of event. Proper type is unsigned 2 byte int. millimeters per second.
private int apparentWindSpeed ;
/ * *
* Apparent wind speed at time of event . Proper type is unsigned 2 byte int . millimeters per second .
* /
private double apparentWindSpeedKnots ;
///Apparent wind angle at time of the event. Wind over starboard = positive.
private short apparentWindAngle ;
/ * *
* Apparent wind angle at time of the event . Wind over starboard = positive .
* /
private Azimuth apparentWindAngle ;
///True wind speed. Proper type is unsigned 2 byte int. millimeters per second.
private int trueWindSpeed ;
/ * *
* True wind speed , in knots .
* /
private double trueWindSpeedKnots ;
///True wind direction. Proper type is unsigned 2 byte int. 0x0000 = North, etc..
private int trueWindDirection ;
/ * *
* True wind direction .
* /
private Bearing trueWindDirection ;
///True wind angle. Clockwise compass direction, 0 = north.
private short trueWindAngle ;
/ * *
* True wind angle . Clockwise compass direction , 0 = north .
* /
private Azimuth trueWindAngle ;
///Current drift. Proper type is unsigned 2 byte int. millimeters per second.
private int currentDrift ;
/ * *
* Current drift , in knots .
* /
private double currentDriftKnots ;
///Current set. Proper type is unsigned 2 byte int. Clockwise compass direction, 0 = north.
private int currentSet ;
/ * *
* Current set .
* /
private Bearing currentSet ;
///Rudder angle. Positive is rudder set to turn yacht to port.
private short rudderAngle ;
/ * *
* Rudder angle . Positive is rudder set to turn yacht to port .
* /
private Azimuth rudderAngle ;
/ * *
* C tor, with all parameters .
* C onstructs a BoatLocation message with the given parameters .
*
* @param messageVersionNumber message number
* @param time time of message
* @param sourceID id of boat
* @param sequenceNumber number of boat message
* @param deviceType type of boat
* @param deviceType The source of the BoatLocation message .
* @param latitude lat of boat
* @param longitude lon of boat
* @param altitude altitude of boat
* @param heading heading of boat
* @param pitch pitch of boat
* @param roll roll of boat
* @param boatSpeed boats speed
* @param boatSpeed Knots boats speed
* @param boatCOG boat cog
* @param boatSOG boat sog
* @param apparentWindSpeed wind speed
* @param boatSOG Knots boat sog
* @param apparentWindSpeed Knots wind speed
* @param apparentWindAngle wind angle
* @param trueWindSpeed true wind speed
* @param trueWindSpeed Knots true wind speed
* @param trueWindDirection true wind direction
* @param trueWindAngle true wind angle
* @param currentDrift current drift
* @param currentDrift Knots current drift
* @param currentSet current set
* @param rudderAngle rudder angle
* /
public BoatLocation ( 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 ) {
public BoatLocation (
byte messageVersionNumber ,
long time ,
int sourceID ,
long sequenceNumber ,
BoatLocationDeviceEnum deviceType ,
double latitude ,
double longitude ,
int altitude ,
Bearing heading ,
short pitch ,
short roll ,
double boatSpeedKnots ,
Bearing boatCOG ,
double boatSOGKnots ,
double apparentWindSpeedKnots ,
Azimuth apparentWindAngle ,
double trueWindSpeedKnots ,
Bearing trueWindDirection ,
Azimuth trueWindAngle ,
double currentDriftKnots ,
Bearing currentSet ,
Azimuth rudderAngle ) {
super ( MessageType . BOATLOCATION ) ;
this . messageVersionNumber = messageVersionNumber ;
@ -138,348 +196,251 @@ public class BoatLocation extends AC35Data {
this . heading = heading ;
this . pitch = pitch ;
this . roll = roll ;
this . boatSpeed = boatSpeed ;
this . boatSpeed Knots = boatSpeed Knots ;
this . boatCOG = boatCOG ;
this . boatSOG = boatSOG ;
this . apparentWindSpeed = apparentWindSpeed ;
this . boatSOG Knots = boatSOG Knots ;
this . apparentWindSpeed Knots = apparentWindSpeed Knots ;
this . apparentWindAngle = apparentWindAngle ;
this . trueWindSpeed = trueWindSpeed ;
this . trueWindSpeed Knots = trueWindSpeed Knots ;
this . trueWindDirection = trueWindDirection ;
this . trueWindAngle = trueWindAngle ;
this . currentDrift = currentDrift ;
this . currentDrift Knots = currentDrift Knots ;
this . currentSet = currentSet ;
this . rudderAngle = rudderAngle ;
}
public BoatLocation ( int sourceID , double lat , double lon , long sequenceNumber , double heading , double boatSpeed , long time ) {
super ( MessageType . BOATLOCATION ) ;
this . messageVersionNumber = BoatLocation . currentMessageVersionNumber ;
this . time = time ;
this . sourceID = sourceID ;
this . sequenceNumber = sequenceNumber ;
this . deviceType = 1 ;
this . latitude = packGPS ( lat ) ;
this . longitude = packGPS ( lon ) ;
this . altitude = 0 ;
this . heading = convertHeadingDoubleToInt ( heading ) ;
this . pitch = 0 ;
this . roll = 0 ;
this . boatSpeed = convertBoatSpeedDoubleToInt ( boatSpeed ) ;
this . boatCOG = 0 ;
this . boatSOG = convertBoatSpeedDoubleToInt ( boatSpeed ) ;
this . apparentWindSpeed = 0 ;
this . apparentWindAngle = 0 ;
this . trueWindSpeed = 0 ;
this . trueWindDirection = 0 ;
this . trueWindAngle = 0 ;
this . currentDrift = 0 ;
this . currentSet = 0 ;
this . rudderAngle = 0 ;
}
//Getters and setters for message properties.
/ * *
* 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 * 65536.0 ) / 360.0 ) ;
return headingInt ;
public BoatLocation (
int sourceID ,
double lat ,
double lon ,
long sequenceNumber ,
BoatLocationDeviceEnum deviceType ,
Bearing heading ,
double boatSpeedKnots ,
long time ) {
this (
BoatLocation . currentMessageVersionNumber ,
time ,
sourceID ,
sequenceNumber ,
deviceType ,
lat ,
lon ,
0 ,
heading ,
( short ) 0 ,
( short ) 0 ,
boatSpeedKnots ,
heading ,
boatSpeedKnots ,
0 ,
Azimuth . fromDegrees ( 0 ) ,
0 ,
Bearing . fromDegrees ( 0 ) ,
Azimuth . fromDegrees ( 0 ) ,
0 ,
Bearing . fromDegrees ( 0 ) ,
Azimuth . fromDegrees ( 0 ) ) ;
}
/ * *
* 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 convertTrueWindAngleDoubleToShort ( 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 millimeters per second.
double millimetersPerSecond = speed * Constants . KnotsToMMPerSecond ;
//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 .
* Returns the version number of the message .
* @return The version number of the message .
* /
public static double convertBoatSpeedIntToDouble ( int speed ) {
//Calculate knots.
double knots = speed / Constants . KnotsToMMPerSecond ;
return knots ;
}
public byte getMessageVersionNumber ( ) {
return messageVersionNumber ;
}
public void setMessageVersionNumber ( byte messageVersionNumber ) {
this . messageVersionNumber = messageVersionNumber ;
}
/ * *
* Returns the time that this message was generated at .
* @return Time message was generated at , in milliseconds since unix epoch .
* /
public long getTime ( ) {
return time ;
}
public void setTime ( long time ) {
this . time = time ;
}
/ * *
* Returns the sourceID of the boat this message relates to .
* @return SourceID of the boat this message relates to .
* /
public int getSourceID ( ) {
return sourceID ;
}
public void setSourceID ( int sourceID ) {
this . sourceID = sourceID ;
}
/ * *
* Returns the sequence number of this message .
* @return The sequence number of the message .
* /
public long getSequenceNumber ( ) {
return sequenceNumber ;
}
public void setSequenceNumber ( long sequenceNumber ) {
this . sequenceNumber = sequenceNumber ;
}
public byte getDeviceType ( ) {
/ * *
* Returns the device source of this message .
* @return The device source of this message .
* /
public BoatLocationDeviceEnum getDeviceType ( ) {
return deviceType ;
}
public void setDeviceType ( byte deviceType ) {
this . deviceType = deviceType ;
}
public int getLatitude ( ) {
/ * *
* Returns the latitude , in degrees , that the boat is located at .
* @return Latitude , in degrees , of boat .
* /
public double getLatitude ( ) {
return latitude ;
}
public void setLatitude ( int latitude ) {
this . latitude = latitude ;
}
public int getLongitude ( ) {
/ * *
* Returns the longitude , in degrees , that the boat is located at .
* @return Longitude , in degrees , of boat .
* /
public double getLongitude ( ) {
return longitude ;
}
public double getLatitudeDouble ( ) {
return unpackGPS ( this . latitude ) ;
}
public double getLongitudeDouble ( ) {
return unpackGPS ( this . longitude ) ;
}
public void setLongitude ( int longitude ) {
this . longitude = longitude ;
}
/ * *
* Returns the altitude of the boat .
* @return The altitude of the boat .
* /
public int getAltitude ( ) {
return altitude ;
}
public void setAltitude ( int altitude ) {
this . altitude = altitude ;
}
public int getHeading ( ) {
/ * *
* Returns the current heading / bearing of the boat .
* @return Heading of the boat .
* /
public Bearing getHeading ( ) {
return heading ;
}
public void setHeading ( int heading ) {
this . heading = heading ;
}
/ * *
* Returns the current pitch of the boat .
* @return Pitch of the boat .
* /
public short getPitch ( ) {
return pitch ;
}
public void setPitch ( short pitch ) {
this . pitch = pitch ;
}
/ * *
* Returns the current roll of the boat .
* @return Roll of the boat .
* /
public short getRoll ( ) {
return roll ;
}
public void setRoll ( short roll ) {
this . roll = roll ;
}
public int getBoatSpeed ( ) {
return boatSpeed ;
/ * *
* Returns the current boat speed , in knots .
* @return Current boat speed , in knots .
* /
public double getBoatSpeedKnots ( ) {
return boatSpeedKnots ;
}
public void setBoatSpeed ( int boatSpeed ) {
this . boatSpeed = boatSpeed ;
}
public int getBoatCOG ( ) {
/ * *
* Returns the boat ' s Course Over Ground .
* @return Boat ' s COG .
* /
public Bearing getBoatCOG ( ) {
return boatCOG ;
}
public void setBoatCOG ( int boatCOG ) {
this . boatCOG = boatCOG ;
}
public int getBoatSOG ( ) {
return boatSOG ;
}
public void setBoatSOG ( int boatSOG ) {
this. boatSOG = boatSOG ;
/ * *
* Returns the boats Speed Over Ground , in knots .
* @return Boat ' s SOG .
* /
public double getBoatSOGKnots ( ) {
return boatSOGKnots ;
}
public int getApparentWindSpeed ( ) {
return apparentWindSpeed ;
}
public void setApparentWindSpeed ( int apparentWindSpeed ) {
this . apparentWindSpeed = apparentWindSpeed ;
/ * *
* Returns the apparent wind speed , in knots , at the boat .
* @return Wind speed , in knots , at the boat .
* /
public double getApparentWindSpeedKnots ( ) {
return apparentWindSpeedKnots ;
}
public short getApparentWindAngle ( ) {
/ * *
* Returns the apparent wind angle at the boat .
* @return Wind angle at the boat .
* /
public Azimuth getApparentWindAngle ( ) {
return apparentWindAngle ;
}
public void setApparentWindAngle ( short apparentWindAngle ) {
this . apparentWindAngle = apparentWindAngle ;
}
public int getTrueWindSpeed ( ) {
return trueWindSpeed ;
/ * *
* Returns the true wind speed , in knots .
* @return True wind speed , in knots .
* /
public double getTrueWindSpeedKnots ( ) {
return trueWindSpeedKnots ;
}
public void setTrueWindSpeed ( int trueWindSpeed ) {
this . trueWindSpeed = trueWindSpeed ;
}
public int getTrueWindDirection ( )
/ * *
* Returns the true wind direction .
* @return True wind direction .
* /
public Bearing getTrueWindDirection ( )
{
return trueWindDirection ;
}
public void setTrueWindDirection ( int trueWindDirection )
{
this . trueWindDirection = trueWindDirection ;
}
public short getTrueWindAngle ( ) {
/ * *
* Returns the true wind angle .
* @return True wind angle .
* /
public Azimuth getTrueWindAngle ( ) {
return trueWindAngle ;
}
public void setTrueWindAngle ( short trueWindAngle ) {
this . trueWindAngle = trueWindAngle ;
}
public int getCurrentDrift ( ) {
return currentDrift ;
/ * *
* Returns the current drift of the boat , in knots .
* @return Current drift , in knots .
* /
public double getCurrentDriftKnots ( ) {
return currentDriftKnots ;
}
public void setCurrentDrift ( int currentDrift ) {
this . currentDrift = currentDrift ;
}
public int getCurrentSet ( ) {
/ * *
* Returns the current set of the boat .
* @return Current set of the boat .
* /
public Bearing getCurrentSet ( ) {
return currentSet ;
}
public void setCurrentSet ( int currentSet ) {
this . currentSet = currentSet ;
}
public short getRudderAngle ( ) {
/ * *
* Returns the current rudder angle of the boat .
* @return Current rudder angle of the boat .
* /
public Azimuth getRudderAngle ( ) {
return rudderAngle ;
}
public void setRudderAngle ( short rudderAngle ) {
this . rudderAngle = rudderAngle ;
}
public double getHeadingDegrees ( ) {
return AC35UnitConverter . unpackHeading ( getHeading ( ) ) ;
}
public double getTrueWindAngleDegrees ( ) {
return AC35UnitConverter . unpackTrueWindAngle ( getTrueWindAngle ( ) ) ;
}
@Override
public String toString ( ) {
@ -519,28 +480,28 @@ public class BoatLocation extends AC35Data {
builder . append ( this . getRoll ( ) ) ;
builder . append ( "\nBoat speed (mm/sec): " ) ;
builder . append ( this . getBoatSpeed ( ) ) ;
builder . append ( this . getBoatSpeed Knots ( ) ) ;
builder . append ( "\nBoat COG: " ) ;
builder . append ( this . getBoatCOG ( ) ) ;
builder . append ( "\nBoat SOG: " ) ;
builder . append ( this . getBoatSOG ( ) ) ;
builder . append ( this . getBoatSOG Knots ( ) ) ;
builder . append ( "\nApparent wind speed: " ) ;
builder . append ( this . getApparentWindSpeed ( ) ) ;
builder . append ( this . getApparentWindSpeed Knots ( ) ) ;
builder . append ( "\nApparent wind angle: " ) ;
builder . append ( this . getApparentWindAngle ( ) ) ;
builder . append ( "\nTrue wind speed: " ) ;
builder . append ( this . getTrueWindSpeed ( ) ) ;
builder . append ( this . getTrueWindSpeed Knots ( ) ) ;
builder . append ( "\nTrue wind angle: " ) ;
builder . append ( this . getTrueWindAngle ( ) ) ;
builder . append ( "\nCurrent drift: " ) ;
builder . append ( this . getCurrentDrift ( ) ) ;
builder . append ( this . getCurrentDrift Knots ( ) ) ;
builder . append ( "\nCurrent set: " ) ;
builder . append ( this . getCurrentSet ( ) ) ;