diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index ef739ae5..693087e1 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -179,10 +179,10 @@ public class BoatGroup extends RaceObject{ * @param rotation Rotation to move graphics to. * @param raceIds RaceID of the object to move. */ - public void setDestination (double newXValue, double newYValue, double rotation, double speed, int... raceIds) { + public void setDestination (double newXValue, double newYValue, double rotation, double groundSpeed, int... raceIds) { if (hasRaceId(raceIds)) { destinationSet = true; - boat.setVelocity(speed); + boat.setVelocity(groundSpeed); if (currentRotation < 0) currentRotation = 360 - currentRotation; double dx = newXValue - boatPoly.getLayoutX(); @@ -226,7 +226,7 @@ public class BoatGroup extends RaceObject{ } } - public void setDestination (double newXValue, double newYValue, double speed, int... raceIDs) { + public void setDestination (double newXValue, double newYValue, double groundSpeed, int... raceIDs) { destinationSet = true; if (hasRaceId(raceIDs)) { @@ -237,7 +237,7 @@ public class BoatGroup extends RaceObject{ ) ) ); - setDestination(newXValue, newYValue, rotation, speed, raceIDs); + setDestination(newXValue, newYValue, rotation, groundSpeed, raceIDs); } } diff --git a/src/main/java/seng302/models/RaceObject.java b/src/main/java/seng302/models/RaceObject.java index bc061584..91f02971 100644 --- a/src/main/java/seng302/models/RaceObject.java +++ b/src/main/java/seng302/models/RaceObject.java @@ -61,7 +61,7 @@ public abstract class RaceObject extends Group { * @param rotation Rotation to move graphics to. * @param raceIds RaceID of the object to move. */ - public abstract void setDestination (double x, double y, double rotation, double speed, int... raceIds); + public abstract void setDestination (double x, double y, double rotation, double groundSpeed, int... raceIds); /** * Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is * set to the co-ordinates (x, y). @@ -69,7 +69,7 @@ public abstract class RaceObject extends Group { * @param y Y co-ordinate to move the graphic to. * @param raceIds RaceID to the object to move. */ - public abstract void setDestination (double x, double y, double speed, int... raceIds); + public abstract void setDestination (double x, double y, double groundSpeed, int... raceIds); public abstract void updatePosition (long timeInterval); diff --git a/src/main/java/seng302/models/mark/MarkGroup.java b/src/main/java/seng302/models/mark/MarkGroup.java index 16a1e06a..79b1759f 100644 --- a/src/main/java/seng302/models/mark/MarkGroup.java +++ b/src/main/java/seng302/models/mark/MarkGroup.java @@ -102,13 +102,13 @@ public class MarkGroup extends RaceObject { //moveTo(points[0].getX(), points[0].getY()); } - public void setDestination (double x, double y, double rotation, double speed, int... raceIds) { + public void setDestination (double x, double y, double rotation, double groundSpeed, int... raceIds) { setDestination(x, y, 0, raceIds); this.rotationalGoal = rotation; calculateRotationalVelocity(); } - public void setDestination (double x, double y, double speed, int... raceIds) { + public void setDestination (double x, double y, double groundSpeed, int... raceIds) { for (int i = 0; i < marks.size(); i++) for (int id : raceIds) if (id == marks.get(i).getId()) diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index dc42963f..e2efd773 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -26,6 +26,7 @@ import java.util.concurrent.PriorityBlockingQueue; * and parsed in by turning the byte arrays into useful data. There are two public static hashmaps * that are threadsafe so the visualiser can always access the latest speed and position available * Created by kre39 on 23/04/17. + * */ public class StreamParser extends Thread{ @@ -39,6 +40,11 @@ public class StreamParser extends Thread{ private static long timeSinceStart = -1; private static List boats = new ArrayList<>(); + /** + * Used to initialise the thread name and stream parser object so a thread can be executed + * + * @param threadName name of the thread + */ public StreamParser(String threadName){ this.threadName = threadName; } @@ -46,6 +52,7 @@ public class StreamParser extends Thread{ /** * Used to within threading so when the stream parser thread runs, it will keep looking for a packet to * process until it is unable to find anymore packets + * */ public void run(){ try { @@ -83,6 +90,7 @@ public class StreamParser extends Thread{ /** * Used to start the stream parser thread when multithreading + * */ public void start () { System.out.println("Starting " + threadName ); @@ -92,6 +100,12 @@ public class StreamParser extends Thread{ } } + /** + * Looks at the type of the packet then sends it to the appropriate parser to extract the + * specific data associated with that packet type + * + * @param packet the packet to be looked at + */ private static void parsePacket(StreamPacket packet) { switch (packet.getType()){ case HEARTBEAT: @@ -138,6 +152,7 @@ public class StreamParser extends Thread{ /** * Extracts the seq num used in the heartbeat packet + * * @param packet Packet parsed in to use the payload */ private static void extractHeartBeat(StreamPacket packet) { @@ -148,6 +163,7 @@ public class StreamParser extends Thread{ * Extracts the useful race status data from race status type packets. This method will also print to the * console the current state of the race (if it has started/finished or is about to start), along side * this it'll also display the amount of time since the race has started or time till it starts + * * @param packet Packet parsed in to use the payload */ private static void extractRaceStatus(StreamPacket packet){ @@ -196,6 +212,7 @@ public class StreamParser extends Thread{ /** * Used to extract the messages passed through with the display message packet + * * @param packet Packet parsed in to use the payload */ private static void extractDisplayMessage(StreamPacket packet){ @@ -214,6 +231,7 @@ public class StreamParser extends Thread{ /** * Used to read in the xml data. Will call the specific methods to create the course and boats + * * @param packet Packet parsed in to use the payload */ private static void extractXmlMessage(StreamPacket packet){ @@ -242,6 +260,7 @@ public class StreamParser extends Thread{ /** * Extracts the race start status from the packet, currently is unused within the app but * is here for potential future use + * * @param packet Packet parsed in to use the payload */ private static void extractRaceStartStatus(StreamPacket packet){ @@ -256,6 +275,7 @@ public class StreamParser extends Thread{ /** * When a yacht event occurs this will parse the byte array to retrieve the necessary info, * currently unused + * * @param packet Packet parsed in to use the payload */ private static void extractYachtEventCode(StreamPacket packet){ @@ -271,6 +291,7 @@ public class StreamParser extends Thread{ /** * When a yacht action occurs this will parse the parse the byte array to retrieve the necessary info, * currently unused + * * @param packet Packet parsed in to use the payload */ private static void extractYachtActionCode(StreamPacket packet){ @@ -285,6 +306,7 @@ public class StreamParser extends Thread{ /** * Strips the message from the chatter text type packets, currently the message is unused + * * @param packet Packet parsed in to use the payload */ private static void extractChatterText(StreamPacket packet){ @@ -298,33 +320,28 @@ public class StreamParser extends Thread{ /** * Used to breakdown the boatlocation packets so the boat coordinates, id and groundspeed are all used * All the other extra data is still being read and translated however is unused. + * * @param packet Packet parsed in to use the payload */ private static void extractBoatLocation(StreamPacket packet){ byte[] payload = packet.getPayload(); - byte deviceType = payload[15]; - byte[] seqBytes = Arrays.copyOfRange(payload,11,15); - byte[] latBytes = Arrays.copyOfRange(payload,16,20); - byte[] lonBytes = Arrays.copyOfRange(payload,20,24); - byte[] boatIdBytes = Arrays.copyOfRange(payload,7,11); - byte[] headingBytes = Arrays.copyOfRange(payload,28,30); - byte[] groundSpeedBytes = Arrays.copyOfRange(payload,38,40); + int deviceType = (int)payload[15]; long timeValid = bytesToLong(Arrays.copyOfRange(payload,1,7)); -// int boatSeq = ByteBuffer.wrap(seqBytes).getInt(); - long seq = bytesToLong(seqBytes); - long boatId = bytesToLong(boatIdBytes); - long rawLat = bytesToLong(latBytes); - long rawLon = bytesToLong(lonBytes); + long seq = bytesToLong(Arrays.copyOfRange(payload,11,15)); + long boatId = bytesToLong(Arrays.copyOfRange(payload,7,11)); + long rawLat = bytesToLong(Arrays.copyOfRange(payload,16,20)); + long rawLon = bytesToLong(Arrays.copyOfRange(payload,20,24)); + //Converts the double to a usable lat/lon double lat = ((180d * (double)rawLat)/Math.pow(2,31)); double lon = ((180d *(double)rawLon)/Math.pow(2,31)); - long heading = bytesToLong(headingBytes); - double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0; - short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF)); - if ((int)deviceType == 1 || (int)deviceType == 3){ + long heading = bytesToLong(Arrays.copyOfRange(payload,28,30)); + double groundSpeed = bytesToLong(Arrays.copyOfRange(payload,38,40))/1000.0; + //type 1 is a racing yacht and type 3 is a mark, needed for updating positions of the mark and boat + if (deviceType == 1 || deviceType == 3){ BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed); - + //add a new priority que to the boatPositions HashMap if (!boatPositions.containsKey(boatId)){ boatPositions.put(boatId, new PriorityBlockingQueue(256, new Comparator() { @Override @@ -337,8 +354,11 @@ public class StreamParser extends Thread{ } } - - + /** + * This packet type is received when a mark or gate is rounded by a boat + * + * @param packet The packet containing the payload + */ private static void extractMarkRounding(StreamPacket packet){ byte[] payload = packet.getPayload(); int messageVersionNo = payload[0]; @@ -351,6 +371,11 @@ public class StreamParser extends Thread{ int markId = payload[20]; } + /** + * This packet type contains periodic data on the state of the wind + * + * @param packet The packet containing the payload + */ private static void extractCourseWind(StreamPacket packet){ byte[] payload = packet.getPayload(); int messageVersionNo = payload[0]; @@ -370,6 +395,11 @@ public class StreamParser extends Thread{ } } + /** + * This packet conatins the average wind to ground speed + * + * @param packet The packet containing the paylaod + */ private static void extractAvgWind(StreamPacket packet){ byte[] payload = packet.getPayload(); int messageVersionNo = payload[0]; @@ -448,6 +478,12 @@ public class StreamParser extends Thread{ return boats; } + + /** + * returns the latest updated object from xml parser + * + * @return the latest xml object + */ public static XMLParser getXmlObject() { return xmlObject; }