package seng302.RaceEventMessages; /** * 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; 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; ///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. Default. */ 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; } /** * 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; } }