mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Removed broken time extracting method and replaced it with currently existing long extractor. Added speed to the setDestination method for the raceObject abstract class.
#story[820]
This commit is contained in:
@@ -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{
|
||||||
//StreamReceiver 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);
|
||||||
|
|||||||
@@ -128,13 +128,14 @@ public class CanvasController {
|
|||||||
for (RaceObject raceObject : raceObjects) {
|
for (RaceObject raceObject : raceObjects) {
|
||||||
raceObject.updatePosition(elapsedNanos);
|
raceObject.updatePosition(elapsedNanos);
|
||||||
for (int id : raceObject.getRaceIds()) {
|
for (int id : raceObject.getRaceIds()) {
|
||||||
if (StreamParser.boatPositions.containsKey((long) id)) {
|
if (StreamParser.getBoatPositions().containsKey((long) id)) {
|
||||||
Point3D p = StreamParser.boatPositions.get((long) id);
|
Point3D p = StreamParser.getBoatPositions().get((long) id);
|
||||||
Point2D p2d = latLonToXY(p.getX(), p.getY());
|
Point2D p2d = latLonToXY(p.getX(), p.getY());
|
||||||
|
double speed = StreamParser.getBoatSpeeds().get((long) id);
|
||||||
double heading = 360.0 / 0xffff * p.getZ();
|
double heading = 360.0 / 0xffff * p.getZ();
|
||||||
raceObject.setDestination(p2d.getX(), p2d.getY(), heading, id);
|
raceObject.setDestination(p2d.getX(), p2d.getY(), heading, speed, id);
|
||||||
}
|
}
|
||||||
StreamParser.boatPositions.remove((long) id);
|
StreamParser.getBoatPositions().remove((long) id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,10 +179,10 @@ public class BoatGroup extends RaceObject{
|
|||||||
* @param rotation Rotation to move graphics to.
|
* @param rotation Rotation to move graphics to.
|
||||||
* @param raceIds RaceID of the object to move.
|
* @param raceIds RaceID of the object to move.
|
||||||
*/
|
*/
|
||||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
public void setDestination (double newXValue, double newYValue, double rotation, double speed, int... raceIds) {
|
||||||
if (hasRaceId(raceIds)) {
|
if (hasRaceId(raceIds)) {
|
||||||
destinationSet = true;
|
destinationSet = true;
|
||||||
boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
boat.setVelocity(speed);
|
||||||
if (currentRotation < 0)
|
if (currentRotation < 0)
|
||||||
currentRotation = 360 - currentRotation;
|
currentRotation = 360 - currentRotation;
|
||||||
double dx = newXValue - boatPoly.getLayoutX();
|
double dx = newXValue - boatPoly.getLayoutX();
|
||||||
@@ -226,7 +226,7 @@ public class BoatGroup extends RaceObject{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double newXValue, double newYValue, int... raceIDs) {
|
public void setDestination (double newXValue, double newYValue, double speed, int... raceIDs) {
|
||||||
destinationSet = true;
|
destinationSet = true;
|
||||||
|
|
||||||
if (hasRaceId(raceIDs)) {
|
if (hasRaceId(raceIDs)) {
|
||||||
@@ -237,7 +237,7 @@ public class BoatGroup extends RaceObject{
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
setDestination(newXValue, newYValue, rotation, raceIDs);
|
setDestination(newXValue, newYValue, rotation, speed, raceIDs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public abstract class RaceObject extends Group {
|
|||||||
* @param rotation Rotation to move graphics to.
|
* @param rotation Rotation to move graphics to.
|
||||||
* @param raceIds RaceID of the object to move.
|
* @param raceIds RaceID of the object to move.
|
||||||
*/
|
*/
|
||||||
public abstract void setDestination (double x, double y, double rotation, int... raceIds);
|
public abstract void setDestination (double x, double y, double rotation, double speed, int... raceIds);
|
||||||
/**
|
/**
|
||||||
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
||||||
* set to the co-ordinates (x, y).
|
* set to the co-ordinates (x, y).
|
||||||
@@ -69,7 +69,7 @@ public abstract class RaceObject extends Group {
|
|||||||
* @param y Y co-ordinate to move the graphic to.
|
* @param y Y co-ordinate to move the graphic to.
|
||||||
* @param raceIds RaceID to the object to move.
|
* @param raceIds RaceID to the object to move.
|
||||||
*/
|
*/
|
||||||
public abstract void setDestination (double x, double y, int... raceIds);
|
public abstract void setDestination (double x, double y, double speed, int... raceIds);
|
||||||
|
|
||||||
public abstract void updatePosition (long timeInterval);
|
public abstract void updatePosition (long timeInterval);
|
||||||
|
|
||||||
|
|||||||
@@ -102,21 +102,21 @@ public class MarkGroup extends RaceObject {
|
|||||||
//moveTo(points[0].getX(), points[0].getY());
|
//moveTo(points[0].getX(), points[0].getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double x, double y, double rotation, int... raceIds) {
|
public void setDestination (double x, double y, double rotation, double speed, int... raceIds) {
|
||||||
setDestination(x, y, raceIds);
|
setDestination(x, y, 0, raceIds);
|
||||||
this.rotationalGoal = rotation;
|
this.rotationalGoal = rotation;
|
||||||
calculateRotationalVelocity();
|
calculateRotationalVelocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double x, double y, int... raceIds) {
|
public void setDestination (double x, double y, double speed, int... raceIds) {
|
||||||
for (int i = 0; i < marks.size(); i++)
|
for (int i = 0; i < marks.size(); i++)
|
||||||
for (int id : raceIds)
|
for (int id : raceIds)
|
||||||
if (id == marks.get(i).getId())
|
if (id == marks.get(i).getId())
|
||||||
setDestinationChild(x, y, Math.max(0, i-1));
|
setDestinationChild(x, y, 0, Math.max(0, i-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setDestinationChild (double x, double y, int childIndex) {
|
private void setDestinationChild (double x, double y, double speed, int childIndex) {
|
||||||
//double relativeX = x - super.getLayoutX();
|
//double relativeX = x - super.getLayoutX();
|
||||||
//double relativeY = y - super.getLayoutY();
|
//double relativeY = y - super.getLayoutY();
|
||||||
Circle markCircle = (Circle) super.getChildren().get(childIndex);
|
Circle markCircle = (Circle) super.getChildren().get(childIndex);
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class StreamParser extends Thread{
|
public class StreamParser extends Thread{
|
||||||
|
|
||||||
public static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
||||||
public static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
||||||
private String threadName;
|
private String threadName;
|
||||||
private Thread t;
|
private Thread t;
|
||||||
private static boolean raceStarted = false;
|
private static boolean raceStarted = false;
|
||||||
@@ -156,11 +156,11 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractRaceStatus(StreamPacket packet){
|
private static void extractRaceStatus(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long currentTime = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long currentTime = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11));
|
long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11));
|
||||||
int raceStatus = payload[11];
|
int raceStatus = payload[11];
|
||||||
// System.out.println("raceStatus = " + raceStatus);
|
// System.out.println("raceStatus = " + raceStatus);
|
||||||
long expectedStartTime = extractTimeStamp(Arrays.copyOfRange(payload,12,18), 6);
|
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
|
||||||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
||||||
@@ -193,8 +193,8 @@ public class StreamParser extends Thread{
|
|||||||
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)];
|
||||||
boatStatus += "\nPenaltiesServed: " + (int)payload[30 + (i * 20)];
|
boatStatus += "\nPenaltiesServed: " + (int)payload[30 + (i * 20)];
|
||||||
boatStatus += "\nEstTimeAtNextMark: " + extractTimeStamp(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)), 6);
|
boatStatus += "\nEstTimeAtNextMark: " + bytesToLong(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)));
|
||||||
boatStatus += "\nEstTimeAtFinish: " + extractTimeStamp(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)), 6);
|
boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)));
|
||||||
boatStatuses.add(boatStatus);
|
boatStatuses.add(boatStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,8 +252,8 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractRaceStartStatus(StreamPacket packet){
|
private static void extractRaceStartStatus(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long raceStartTime = extractTimeStamp(Arrays.copyOfRange(payload,9,15), 6);
|
long raceStartTime = bytesToLong(Arrays.copyOfRange(payload,9,15));
|
||||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,15,19));
|
long raceId = bytesToLong(Arrays.copyOfRange(payload,15,19));
|
||||||
int notificationType = payload[19];
|
int notificationType = payload[19];
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractYachtEventCode(StreamPacket packet){
|
private static void extractYachtEventCode(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||||
long incidentId = bytesToLong(Arrays.copyOfRange(payload,17,21));
|
long incidentId = bytesToLong(Arrays.copyOfRange(payload,17,21));
|
||||||
@@ -281,7 +281,7 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractYachtActionCode(StreamPacket packet){
|
private static void extractYachtActionCode(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
long subjectId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||||
long incidentId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
long incidentId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||||
int eventId = payload[17];
|
int eventId = payload[17];
|
||||||
@@ -315,14 +315,14 @@ public class StreamParser extends Thread{
|
|||||||
byte[] headingBytes = Arrays.copyOfRange(payload,28,30);
|
byte[] headingBytes = Arrays.copyOfRange(payload,28,30);
|
||||||
byte[] groundSpeedBytes = Arrays.copyOfRange(payload,38,40);
|
byte[] groundSpeedBytes = Arrays.copyOfRange(payload,38,40);
|
||||||
|
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
|
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
|
||||||
long seq = bytesToLong(seqBytes);
|
long seq = bytesToLong(seqBytes);
|
||||||
long boatId = bytesToLong(boatIdBytes);
|
long boatId = bytesToLong(boatIdBytes);
|
||||||
long lat = bytesToLong(latBytes);
|
long lat = bytesToLong(latBytes);
|
||||||
long lon = bytesToLong(lonBytes);
|
long lon = bytesToLong(lonBytes);
|
||||||
long heading = bytesToLong(headingBytes);
|
long heading = bytesToLong(headingBytes);
|
||||||
// long speed = extractTimeStamp(speedBytes, 2);
|
// long speed = bytesToLong(speedBytes);
|
||||||
double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0;
|
double groundSpeed = bytesToLong(groundSpeedBytes)/1000.0;
|
||||||
short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF));
|
short s = (short) ((groundSpeedBytes[1] & 0xFF) << 8 | (groundSpeedBytes[0] & 0xFF));
|
||||||
if ((int)deviceType == 1 || (int)deviceType == 3){
|
if ((int)deviceType == 1 || (int)deviceType == 3){
|
||||||
@@ -345,7 +345,7 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractMarkRounding(StreamPacket packet){
|
private static void extractMarkRounding(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
long raceId = bytesToLong(Arrays.copyOfRange(payload,9,13));
|
||||||
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
long subjectId = bytesToLong(Arrays.copyOfRange(payload,13,17));
|
||||||
int boatStatus = payload[17];
|
int boatStatus = payload[17];
|
||||||
@@ -362,7 +362,7 @@ public class StreamParser extends Thread{
|
|||||||
ArrayList<String> windInfo = new ArrayList<>();
|
ArrayList<String> windInfo = new ArrayList<>();
|
||||||
for (int i = 0; i < loopCount; i++){
|
for (int i = 0; i < loopCount; i++){
|
||||||
String wind = "WindId: " + payload[3 + (20 * i)];
|
String wind = "WindId: " + payload[3 + (20 * i)];
|
||||||
wind += "\nTime: " + extractTimeStamp(Arrays.copyOfRange(payload,4 + (20 * i),10 + (20 * i)), 6);
|
wind += "\nTime: " + bytesToLong(Arrays.copyOfRange(payload,4 + (20 * i),10 + (20 * i)));
|
||||||
wind += "\nRaceId: " + bytesToLong(Arrays.copyOfRange(payload,10 + (20 * i),14 + (20 * i)));
|
wind += "\nRaceId: " + bytesToLong(Arrays.copyOfRange(payload,10 + (20 * i),14 + (20 * i)));
|
||||||
wind += "\nWindDirection: " + bytesToLong(Arrays.copyOfRange(payload,14 + (20 * i),16 + (20 * i)));
|
wind += "\nWindDirection: " + bytesToLong(Arrays.copyOfRange(payload,14 + (20 * i),16 + (20 * i)));
|
||||||
wind += "\nWindSpeed: " + bytesToLong(Arrays.copyOfRange(payload,16 + (20 * i),18 + (20 * i)));
|
wind += "\nWindSpeed: " + bytesToLong(Arrays.copyOfRange(payload,16 + (20 * i),18 + (20 * i)));
|
||||||
@@ -376,7 +376,7 @@ public class StreamParser extends Thread{
|
|||||||
private static void extractAvgWind(StreamPacket packet){
|
private static void extractAvgWind(StreamPacket packet){
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
long timeStamp = bytesToLong(Arrays.copyOfRange(payload,1,7));
|
||||||
long rawPeriod = bytesToLong(Arrays.copyOfRange(payload,7,9));
|
long rawPeriod = bytesToLong(Arrays.copyOfRange(payload,7,9));
|
||||||
long rawSamplePeriod = bytesToLong(Arrays.copyOfRange(payload,9,11));
|
long rawSamplePeriod = bytesToLong(Arrays.copyOfRange(payload,9,11));
|
||||||
long period2 = bytesToLong(Arrays.copyOfRange(payload,11,13));
|
long period2 = bytesToLong(Arrays.copyOfRange(payload,11,13));
|
||||||
@@ -387,16 +387,6 @@ public class StreamParser extends Thread{
|
|||||||
long speed4 = bytesToLong(Arrays.copyOfRange(payload,21,23));
|
long speed4 = bytesToLong(Arrays.copyOfRange(payload,21,23));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long extractTimeStamp(byte[] timeStampBytes, int noOfBytes){
|
|
||||||
long timeStamp = 0;
|
|
||||||
long multiplier=1;
|
|
||||||
for(int i = 0;i < noOfBytes;i++) {
|
|
||||||
timeStamp += timeStampBytes[i]*multiplier;
|
|
||||||
multiplier *= 256;
|
|
||||||
}
|
|
||||||
return timeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* takes an array of up to 7 bytes and returns a positive
|
* takes an array of up to 7 bytes and returns a positive
|
||||||
* long constructed from the input bytes
|
* long constructed from the input bytes
|
||||||
@@ -461,6 +451,13 @@ public class StreamParser extends Thread{
|
|||||||
return boats;
|
return boats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ConcurrentHashMap<Long, Point3D> getBoatPositions() {
|
||||||
|
return boatPositions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConcurrentHashMap<Long, Double> getBoatSpeeds() {
|
||||||
|
return boatSpeeds;
|
||||||
|
}
|
||||||
|
|
||||||
public static XMLParser getXmlObject() {
|
public static XMLParser getXmlObject() {
|
||||||
return xmlObject;
|
return xmlObject;
|
||||||
|
|||||||
Reference in New Issue
Block a user