|
|
|
|
@ -1,13 +1,20 @@
|
|
|
|
|
package seng302.Networking;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
import seng302.Mock.BoatXMLReader;
|
|
|
|
|
import seng302.Mock.RegattaXMLReader;
|
|
|
|
|
import seng302.Mock.StreamedCourseXMLReader;
|
|
|
|
|
import seng302.Networking.BinaryMessageDecoder;
|
|
|
|
|
import seng302.Networking.MessageDecoders.*;
|
|
|
|
|
import seng302.Networking.Utils.*;
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.*;
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
import java.nio.ByteOrder;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
|
|
|
|
|
@ -27,12 +34,17 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
long heartbeatSeqNum;
|
|
|
|
|
|
|
|
|
|
private Map<Integer, BoatLocationMessage> boatLocation;
|
|
|
|
|
private BoatXMLReader boatXMLReader;
|
|
|
|
|
private StreamedCourseXMLReader streamedCourseXMLReader;
|
|
|
|
|
private RegattaXMLReader regattaXMLReader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VisualiserInput() throws IOException{
|
|
|
|
|
|
|
|
|
|
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
|
|
|
|
|
|
|
|
|
boatLocation = new HashMap<>();
|
|
|
|
|
//this is the test data that streams form the AC35 website
|
|
|
|
|
connectionSocket = new Socket("livedata.americascup.com",4941);
|
|
|
|
|
|
|
|
|
|
@ -106,6 +118,20 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
break;
|
|
|
|
|
case XMLMESSAGE:
|
|
|
|
|
// System.out.println("XML Message!");
|
|
|
|
|
XMLMessage xml = (XMLMessage) data;/*
|
|
|
|
|
try {
|
|
|
|
|
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
|
|
|
|
|
regattaXMLReader = new RegattaXMLReader(xml.getXmlMessage());
|
|
|
|
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeRace){
|
|
|
|
|
streamedCourseXMLReader = new StreamedCourseXMLReader(xml.getXmlMessage());
|
|
|
|
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
|
|
|
|
|
boatXMLReader = new BoatXMLReader(xml.getXmlMessage());
|
|
|
|
|
}
|
|
|
|
|
} catch (SAXException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (ParserConfigurationException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}*/
|
|
|
|
|
System.out.println(((XMLMessage)data).getXmlMessage());
|
|
|
|
|
break;
|
|
|
|
|
case RACESTARTSTATUS:
|
|
|
|
|
@ -124,6 +150,14 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
//no decoder
|
|
|
|
|
break;
|
|
|
|
|
case BOATLOCATION:
|
|
|
|
|
BoatLocationMessage msg = (BoatLocationMessage) data;
|
|
|
|
|
if (boatLocation.containsKey(msg.getSourceID())){
|
|
|
|
|
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
|
|
|
|
boatLocation.put(msg.getSourceID(), msg);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
boatLocation.put(msg.getSourceID(), msg);
|
|
|
|
|
}
|
|
|
|
|
// System.out.println("Boat Location Message!");
|
|
|
|
|
break;
|
|
|
|
|
case MARKROUNDING:
|
|
|
|
|
|