mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Cleaned up code for merge.
#story[889]
This commit is contained in:
@@ -63,8 +63,6 @@ public class App extends Application
|
|||||||
//Change the StreamReceiver in this else block to change the default data source.
|
//Change the StreamReceiver in this else block to change the default data source.
|
||||||
else{
|
else{
|
||||||
sr = new StreamReceiver("localhost", 4949, "RaceStream");
|
sr = new StreamReceiver("localhost", 4949, "RaceStream");
|
||||||
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
|
|
||||||
// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.start();
|
sr.start();
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ public class CanvasController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkForCourseChanges() {
|
private void checkForCourseChanges() {
|
||||||
if (StreamParser.isNewXmlRecieved()){
|
if (StreamParser.isNewRaceXmlReceived()){
|
||||||
System.out.println("New Canvas found");
|
System.out.println("New Canvas found");
|
||||||
gc.setFill(Color.SKYBLUE);
|
gc.setFill(Color.SKYBLUE);
|
||||||
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
||||||
@@ -357,7 +357,8 @@ public class CanvasController {
|
|||||||
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
|
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
|
||||||
*/
|
*/
|
||||||
private void fitMarksToCanvas() {
|
private void fitMarksToCanvas() {
|
||||||
StreamParser.isNewXmlRecieved();
|
//Check is called once to avoid unnecessarily change the course limits once the race is running
|
||||||
|
StreamParser.isNewRaceXmlReceived();
|
||||||
findMinMaxPoint();
|
findMinMaxPoint();
|
||||||
double minLonToMaxLon = scaleRaceExtremities();
|
double minLonToMaxLon = scaleRaceExtremities();
|
||||||
calculateReferencePointLocation(minLonToMaxLon);
|
calculateReferencePointLocation(minLonToMaxLon);
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package seng302.models.parsers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Kusal on 4/24/2017.
|
|
||||||
*/
|
|
||||||
public enum PacketType {
|
|
||||||
HEARTBEAT,
|
|
||||||
RACE_STATUS,
|
|
||||||
DISPLAY_TEXT_MESSAGE,
|
|
||||||
XML_MESSAGE,
|
|
||||||
RACE_START_STATUS,
|
|
||||||
YACHT_EVENT_CODE,
|
|
||||||
YACHT_ACTION_CODE,
|
|
||||||
CHATTER_TEXT,
|
|
||||||
BOAT_LOCATION,
|
|
||||||
MARK_ROUNDING,
|
|
||||||
COURSE_WIND,
|
|
||||||
AVG_WIND,
|
|
||||||
OTHER;
|
|
||||||
|
|
||||||
static PacketType assignPacketType(int packetType){
|
|
||||||
switch(packetType){
|
|
||||||
case 1:
|
|
||||||
return HEARTBEAT;
|
|
||||||
case 12:
|
|
||||||
return RACE_STATUS;
|
|
||||||
case 20:
|
|
||||||
return DISPLAY_TEXT_MESSAGE;
|
|
||||||
case 26:
|
|
||||||
return XML_MESSAGE;
|
|
||||||
case 27:
|
|
||||||
return RACE_START_STATUS;
|
|
||||||
case 29:
|
|
||||||
return YACHT_EVENT_CODE;
|
|
||||||
case 31:
|
|
||||||
return YACHT_ACTION_CODE;
|
|
||||||
case 36:
|
|
||||||
return CHATTER_TEXT;
|
|
||||||
case 37:
|
|
||||||
return BOAT_LOCATION;
|
|
||||||
case 38:
|
|
||||||
return MARK_ROUNDING;
|
|
||||||
case 44:
|
|
||||||
return COURSE_WIND;
|
|
||||||
case 47:
|
|
||||||
return AVG_WIND;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
return OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package seng302.models.parsers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by kre39 on 23/04/17.
|
|
||||||
*/
|
|
||||||
public class StreamPacket {
|
|
||||||
|
|
||||||
//Change int to an ENUM for the type
|
|
||||||
private PacketType type;
|
|
||||||
|
|
||||||
private long messageLength;
|
|
||||||
private long timeStamp;
|
|
||||||
private byte[] payload;
|
|
||||||
|
|
||||||
StreamPacket(int type, long messageLength, long timeStamp, byte[] payload) {
|
|
||||||
this.type = PacketType.assignPacketType(type);
|
|
||||||
this.messageLength = messageLength;
|
|
||||||
this.timeStamp = timeStamp;
|
|
||||||
this.payload = payload;
|
|
||||||
// System.out.println("type = " + this.type.toString());
|
|
||||||
//switch the packet type to deal with what ever specific packet you want to deal with
|
|
||||||
// if (this.type == PacketType.XML_MESSAGE){
|
|
||||||
// //System.out.println("--------");
|
|
||||||
// System.out.println(new String(payload));
|
|
||||||
// //StreamParser.parsePacket(this);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMessageLength() {
|
|
||||||
return messageLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
long getTimeStamp() {
|
|
||||||
return timeStamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,7 +31,7 @@ public class StreamParser extends Thread{
|
|||||||
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
|
||||||
private String threadName;
|
private String threadName;
|
||||||
private Thread t;
|
private Thread t;
|
||||||
private static boolean newXmlRecieved = false;
|
private static boolean newRaceXmlReceived = false;
|
||||||
private static boolean raceStarted = false;
|
private static boolean raceStarted = false;
|
||||||
private static XMLParser xmlObject;
|
private static XMLParser xmlObject;
|
||||||
private static boolean raceFinished = false;
|
private static boolean raceFinished = false;
|
||||||
@@ -124,7 +124,7 @@ public class StreamParser extends Thread{
|
|||||||
break;
|
break;
|
||||||
case XML_MESSAGE:
|
case XML_MESSAGE:
|
||||||
System.out.println("XML MESSAGE GOT");
|
System.out.println("XML MESSAGE GOT");
|
||||||
newXmlRecieved = true;
|
newRaceXmlReceived = true;
|
||||||
extractXmlMessage(packet);
|
extractXmlMessage(packet);
|
||||||
break;
|
break;
|
||||||
case RACE_START_STATUS:
|
case RACE_START_STATUS:
|
||||||
@@ -299,7 +299,6 @@ public class StreamParser extends Thread{
|
|||||||
int messageType = payload[9];
|
int messageType = payload[9];
|
||||||
long messageLength = bytesToLong(Arrays.copyOfRange(payload,12,14));
|
long messageLength = bytesToLong(Arrays.copyOfRange(payload,12,14));
|
||||||
String xmlMessage = new String((Arrays.copyOfRange(payload,14,(int) (14 + messageLength)))).trim();
|
String xmlMessage = new String((Arrays.copyOfRange(payload,14,(int) (14 + messageLength)))).trim();
|
||||||
System.out.println("xmlMessage = " + xmlMessage);
|
|
||||||
|
|
||||||
//Create XML document Object
|
//Create XML document Object
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
@@ -317,7 +316,7 @@ public class StreamParser extends Thread{
|
|||||||
boats = xmlObject.getBoatXML().getCompetingBoats();
|
boats = xmlObject.getBoatXML().getCompetingBoats();
|
||||||
}
|
}
|
||||||
if (messageType == 6) { //6 is race info xml
|
if (messageType == 6) { //6 is race info xml
|
||||||
newXmlRecieved = true;
|
newRaceXmlReceived = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,9 +585,15 @@ public class StreamParser extends Thread{
|
|||||||
System.out.println("[CLIENT] Shutting down stream parser");
|
System.out.println("[CLIENT] Shutting down stream parser");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNewXmlRecieved(){
|
/**
|
||||||
if (newXmlRecieved){
|
* Used to check if a new un-processed xml has been found, if so will return true before
|
||||||
newXmlRecieved = false;
|
* toggling off so that the next check will return false.
|
||||||
|
*
|
||||||
|
* @return the status of if new xml has been received
|
||||||
|
*/
|
||||||
|
public static boolean isNewRaceXmlReceived(){
|
||||||
|
if (newRaceXmlReceived){
|
||||||
|
newRaceXmlReceived = false;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},25000);
|
},25000);
|
||||||
|
//Delays the new course xml data for 25 seconds so the boats are able to pass the starting line
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
import seng302.models.parsers.packets.StreamPacket;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|||||||
Reference in New Issue
Block a user