|
|
|
|
@ -1,13 +1,19 @@
|
|
|
|
|
package seng302.Networking;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
import seng302.Mock.*;
|
|
|
|
|
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.text.ParseException;
|
|
|
|
|
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,18 +33,39 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
long heartbeatSeqNum;
|
|
|
|
|
|
|
|
|
|
private StreamedCourse course = null;
|
|
|
|
|
|
|
|
|
|
private Map<Integer, BoatLocationMessage> boatLocation;
|
|
|
|
|
|
|
|
|
|
VisualiserInput() throws IOException{
|
|
|
|
|
public VisualiserInput(Socket connectionSocket) throws IOException{
|
|
|
|
|
|
|
|
|
|
connectionSocket = new Socket(InetAddress.getLocalHost(), 5003);
|
|
|
|
|
connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
|
|
|
|
|
|
|
|
|
//this is the test data that streams form the AC35 website
|
|
|
|
|
// connectionSocket = new Socket("livedata.americascup.com",4941);
|
|
|
|
|
this.course = new StreamedCourse();
|
|
|
|
|
this.boatLocation = new HashMap<>();
|
|
|
|
|
this.connectionSocket = connectionSocket;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//start Time
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
this.lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides StreamedCourse container for fixed course data
|
|
|
|
|
* @return course for current VisualiserInput instance
|
|
|
|
|
* @see seng302.Mock.StreamedCourse
|
|
|
|
|
*/
|
|
|
|
|
public StreamedCourse getCourse() {
|
|
|
|
|
return course;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the last boat location message associated with the given boat source ID.
|
|
|
|
|
* @param sourceID unique global identifier for boat
|
|
|
|
|
* @return most recent location message
|
|
|
|
|
*/
|
|
|
|
|
public BoatLocationMessage getBoatLocationMessage(int sourceID) {
|
|
|
|
|
return boatLocation.get(sourceID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -105,7 +132,24 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
//no decoder for this.
|
|
|
|
|
break;
|
|
|
|
|
case XMLMESSAGE:
|
|
|
|
|
System.out.println("XML Message!");
|
|
|
|
|
// System.out.println("XML Message!");
|
|
|
|
|
XMLMessage xml = (XMLMessage) data;
|
|
|
|
|
try {
|
|
|
|
|
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
|
|
|
|
|
System.out.println("Setting Regatta");
|
|
|
|
|
course.setRegattaXMLReader(new RegattaXMLReader(xml.getXmlMessage()));
|
|
|
|
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeRace){
|
|
|
|
|
System.out.println("Setting Course");
|
|
|
|
|
course.setStreamedCourseXMLReader(new StreamedCourseXMLReader(xml.getXmlMessage()));
|
|
|
|
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
|
|
|
|
|
System.out.println("Setting Boats");
|
|
|
|
|
course.setBoatXMLReader(new BoatXMLReader(xml.getXmlMessage()));
|
|
|
|
|
}
|
|
|
|
|
} catch (SAXException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (ParserConfigurationException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RACESTARTSTATUS:
|
|
|
|
|
System.out.println("Race Start Status Message");
|
|
|
|
|
@ -123,7 +167,15 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
//no decoder
|
|
|
|
|
break;
|
|
|
|
|
case BOATLOCATION:
|
|
|
|
|
System.out.println("Boat Location Message!");
|
|
|
|
|
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:
|
|
|
|
|
// System.out.println("Mark Rounding Message!");
|
|
|
|
|
@ -153,8 +205,10 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
public static void main(String argv[]) throws Exception
|
|
|
|
|
{
|
|
|
|
|
VisualiserInput reciever = new VisualiserInput();
|
|
|
|
|
reciever.run();
|
|
|
|
|
//this is the test data that streams form the AC35 website
|
|
|
|
|
Socket socket = new Socket("livedata.americascup.com",4941);
|
|
|
|
|
VisualiserInput receiver = new VisualiserInput(socket);
|
|
|
|
|
receiver.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|