Merge remote-tracking branch 'origin/splitIntoTwoModules' into splitIntoTwoModules
# Conflicts: # visualiser/src/main/java/seng302/VisualiserInput.java
This commit is contained in:
@@ -180,7 +180,7 @@ public class BoatData {
|
|||||||
private void appendBoatName(Element boat, int i) {
|
private void appendBoatName(Element boat, int i) {
|
||||||
//BoatName attribute
|
//BoatName attribute
|
||||||
Attr attrBoatName = doc.createAttribute("BoatName");
|
Attr attrBoatName = doc.createAttribute("BoatName");
|
||||||
attrBoatName.setValue(boatData.get(i).toString());
|
attrBoatName.setValue(boatData.get(i).getName());
|
||||||
boat.setAttributeNode(attrBoatName);
|
boat.setAttributeNode(attrBoatName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,15 @@ public class MockOutput implements Runnable
|
|||||||
private int heartbeatSequenceNum = 1;
|
private int heartbeatSequenceNum = 1;
|
||||||
private int boatLocationSequenceNumber = 1;
|
private int boatLocationSequenceNumber = 1;
|
||||||
private int raceStatusSequenceNumber = 1;
|
private int raceStatusSequenceNumber = 1;
|
||||||
|
private String raceXml;
|
||||||
|
private String regattaXml;
|
||||||
|
private String boatsXml;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MockOutput() throws IOException {
|
public MockOutput() throws IOException {
|
||||||
lastHeartbeatTime = System.currentTimeMillis();
|
lastHeartbeatTime = System.currentTimeMillis();
|
||||||
serverSocket = new ServerSocket(4942);
|
serverSocket = new ServerSocket(4945);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* calculates the time since last heartbeat
|
* calculates the time since last heartbeat
|
||||||
@@ -131,48 +136,13 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
/*******************************Test********************************/
|
/*******************************Test********************************/
|
||||||
|
|
||||||
StringBuilder xmlString1;
|
while(boatsXml == null || regattaXml == null || raceXml == null) {
|
||||||
|
|
||||||
BufferedReader br1 = new BufferedReader(new InputStreamReader(
|
|
||||||
this.getClass().getResourceAsStream(("/raceXML/Boats.xml"))));
|
|
||||||
|
|
||||||
String line1;
|
|
||||||
xmlString1 = new StringBuilder();
|
|
||||||
while((line1=br1.readLine())!= null){
|
|
||||||
xmlString1.append(line1.trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseXMLString(xmlString1.toString(), XMLMessage.XMLTypeBoat);
|
parseXMLString(raceXml, XMLMessage.XMLTypeRace);
|
||||||
|
parseXMLString(regattaXml, XMLMessage.XMLTypeRegatta);
|
||||||
|
parseXMLString(boatsXml, XMLMessage.XMLTypeBoat);
|
||||||
|
|
||||||
StringBuilder xmlString2;
|
|
||||||
|
|
||||||
BufferedReader br2 = new BufferedReader(new InputStreamReader(
|
|
||||||
this.getClass().getResourceAsStream(("/raceXML/Race.xml"))));
|
|
||||||
|
|
||||||
String line2;
|
|
||||||
xmlString2 = new StringBuilder();
|
|
||||||
while((line2=br2.readLine())!= null){
|
|
||||||
xmlString2.append(line2.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
parseXMLString(xmlString2.toString(), XMLMessage.XMLTypeRace);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
StringBuilder xmlString;
|
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
||||||
this.getClass().getResourceAsStream(("/raceXML/Regatta.xml"))));
|
|
||||||
|
|
||||||
String line;
|
|
||||||
xmlString = new StringBuilder();
|
|
||||||
while((line=br.readLine())!= null){
|
|
||||||
xmlString.append(line.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
parseXMLString(xmlString.toString(), XMLMessage.XMLTypeRegatta);
|
|
||||||
|
|
||||||
/*******************************Test********************************/
|
/*******************************Test********************************/
|
||||||
|
|
||||||
@@ -206,6 +176,20 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setRaceXml(String raceXml) {
|
||||||
|
this.raceXml = raceXml;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setRegattaXml(String regattaXml) {
|
||||||
|
this.regattaXml = regattaXml;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setBoatsXml(String boatsXml) {
|
||||||
|
this.boatsXml = boatsXml;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String argv[]) throws Exception
|
public static void main(String argv[]) throws Exception
|
||||||
{
|
{
|
||||||
MockOutput client = new MockOutput();
|
MockOutput client = new MockOutput();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class Event {
|
|||||||
System.setOut(System.out);
|
System.setOut(System.out);
|
||||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||||
String xmlString = regattaData.createXML();
|
String xmlString = regattaData.createXML();
|
||||||
|
mockOutput.setRegattaXml(xmlString);
|
||||||
mockOutput.parseXMLString(xmlString, 26);
|
mockOutput.parseXMLString(xmlString, 26);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,6 +62,8 @@ public class Event {
|
|||||||
RaceData raceData = new RaceData(raceDataSource);
|
RaceData raceData = new RaceData(raceDataSource);
|
||||||
//Serialize race data to an XML as a string.
|
//Serialize race data to an XML as a string.
|
||||||
String xmlString = raceData.createXML();
|
String xmlString = raceData.createXML();
|
||||||
|
System.out.println(xmlString);
|
||||||
|
mockOutput.setRaceXml(xmlString);
|
||||||
mockOutput.parseXMLString(xmlString, 26);
|
mockOutput.parseXMLString(xmlString, 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +71,8 @@ public class Event {
|
|||||||
BoatData boatData = new BoatData(raceDataSource.getBoats());
|
BoatData boatData = new BoatData(raceDataSource.getBoats());
|
||||||
//Serialize race data to an XML as a string.
|
//Serialize race data to an XML as a string.
|
||||||
String xmlString = boatData.createXML();
|
String xmlString = boatData.createXML();
|
||||||
|
System.out.println(xmlString);
|
||||||
|
mockOutput.setBoatsXml(xmlString);
|
||||||
mockOutput.parseXMLString(xmlString, 26);
|
mockOutput.parseXMLString(xmlString, 26);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<raceId>5326</raceId>
|
<raceId>5326</raceId>
|
||||||
<boats>
|
<boats>
|
||||||
<boat>
|
<boat>
|
||||||
<name>ORACLE TEAM USA</name>
|
<name>Team 7</name>
|
||||||
<speed>20</speed>
|
<speed>20</speed>
|
||||||
<abbr>USA</abbr>
|
<abbr>USA</abbr>
|
||||||
<sourceID>121</sourceID>
|
<sourceID>121</sourceID>
|
||||||
|
|||||||
@@ -193,9 +193,13 @@ public class StartController extends Controller implements Observer {
|
|||||||
if(((StreamedCourse) o).getBoats() != null) {
|
if(((StreamedCourse) o).getBoats() != null) {
|
||||||
initialiseTables();
|
initialiseTables();
|
||||||
}
|
}
|
||||||
if(((StreamedCourse)o).getZonedDateTime() != null) {
|
if (((StreamedCourse) o).getZonedDateTime() != null) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
{
|
||||||
setRaceClock();
|
setRaceClock();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package seng302.Mock;
|
package seng302.Mock;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
@@ -71,25 +72,28 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void read() throws ParseException, StreamedCourseXMLException {
|
private void read() throws ParseException, StreamedCourseXMLException {
|
||||||
// readRace();
|
readRace();
|
||||||
readParticipants();
|
readParticipants();
|
||||||
readCourse();
|
readCourse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readRace() throws ParseException {
|
private void readRace() throws ParseException {
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
||||||
|
|
||||||
|
System.out.println(getTextValueOfNode(settings, "CreationTimeDate"));
|
||||||
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
||||||
raceType = getTextValueOfNode(settings, "RaceType");
|
raceType = getTextValueOfNode(settings, "RaceType");
|
||||||
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
||||||
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
||||||
raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
||||||
|
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
|
||||||
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readParticipants() {
|
private void readParticipants() {
|
||||||
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
|
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
|
||||||
|
nParticipants.getChildNodes().getLength();
|
||||||
for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) {
|
for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) {
|
||||||
int sourceID;
|
int sourceID;
|
||||||
Node yacht = nParticipants.getChildNodes().item(i);
|
Node yacht = nParticipants.getChildNodes().item(i);
|
||||||
@@ -157,7 +161,8 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
* @return value of "compoundMarkID" attribute
|
* @return value of "compoundMarkID" attribute
|
||||||
*/
|
*/
|
||||||
private int getCompoundMarkID(Element element) {
|
private int getCompoundMarkID(Element element) {
|
||||||
return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
//return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
private Map<Integer, BoatLocationMessage> boatLocation;
|
private Map<Integer, BoatLocationMessage> boatLocation;
|
||||||
|
|
||||||
|
private RaceStatus raceStatus;
|
||||||
|
|
||||||
|
private Map<Integer, BoatStatusMessage> boatStatus;
|
||||||
|
|
||||||
|
public VisualiserInput(StreamedCourse course) throws IOException{
|
||||||
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
||||||
|
|
||||||
this.connectionSocket = socket;
|
this.connectionSocket = socket;
|
||||||
@@ -44,6 +49,7 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
this.course = course;
|
this.course = course;
|
||||||
this.boatLocation = new HashMap<>();
|
this.boatLocation = new HashMap<>();
|
||||||
|
this.boatStatus = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
//start Time
|
//start Time
|
||||||
@@ -77,6 +83,30 @@ public class VisualiserInput implements Runnable
|
|||||||
return (now - lastHeartbeatTime) / 1000.0;
|
return (now - lastHeartbeatTime) / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the boat locations
|
||||||
|
* @return locations of where the boats are
|
||||||
|
*/
|
||||||
|
public Map<Integer, BoatLocationMessage> getBoatLocation() {
|
||||||
|
return boatLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the status of the race
|
||||||
|
* @return the status of the race
|
||||||
|
*/
|
||||||
|
public RaceStatus getRaceStatus() {
|
||||||
|
return raceStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hashmap of the boat status'
|
||||||
|
* @return Hash map of boat status
|
||||||
|
*/
|
||||||
|
public Map<Integer, BoatStatusMessage> getBoatStatus() {
|
||||||
|
return boatStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an inputStream and reads the first 15 bytes (the header) and gets the message length
|
* 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
|
* for the whole message then reads that and returns the byte array
|
||||||
@@ -128,14 +158,18 @@ public class VisualiserInput implements Runnable
|
|||||||
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
// System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||||
break;
|
break;
|
||||||
case RACESTATUS:
|
case RACESTATUS:
|
||||||
// System.out.println("Race Status Message");
|
System.out.println("Race Status Message");
|
||||||
|
raceStatus = ((RaceStatus) data);
|
||||||
|
for (BoatStatusMessage msg: raceStatus.getBoatStatusMessages()){
|
||||||
|
boatStatus.put(msg.getSourceID(), msg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DISPLAYTEXTMESSAGE:
|
case DISPLAYTEXTMESSAGE:
|
||||||
// System.out.println("Display Text Message");
|
// System.out.println("Display Text Message");
|
||||||
//no decoder for this.
|
//no decoder for this.
|
||||||
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){
|
||||||
@@ -159,7 +193,7 @@ public class VisualiserInput implements Runnable
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RACESTARTSTATUS:
|
case RACESTARTSTATUS:
|
||||||
System.out.println("Race Start Status Message");
|
//System.out.println("Race Start Status Message");
|
||||||
break;
|
break;
|
||||||
case YACHTEVENTCODE:
|
case YACHTEVENTCODE:
|
||||||
// System.out.println("Yacht Action Code!");
|
// System.out.println("Yacht Action Code!");
|
||||||
|
|||||||
@@ -44,4 +44,5 @@ public class BoatsXMLTest {
|
|||||||
StreamedBoat boat = (StreamedBoat) boatXMLReader.getBoats().get(0);
|
StreamedBoat boat = (StreamedBoat) boatXMLReader.getBoats().get(0);
|
||||||
assertEquals(boat.getSourceID(), 101);
|
assertEquals(boat.getSourceID(), 101);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user