|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
package seng302;
|
|
|
|
|
import org.opengis.style.Mark;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
import seng302.Mock.*;
|
|
|
|
|
import seng302.Networking.BinaryMessageDecoder;
|
|
|
|
|
@ -41,14 +42,23 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
private Map<Integer, BoatStatusMessage> boatStatus;
|
|
|
|
|
|
|
|
|
|
public VisualiserInput(StreamedCourse course) throws IOException{
|
|
|
|
|
private AverageWind averageWind;
|
|
|
|
|
|
|
|
|
|
this.connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
|
|
|
|
private CourseWinds courseWinds;
|
|
|
|
|
|
|
|
|
|
private Map<Integer, MarkRounding> markRounding;
|
|
|
|
|
|
|
|
|
|
private RaceStartStatus raceStartStatus;
|
|
|
|
|
|
|
|
|
|
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
|
|
|
|
|
|
|
|
|
this.connectionSocket = socket;
|
|
|
|
|
// this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
|
|
|
|
|
|
|
|
|
this.course = course;
|
|
|
|
|
this.boatLocation = new HashMap<>();
|
|
|
|
|
this.boatStatus = new HashMap<>();
|
|
|
|
|
this.markRounding = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//start Time
|
|
|
|
|
@ -106,6 +116,30 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
return boatStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the average wind of the race
|
|
|
|
|
* @return average wind in the race
|
|
|
|
|
*/
|
|
|
|
|
public AverageWind getAverageWind() {
|
|
|
|
|
return averageWind;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns winds in the course
|
|
|
|
|
* @return winds that are in the course
|
|
|
|
|
*/
|
|
|
|
|
public CourseWinds getCourseWinds() {
|
|
|
|
|
return courseWinds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns get Mark Rounding Boat Source ID, MarkRound
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Map<Integer, MarkRounding> getMarkRounding() {
|
|
|
|
|
return markRounding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Takes an inputStream and reads the first 15 bytes (the header) and gets the message length
|
|
|
|
|
* for the whole message then reads that and returns the byte array
|
|
|
|
|
@ -154,7 +188,7 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
//note: if the program runs for over 340 years, this will crash.
|
|
|
|
|
heartbeatSeqNum = ByteConverter.bytesToLong(testDecoder.getMessage());
|
|
|
|
|
System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
|
|
|
|
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
|
|
|
|
break;
|
|
|
|
|
case RACESTATUS:
|
|
|
|
|
System.out.println("Race Status Message");
|
|
|
|
|
@ -193,6 +227,8 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
break;
|
|
|
|
|
case RACESTARTSTATUS:
|
|
|
|
|
//System.out.println("Race Start Status Message");
|
|
|
|
|
RaceStartStatus rSS = (RaceStartStatus) data;
|
|
|
|
|
raceStartStatus = rSS;
|
|
|
|
|
break;
|
|
|
|
|
case YACHTEVENTCODE:
|
|
|
|
|
// System.out.println("Yacht Action Code!");
|
|
|
|
|
@ -207,6 +243,7 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
//no decoder
|
|
|
|
|
break;
|
|
|
|
|
case BOATLOCATION:
|
|
|
|
|
System.out.println("Boat Location!");
|
|
|
|
|
BoatLocationMessage msg = (BoatLocationMessage) data;
|
|
|
|
|
if (boatLocation.containsKey(msg.getSourceID())){
|
|
|
|
|
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
|
|
|
|
@ -219,12 +256,17 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
break;
|
|
|
|
|
case MARKROUNDING:
|
|
|
|
|
// System.out.println("Mark Rounding Message!");
|
|
|
|
|
MarkRounding mkrounding = (MarkRounding) data;
|
|
|
|
|
markRounding.put(mkrounding.getSourceID(), mkrounding);
|
|
|
|
|
break;
|
|
|
|
|
case COURSEWIND:
|
|
|
|
|
// System.out.println("Course Wind Message!");
|
|
|
|
|
courseWinds = (CourseWinds) data;
|
|
|
|
|
break;
|
|
|
|
|
case AVGWIND:
|
|
|
|
|
// System.out.println("Average Wind Message!");
|
|
|
|
|
AverageWind avgWind = (AverageWind) data;
|
|
|
|
|
averageWind = avgWind;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
System.out.println("Broken Message!");
|
|
|
|
|
@ -245,7 +287,8 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
public static void main(String argv[]) throws Exception
|
|
|
|
|
{
|
|
|
|
|
VisualiserInput receiver = new VisualiserInput(new StreamedCourse());
|
|
|
|
|
Socket socket = new Socket(InetAddress.getLocalHost(), 4942);
|
|
|
|
|
VisualiserInput receiver = new VisualiserInput(socket, new StreamedCourse());
|
|
|
|
|
receiver.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|