Updated wind direction on race view controller so it responds to the stream.

#story[818]
This commit is contained in:
Zhi You Tan
2017-05-02 18:02:44 +12:00
parent 04ce6f6103
commit 3af15b2b95
3 changed files with 30 additions and 5 deletions
@@ -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
*/ */
@@ -39,6 +39,7 @@ public class StreamParser extends Thread{
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<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,6 +195,8 @@ 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];
@@ -487,5 +490,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;
}
} }
@@ -265,7 +265,7 @@ public class ServerThread implements Runnable, Observer {
for (Boat b : ((Simulator) o).getBoats()){ for (Boat b : ((Simulator) o).getBoats()){
try { try {
Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(), Message m = new BoatLocationMessage(b.getSourceID(), 1, b.getLat(),
b.getLng(), b.getHeadingCorner().getBearingToNextCorner(), b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(),
((long) b.getSpeed())); ((long) b.getSpeed()));
server.send(m); server.send(m);
} catch (IOException e) { } catch (IOException e) {