Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into splitIntoTwoModules
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>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package seng302.Controllers;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
|
import seng302.VisualiserInput;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -16,8 +17,8 @@ public class MainController extends Controller {
|
|||||||
@FXML
|
@FXML
|
||||||
RaceController raceController;
|
RaceController raceController;
|
||||||
|
|
||||||
public void beginRace(int scaleFactor, RaceDataSource raceData) {
|
public void beginRace(VisualiserInput visualiserInput) {
|
||||||
raceController.startRace(scaleFactor, raceData);
|
raceController.startRace(visualiserInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import seng302.Mock.StreamedRace;
|
|||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
import seng302.RaceXMLReader;
|
import seng302.RaceXMLReader;
|
||||||
|
import seng302.VisualiserInput;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -114,13 +115,13 @@ public class RaceController extends Controller {
|
|||||||
* Initializes and runs the race, based on the user's chosen scale factor
|
* Initializes and runs the race, based on the user's chosen scale factor
|
||||||
* Currently uses an example racecourse
|
* Currently uses an example racecourse
|
||||||
*
|
*
|
||||||
* @param scaleFactor scale value of race
|
* @param visualiserInput
|
||||||
*/
|
*/
|
||||||
public void startRace(int scaleFactor, RaceDataSource raceData) {
|
public void startRace(VisualiserInput visualiserInput) {
|
||||||
StreamedRace newRace = new StreamedRace(raceData, this, scaleFactor);
|
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||||
//newRace.initialiseBoats();
|
//newRace.initialiseBoats();
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas(raceData);
|
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||||
raceMap.setMouseTransparent(true);
|
raceMap.setMouseTransparent(true);
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||||
@@ -133,8 +134,8 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
//Initialize save annotation array, fps listener, and annotation listeners
|
//Initialize save annotation array, fps listener, and annotation listeners
|
||||||
//timezone
|
//timezone
|
||||||
RaceClock raceClock = new RaceClock(raceData.getZonedDateTime());
|
// RaceClock raceClock = new RaceClock(visualiserInput.getCourse().getZonedDateTime());
|
||||||
timeZone.setText(raceClock.getTimeZone());
|
// timeZone.setText(raceClock.getTimeZone());
|
||||||
initializeFPS();
|
initializeFPS();
|
||||||
initializeAnnotations();
|
initializeAnnotations();
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import seng302.RaceDataSource;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -53,6 +55,8 @@ public class StartController extends Controller implements Observer {
|
|||||||
private StreamedCourse raceData;
|
private StreamedCourse raceData;
|
||||||
private long timeLeft = 1;
|
private long timeLeft = 1;
|
||||||
|
|
||||||
|
private VisualiserInput visualiserInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins the race with a scale factor of 15
|
* Begins the race with a scale factor of 15
|
||||||
*/
|
*/
|
||||||
@@ -88,7 +92,7 @@ public class StartController extends Controller implements Observer {
|
|||||||
try {
|
try {
|
||||||
raceData = new StreamedCourse();
|
raceData = new StreamedCourse();
|
||||||
raceData.addObserver(this);
|
raceData.addObserver(this);
|
||||||
VisualiserInput visualiserInput = new VisualiserInput(raceData);
|
visualiserInput = new VisualiserInput(new Socket("livedata.americascup.com", 4941), raceData);
|
||||||
new Thread(visualiserInput).start();
|
new Thread(visualiserInput).start();
|
||||||
// StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
// StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
||||||
// streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
// streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
||||||
@@ -150,7 +154,7 @@ public class StartController extends Controller implements Observer {
|
|||||||
if (timeLeft <= 0) {
|
if (timeLeft <= 0) {
|
||||||
updateTime("Race is starting...");
|
updateTime("Race is starting...");
|
||||||
stop();
|
stop();
|
||||||
parent.beginRace(scaleFactor, raceData);
|
parent.beginRace(visualiserInput);
|
||||||
startWrapper.setVisible(false);
|
startWrapper.setVisible(false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -80,12 +80,15 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
private void readRace() throws ParseException {
|
private void readRace() throws ParseException {
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
||||||
|
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
||||||
|
|
||||||
|
if (raceTimeTag.getNamedItem("Time") != null) dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
if (raceTimeTag.getNamedItem("Time") != null) 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);
|
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
|
||||||
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
||||||
@@ -93,6 +96,7 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
|
|
||||||
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);
|
||||||
@@ -160,7 +164,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import seng302.Constants;
|
|||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
|
import seng302.Networking.MessageDecoders.BoatLocationDecoder;
|
||||||
|
import seng302.Networking.Utils.BoatLocationMessage;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
|
import seng302.VisualiserInput;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -15,12 +18,12 @@ import java.util.*;
|
|||||||
* Created by jjg64 on 21/04/17.
|
* Created by jjg64 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
public class StreamedRace extends Race {
|
public class StreamedRace extends Race {
|
||||||
private RaceDataSource raceData;
|
private VisualiserInput visualiserInput;
|
||||||
|
private double MMPS_TO_KN = 0.001944;
|
||||||
|
|
||||||
public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
public StreamedRace(VisualiserInput visualiserInput, RaceController controller) {
|
||||||
super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
|
super(visualiserInput.getCourse(), controller, 1);
|
||||||
this.raceData = raceData;
|
this.visualiserInput = visualiserInput;
|
||||||
this.scaleFactor = 1; // There will be no scaling in a live streamed race
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialiseBoats() {
|
public void initialiseBoats() {
|
||||||
@@ -72,8 +75,16 @@ public class StreamedRace extends Race {
|
|||||||
* @param millisecondsElapsed time since last update
|
* @param millisecondsElapsed time since last update
|
||||||
*/
|
*/
|
||||||
protected void updatePosition(Boat boat, int millisecondsElapsed) {
|
protected void updatePosition(Boat boat, int millisecondsElapsed) {
|
||||||
//TODO Grab info from network
|
int sourceID = boat.getSourceID();
|
||||||
// setPosition(boat, coordinate);
|
BoatLocationMessage boatLocationMessage = visualiserInput.getBoatLocationMessage(sourceID);
|
||||||
|
if(boatLocationMessage != null) {
|
||||||
|
System.out.println(sourceID);
|
||||||
|
double lat = boatLocationMessage.getLatitudeDouble();
|
||||||
|
double lon = boatLocationMessage.getLongitudeDouble();
|
||||||
|
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
|
||||||
|
boat.setHeading(boatLocationMessage.getHeadingDegrees());
|
||||||
|
boat.setVelocity(boatLocationMessage.getBoatSpeed() * MMPS_TO_KN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPosition(Boat boat, GPSCoordinate coordinate) {
|
protected void setPosition(Boat boat, GPSCoordinate coordinate) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class Boat {
|
|||||||
protected long timeFinished;
|
protected long timeFinished;
|
||||||
protected StringProperty position;
|
protected StringProperty position;
|
||||||
protected boolean started = false;
|
protected boolean started = false;
|
||||||
|
protected boolean dnf = false;
|
||||||
private double wakeScale = 1 / 50;
|
private double wakeScale = 1 / 50;
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
|
|
||||||
@@ -234,4 +235,12 @@ public class Boat {
|
|||||||
public int getSourceID() {
|
public int getSourceID() {
|
||||||
return this.sourceID;
|
return this.sourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDnf() {
|
||||||
|
return dnf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDnf(boolean dnf) {
|
||||||
|
this.dnf = dnf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.geotools.referencing.GeodeticCalculator;
|
|||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
|
import seng302.VisualiserInput;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -31,7 +32,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race
|
||||||
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +70,10 @@ public abstract class Race implements Runnable {
|
|||||||
this(Arrays.asList(startingBoats), legs, controller, scaleFactor);
|
this(Arrays.asList(startingBoats), legs, controller, scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setController(RaceController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void initialiseBoats();
|
public abstract void initialiseBoats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,9 +51,10 @@ public class VisualiserInput implements Runnable
|
|||||||
private RaceStartStatus raceStartStatus;
|
private RaceStartStatus raceStartStatus;
|
||||||
|
|
||||||
public VisualiserInput(StreamedCourse course) throws IOException{
|
public VisualiserInput(StreamedCourse course) throws IOException{
|
||||||
|
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
||||||
|
|
||||||
//connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
this.connectionSocket = socket;
|
||||||
this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
// this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||||
|
|
||||||
this.course = course;
|
this.course = course;
|
||||||
this.boatLocation = new HashMap<>();
|
this.boatLocation = new HashMap<>();
|
||||||
@@ -188,7 +189,7 @@ public class VisualiserInput implements Runnable
|
|||||||
lastHeartbeatTime = System.currentTimeMillis();
|
lastHeartbeatTime = System.currentTimeMillis();
|
||||||
//note: if the program runs for over 340 years, this will crash.
|
//note: if the program runs for over 340 years, this will crash.
|
||||||
heartbeatSeqNum = ByteConverter.bytesToLong(testDecoder.getMessage());
|
heartbeatSeqNum = ByteConverter.bytesToLong(testDecoder.getMessage());
|
||||||
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");
|
||||||
@@ -243,6 +244,7 @@ public class VisualiserInput implements Runnable
|
|||||||
//no decoder
|
//no decoder
|
||||||
break;
|
break;
|
||||||
case BOATLOCATION:
|
case BOATLOCATION:
|
||||||
|
System.out.println("Boat Location!");
|
||||||
BoatLocationMessage msg = (BoatLocationMessage) data;
|
BoatLocationMessage msg = (BoatLocationMessage) data;
|
||||||
if (boatLocation.containsKey(msg.getSourceID())){
|
if (boatLocation.containsKey(msg.getSourceID())){
|
||||||
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
|
||||||
@@ -286,7 +288,8 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
public static void main(String argv[]) throws Exception
|
public static void main(String argv[]) throws Exception
|
||||||
{
|
{
|
||||||
VisualiserInput receiver = new VisualiserInput(new StreamedCourse());
|
Socket socket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||||
|
VisualiserInput receiver = new VisualiserInput(socket, new StreamedCourse());
|
||||||
receiver.run();
|
receiver.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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