@ -9,22 +9,7 @@ import seng302.Constants;
/ * *
* 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 ;
public class BoatLocationMessage {
public static final byte Unknown = 0 ;
public static final byte RacingYacht = 1 ;
public static final byte CommitteeBoat = 2 ;
@ -39,8 +24,16 @@ public class BoatLocationMessage
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 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 ;
@ -93,12 +86,12 @@ public class BoatLocationMessage
/ * *
* Ctor . Default .
* /
public BoatLocationMessage ( )
{
public BoatLocationMessage ( ) {
}
/ * *
* Ctor , with all parameters .
*
* @param messageVersionNumber
* @param time
* @param sourceID
@ -121,8 +114,7 @@ public class BoatLocationMessage
* @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 trueWindAngle , int currentDrift , int currentSet , short rudderAngle ) {
this . messageVersionNumber = messageVersionNumber ;
this . time = time ;
this . sourceID = sourceID ;
@ -149,342 +141,289 @@ public class BoatLocationMessage
//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 / 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 ( )
{
public byte getMessageVersionNumber ( ) {
return messageVersionNumber ;
}
public void setMessageVersionNumber ( byte 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 long getSequenceNumber ( )
{
public long getSequenceNumber ( ) {
return sequenceNumber ;
}
public void setSequenceNumber ( long sequenceNumber )
{
public void setSequenceNumber ( long sequenceNumber ) {
this . sequenceNumber = sequenceNumber ;
}
public byte getDeviceType ( )
{
public byte getDeviceType ( ) {
return deviceType ;
}
public void setDeviceType ( byte 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 short getPitch ( )
{
public short getPitch ( ) {
return pitch ;
}
public void setPitch ( short pitch )
{
public void setPitch ( short pitch ) {
this . pitch = pitch ;
}
public short getRoll ( )
{
public short getRoll ( ) {
return roll ;
}
public void setRoll ( short 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 short getApparentWindAngle ( )
{
public short getApparentWindAngle ( ) {
return apparentWindAngle ;
}
public void setApparentWindAngle ( short 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 short getTrueWindAngle ( )
{
public short getTrueWindAngle ( ) {
return trueWindAngle ;
}
public void setTrueWindAngle ( short 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 short getRudderAngle ( )
{
public short getRudderAngle ( ) {
return rudderAngle ;
}
public void setRudderAngle ( short rudderAngle )
{
public void setRudderAngle ( short rudderAngle ) {
this . rudderAngle = rudderAngle ;
}
/ * *
* 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 ;
}
@Override
public String toString ( )
{
public String toString ( ) {
StringBuilder builder = new StringBuilder ( ) ;
builder . append ( "Message version number: " ) ;