Generate StreamedCourse from VisualiserInput
#story[782]
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package seng302.Networking;
|
package seng302.Networking;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.Mock.BoatXMLReader;
|
import seng302.Mock.*;
|
||||||
import seng302.Mock.RegattaXMLReader;
|
|
||||||
import seng302.Mock.StreamedCourseXMLReader;
|
|
||||||
import seng302.Networking.BinaryMessageDecoder;
|
import seng302.Networking.BinaryMessageDecoder;
|
||||||
import seng302.Networking.MessageDecoders.*;
|
import seng302.Networking.MessageDecoders.*;
|
||||||
import seng302.Networking.Utils.*;
|
import seng302.Networking.Utils.*;
|
||||||
@@ -12,6 +10,7 @@ import java.io.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -34,23 +33,39 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
long heartbeatSeqNum;
|
long heartbeatSeqNum;
|
||||||
|
|
||||||
|
private StreamedCourse course = null;
|
||||||
|
|
||||||
private Map<Integer, BoatLocationMessage> boatLocation;
|
private Map<Integer, BoatLocationMessage> boatLocation;
|
||||||
private BoatXMLReader boatXMLReader;
|
|
||||||
private StreamedCourseXMLReader streamedCourseXMLReader;
|
|
||||||
private RegattaXMLReader regattaXMLReader;
|
|
||||||
|
|
||||||
|
public VisualiserInput(Socket connectionSocket) throws IOException{
|
||||||
VisualiserInput() throws IOException{
|
|
||||||
|
|
||||||
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||||
|
|
||||||
boatLocation = new HashMap<>();
|
this.course = new StreamedCourse();
|
||||||
//this is the test data that streams form the AC35 website
|
this.boatLocation = new HashMap<>();
|
||||||
connectionSocket = new Socket("livedata.americascup.com",4941);
|
this.connectionSocket = connectionSocket;
|
||||||
|
|
||||||
|
|
||||||
//start Time
|
//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;
|
break;
|
||||||
case XMLMESSAGE:
|
case XMLMESSAGE:
|
||||||
// System.out.println("XML Message!");
|
// System.out.println("XML Message!");
|
||||||
XMLMessage xml = (XMLMessage) data;/*
|
XMLMessage xml = (XMLMessage) data;
|
||||||
try {
|
try {
|
||||||
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
|
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){
|
} 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){
|
} 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) {
|
} catch (SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}*/
|
}
|
||||||
System.out.println(((XMLMessage)data).getXmlMessage());
|
|
||||||
break;
|
break;
|
||||||
case RACESTARTSTATUS:
|
case RACESTARTSTATUS:
|
||||||
// System.out.println("Race Start Status Message");
|
// System.out.println("Race Start Status Message");
|
||||||
@@ -188,8 +205,10 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
public static void main(String argv[]) throws Exception
|
public static void main(String argv[]) throws Exception
|
||||||
{
|
{
|
||||||
VisualiserInput reciever = new VisualiserInput();
|
//this is the test data that streams form the AC35 website
|
||||||
reciever.run();
|
Socket socket = new Socket("livedata.americascup.com",4941);
|
||||||
|
VisualiserInput receiver = new VisualiserInput(socket);
|
||||||
|
receiver.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package seng302.Mock;
|
package seng302.Mock;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import jdk.internal.util.xml.impl.Input;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.Model.Boat;
|
import seng302.Model.Boat;
|
||||||
import seng302.XMLReader;
|
import seng302.XMLReader;
|
||||||
@@ -47,6 +49,10 @@ public class BoatXMLReader extends XMLReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BoatXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||||
|
super(xmlString);
|
||||||
|
}
|
||||||
|
|
||||||
public void read() {
|
public void read() {
|
||||||
readSettings();
|
readSettings();
|
||||||
readShapes();
|
readShapes();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seng302.Mock;
|
|||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.XMLReader;
|
import seng302.XMLReader;
|
||||||
|
|
||||||
@@ -42,6 +43,10 @@ public class RegattaXMLReader extends XMLReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RegattaXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||||
|
super(xmlString);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the XML
|
* Read the XML
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public class StreamedCourse implements RaceDataSource {
|
|||||||
BoatXMLReader boatXMLReader = null;
|
BoatXMLReader boatXMLReader = null;
|
||||||
RegattaXMLReader regattaXMLReader = null;
|
RegattaXMLReader regattaXMLReader = null;
|
||||||
|
|
||||||
|
public StreamedCourse() {}
|
||||||
|
|
||||||
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
|
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
|
||||||
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
||||||
}
|
}
|
||||||
@@ -25,15 +27,19 @@ public class StreamedCourse implements RaceDataSource {
|
|||||||
|
|
||||||
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
|
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
|
||||||
this.boatXMLReader = boatXMLReader;
|
this.boatXMLReader = boatXMLReader;
|
||||||
if (streamedCourseXMLReader != null) {
|
if (streamedCourseXMLReader != null && boatXMLReader != null) {
|
||||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||||
boatXMLReader.read();
|
boatXMLReader.read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StreamedCourseXMLReader getStreamedCourseXMLReader() {
|
||||||
|
return streamedCourseXMLReader;
|
||||||
|
}
|
||||||
|
|
||||||
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
|
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
|
||||||
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
||||||
if (streamedCourseXMLReader != null) {
|
if (streamedCourseXMLReader != null && boatXMLReader != null) {
|
||||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||||
boatXMLReader.read();
|
boatXMLReader.read();
|
||||||
}
|
}
|
||||||
@@ -43,10 +49,6 @@ public class StreamedCourse implements RaceDataSource {
|
|||||||
this.regattaXMLReader = regattaXMLReader;
|
this.regattaXMLReader = regattaXMLReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegattaXMLReader getRegattaXMLReader() {
|
|
||||||
return regattaXMLReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Boat> getBoats() {
|
public List<Boat> getBoats() {
|
||||||
return boatXMLReader.getBoats();
|
return boatXMLReader.getBoats();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
@@ -63,6 +64,10 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StreamedCourseXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||||
|
super(xmlString);
|
||||||
|
}
|
||||||
|
|
||||||
private void read() throws ParseException, StreamedCourseXMLException {
|
private void read() throws ParseException, StreamedCourseXMLException {
|
||||||
readRace();
|
readRace();
|
||||||
readParticipants();
|
readParticipants();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package seng302;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@@ -26,6 +27,12 @@ public abstract class XMLReader {
|
|||||||
doc.getDocumentElement().normalize();
|
doc.getDocumentElement().normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XMLReader(InputSource xmlInput) throws ParserConfigurationException, IOException, SAXException {
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
doc = dBuilder.parse(xmlInput);
|
||||||
|
}
|
||||||
|
|
||||||
public Document getDocument() {
|
public Document getDocument() {
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user