Merge remote-tracking branch 'origin/wake_remake' into develop

# Conflicts:
#	src/main/java/seng302/App.java
This commit is contained in:
Zhi You Tan
2017-05-02 22:09:03 +12:00
6 changed files with 57 additions and 19 deletions
+5 -5
View File
@@ -31,16 +31,16 @@ public class App extends Application
} }
if (args.length > 1){ if (args.length > 1){
sr = new StreamReceiver("localhost", 8085, "TestThread1"); sr = new StreamReceiver("localhost", 8085, "RaceStream");
} }
else{ else{
sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1"); // sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"RaceStream");
// sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1"); sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
// sr = new StreamReceiver("localhost", 8085, "TestThread1"); // sr = new StreamReceiver("localhost", 8085, "RaceStream");
} }
sr.start(); sr.start();
StreamParser streamParser = new StreamParser("TestThread2"); StreamParser streamParser = new StreamParser("StreamParser");
streamParser.start(); streamParser.start();
launch(args); launch(args);
@@ -300,6 +300,8 @@ public class CanvasController {
private void drawFps(int fps){ private void drawFps(int fps){
if (raceViewController.isDisplayFps()){ if (raceViewController.isDisplayFps()){
gc.clearRect(5,5,50,20); gc.clearRect(5,5,50,20);
gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21);
gc.setFill(Color.BLACK); gc.setFill(Color.BLACK);
gc.setFont(new Font(14)); gc.setFont(new Font(14));
gc.setLineWidth(3); gc.setLineWidth(3);
@@ -15,7 +15,6 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import seng302.models.Boat;
import seng302.models.parsers.StreamParser; import seng302.models.parsers.StreamParser;
import seng302.models.parsers.XMLParser; import seng302.models.parsers.XMLParser;
@@ -124,18 +123,18 @@ public class Controller implements Initializable {
} }
private void updateTeamList() { private void updateTeamList() {
ObservableList<Boat> data = FXCollections.observableArrayList(); ObservableList<XMLParser.BoatXMLObject.Boat> data = FXCollections.observableArrayList();
teamList.setItems(data); teamList.setItems(data);
boatNameCol.setCellValueFactory( boatNameCol.setCellValueFactory(
new PropertyValueFactory<Boat,String>("boatName") new PropertyValueFactory<XMLParser.BoatXMLObject.Boat,String>("BoatName")
); );
shortNameCol.setCellValueFactory( shortNameCol.setCellValueFactory(
new PropertyValueFactory<Boat,String>("shortName") new PropertyValueFactory<XMLParser.BoatXMLObject.Boat,String>("ShortName")
); );
countryCol.setCellValueFactory( countryCol.setCellValueFactory(
new PropertyValueFactory<Boat,String>("country") new PropertyValueFactory<XMLParser.BoatXMLObject.Boat,String>("Country")
); );
for (Boat boat : StreamParser.getBoats()) { for (XMLParser.BoatXMLObject.Boat boat : StreamParser.getBoats()) {
data.add(boat); data.add(boat);
} }
} }
@@ -69,11 +69,11 @@ public class RaceViewController extends Thread{
includedCanvasController.initializeCanvas(); includedCanvasController.initializeCanvas();
initializeTimer(); initializeTimer();
initializeSettings(); initializeSettings();
initialiseWindDirection();
//set wind direction!!!!!!! can't find another place to put my code --haoming //set wind direction!!!!!!! can't find another place to put my code --haoming
double windDirection = new ConfigParser("/config/config.xml").getWindDirection(); // double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
windDirectionText.setText(String.format("%.1f°", windDirection)); // windDirectionText.setText(String.format("%.1f°", windDirection));
windArrowText.setRotate(windDirection); // windArrowText.setRotate(windDirection);
includedCanvasController.timer.start(); includedCanvasController.timer.start();
} }
@@ -145,6 +145,19 @@ public class RaceViewController extends Thread{
timerTimeline.playFromStart(); timerTimeline.playFromStart();
} }
private void initialiseWindDirection() {
Timeline windDirTimeline = new Timeline();
windDirTimeline.setCycleCount(Timeline.INDEFINITE);
windDirTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1),
event -> {
windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection()));
windArrowText.setRotate(StreamParser.getWindDirection());
})
);
windDirTimeline.playFromStart();
}
/** /**
* Generates time line for each boat, and stores time time into timelineInfos hash map * Generates time line for each boat, and stores time time into timelineInfos hash map
*/ */
@@ -5,7 +5,6 @@ import javafx.geometry.Point3D;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import seng302.models.Boat;
import seng302.models.parsers.packets.BoatPositionPacket; import seng302.models.parsers.packets.BoatPositionPacket;
import seng302.models.parsers.packets.StreamPacket; import seng302.models.parsers.packets.StreamPacket;
@@ -38,7 +37,8 @@ public class StreamParser extends Thread{
private static boolean raceFinished = false; private static boolean raceFinished = false;
private static boolean streamStatus = false; private static boolean streamStatus = false;
private static long timeSinceStart = -1; private static long timeSinceStart = -1;
private static List<Boat> boats = new ArrayList<>(); private static List<XMLParser.BoatXMLObject.Boat> boats = new ArrayList<>();
private static double windDirection = 0;
/** /**
* Used to initialise the thread name and stream parser object so a thread can be executed * Used to initialise the thread name and stream parser object so a thread can be executed
@@ -194,12 +194,15 @@ public class StreamParser extends Thread{
timeSinceStart = timeTillStart; timeSinceStart = timeTillStart;
} }
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20)); long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc...
windDirection = windDir / windDirFactor;
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22)); long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
int noBoats = payload[22]; int noBoats = payload[22];
int raceType = payload[23]; int raceType = payload[23];
ArrayList<String> boatStatuses = new ArrayList<>(); ArrayList<String> boatStatuses = new ArrayList<>();
for (int i = 0; i < noBoats; i++){ for (int i = 0; i < noBoats; i++){
String boatStatus = "SourceID: " + bytesToLong(Arrays.copyOfRange(payload,24 + (i * 20),28+ (i * 20))); Long boatStatusSourceID = bytesToLong(Arrays.copyOfRange(payload,24 + (i * 20),28+ (i * 20)));
String boatStatus = "SourceID: " + boatStatusSourceID;
boatStatus += "\nBoat Status: " + (int)payload[28 + (i * 20)]; boatStatus += "\nBoat Status: " + (int)payload[28 + (i * 20)];
boatStatus += "\nLegNumber: " + (int)payload[29 + (i * 20)]; boatStatus += "\nLegNumber: " + (int)payload[29 + (i * 20)];
boatStatus += "\nPenaltiesAwarded: " + (int)payload[29 + (i * 20)]; boatStatus += "\nPenaltiesAwarded: " + (int)payload[29 + (i * 20)];
@@ -255,6 +258,9 @@ public class StreamParser extends Thread{
} }
xmlObject.constructXML(doc, messageType); xmlObject.constructXML(doc, messageType);
if (messageType == 7) { //7 is the boat XML
boats = xmlObject.getBoatXML().getCompetingBoats();
}
} }
/** /**
@@ -474,7 +480,7 @@ public class StreamParser extends Thread{
* *
* @return list of boats * @return list of boats
*/ */
public static List<Boat> getBoats() { public static List<XMLParser.BoatXMLObject.Boat> getBoats() {
return boats; return boats;
} }
@@ -487,5 +493,14 @@ public class StreamParser extends Thread{
public static XMLParser getXmlObject() { public static XMLParser getXmlObject() {
return xmlObject; return xmlObject;
} }
/**
* returns the wind direction in degrees
*
* @return a double wind direction value
*/
public static double getWindDirection() {
return windDirection;
}
} }
@@ -6,6 +6,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Class to create an XML object from the XML Packet Messages. * Class to create an XML object from the XML Packet Messages.
@@ -392,6 +393,8 @@ public class XMLParser {
//Boats //Boats
ArrayList<Boat> boats; ArrayList<Boat> boats;
//Competing boats
List<Boat> competingBoats = new ArrayList<>();
/** /**
* Constructor for a BoatXMLObject. * Constructor for a BoatXMLObject.
@@ -426,6 +429,9 @@ public class XMLParser {
if (currentBoat.getNodeName().equals("Boat")) { if (currentBoat.getNodeName().equals("Boat")) {
Boat boat = new Boat(currentBoat); Boat boat = new Boat(currentBoat);
this.boats.add(boat); this.boats.add(boat);
if (boat.getBoatType().equals("Yacht")) {
competingBoats.add(boat);
}
} }
//System.out.println(this.getBoats()); //System.out.println(this.getBoats());
} }
@@ -441,6 +447,9 @@ public class XMLParser {
public Double getCourseZoneSize() { return courseZoneSize; } public Double getCourseZoneSize() { return courseZoneSize; }
public ArrayList<Double> getZoneLimits() { return zoneLimits; } public ArrayList<Double> getZoneLimits() { return zoneLimits; }
public ArrayList<Boat> getBoats() { return boats; } public ArrayList<Boat> getBoats() { return boats; }
public List<Boat> getCompetingBoats() {
return competingBoats;
}
public class Boat { public class Boat {