Generate StreamedCourse from VisualiserInput

#story[782]
This commit is contained in:
Connor Taylor-Brown
2017-04-28 20:29:03 +12:00
parent 8569d3f2dc
commit 68a8f64fd3
6 changed files with 70 additions and 26 deletions
@@ -1,8 +1,6 @@
package seng302.Networking;
import org.xml.sax.SAXException;
import seng302.Mock.BoatXMLReader;
import seng302.Mock.RegattaXMLReader;
import seng302.Mock.StreamedCourseXMLReader;
import seng302.Mock.*;
import seng302.Networking.BinaryMessageDecoder;
import seng302.Networking.MessageDecoders.*;
import seng302.Networking.Utils.*;
@@ -12,6 +10,7 @@ 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;
@@ -34,23 +33,39 @@ public class VisualiserInput implements Runnable
long heartbeatSeqNum;
private StreamedCourse course = null;
private Map<Integer, BoatLocationMessage> boatLocation;
private BoatXMLReader boatXMLReader;
private StreamedCourseXMLReader streamedCourseXMLReader;
private RegattaXMLReader regattaXMLReader;
VisualiserInput() throws IOException{
public VisualiserInput(Socket connectionSocket) 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);
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);
}
/**
@@ -118,21 +133,23 @@ public class VisualiserInput implements Runnable
break;
case XMLMESSAGE:
// System.out.println("XML Message!");
XMLMessage xml = (XMLMessage) data;/*
XMLMessage xml = (XMLMessage) data;
try {
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
regattaXMLReader = new RegattaXMLReader(xml.getXmlMessage());
System.out.println("Setting Regatta");
course.setRegattaXMLReader(new RegattaXMLReader(xml.getXmlMessage()));
} else if (xml.getXmlMsgSubType() == xml.XMLTypeRace){
streamedCourseXMLReader = new StreamedCourseXMLReader(xml.getXmlMessage());
System.out.println("Setting Course");
course.setStreamedCourseXMLReader(new StreamedCourseXMLReader(xml.getXmlMessage()));
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
boatXMLReader = new BoatXMLReader(xml.getXmlMessage());
System.out.println("Setting Boats");
course.setBoatXMLReader(new BoatXMLReader(xml.getXmlMessage()));
}
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}*/
System.out.println(((XMLMessage)data).getXmlMessage());
}
break;
case RACESTARTSTATUS:
// System.out.println("Race Start Status Message");
@@ -188,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();
}
}