mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
partway through fixing boat movement to be updated from the data valid timestamp rather than the data sent timestamp #story[820]
This commit is contained in:
@@ -146,21 +146,23 @@ public class BoatGroup extends RaceObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||||
destinationSet = true;
|
moveGroupBy(newXValue - boatPoly.getLayoutX(), newYValue - boatPoly.getLayoutY(), rotation);
|
||||||
boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
|
||||||
if (hasRaceId(raceIds)) {
|
// destinationSet = true;
|
||||||
this.pixelVelocityX = (newXValue - boatPoly.getLayoutX()) / expectedUpdateInterval;
|
// boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
||||||
this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
|
// if (hasRaceId(raceIds)) {
|
||||||
this.rotationalGoal = rotation;
|
// this.pixelVelocityX = (newXValue - boatPoly.getLayoutX()) / expectedUpdateInterval;
|
||||||
calculateRotationalVelocity();
|
// this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
|
||||||
rotateTo(rotation);
|
// this.rotationalGoal = rotation;
|
||||||
if (wakeGenerationDelay > 0) {
|
// calculateRotationalVelocity();
|
||||||
wake.rotate(rotationalGoal);
|
// rotateTo(rotation);
|
||||||
wakeGenerationDelay--;
|
// if (wakeGenerationDelay > 0) {
|
||||||
} else {
|
// wake.rotate(rotationalGoal);
|
||||||
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, pixelVelocityX, pixelVelocityY);
|
// wakeGenerationDelay--;
|
||||||
}
|
// } else {
|
||||||
}
|
// wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, pixelVelocityX, pixelVelocityY);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double newXValue, double newYValue, int... raceIDs) {
|
public void setDestination (double newXValue, double newYValue, int... raceIDs) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ 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.parsers.packets.BoatPositionPacket;
|
||||||
|
import seng302.models.parsers.packets.StreamPacket;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@@ -12,12 +14,11 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The purpose of this class is to take in the stream of divided packets so they can be read
|
* The purpose of this class is to take in the stream of divided packets so they can be read
|
||||||
@@ -27,14 +28,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class StreamParser extends Thread{
|
public class StreamParser extends Thread{
|
||||||
|
|
||||||
public static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
|
||||||
public 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public StreamParser(String threadName){
|
public StreamParser(String threadName){
|
||||||
this.threadName = threadName;
|
this.threadName = threadName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,28 +317,31 @@ 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 timeValid = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
|
||||||
// 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 rawLat = bytesToLong(latBytes);
|
||||||
long lon = bytesToLong(lonBytes);
|
long rawLon = bytesToLong(lonBytes);
|
||||||
|
double lat = ((180d * (double)rawLat)/Math.pow(2,31));
|
||||||
|
double lon = ((180d *(double)rawLon)/Math.pow(2,31));
|
||||||
long heading = bytesToLong(headingBytes);
|
long heading = bytesToLong(headingBytes);
|
||||||
// long speed = extractTimeStamp(speedBytes, 2);
|
// long speed = extractTimeStamp(speedBytes, 2);
|
||||||
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 == 4){
|
if ((int)deviceType == 1){
|
||||||
// System.out.println("boatId = " + boatId);
|
|
||||||
// System.out.println("deviceType = " + (long)deviceType);
|
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
|
||||||
// System.out.println("seq = " + seq);
|
|
||||||
//needs to be validated
|
if (!boatPositions.containsKey(boatId)){
|
||||||
Point3D point = new Point3D(((180d * (double)lat)/Math.pow(2,31)),((180d *(double)lon)/Math.pow(2,31)),(double)heading);
|
boatPositions.put(boatId, new PriorityBlockingQueue<BoatPositionPacket>(256, new Comparator<BoatPositionPacket>() {
|
||||||
boatPositions.put(boatId, point);
|
@Override
|
||||||
boatSpeeds.put(boatId, groundSpeed);
|
public int compare(BoatPositionPacket p1, BoatPositionPacket p2) {
|
||||||
// boatPositions.replace(boatId, point);
|
return (int) (p1.getTimeValid() - p2.getTimeValid());
|
||||||
// boatSpeeds.replace(boatId, groundSpeed);
|
}
|
||||||
// System.out.println("lon = " + ((180d * (double)lon)/Math.pow(2,31)));
|
}));
|
||||||
// System.out.println("lat = " + ((180d *(double)lat)/Math.pow(2,31)));
|
}
|
||||||
|
boatPositions.get(boatId).put(boatPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models.parsers;
|
package seng302.models.parsers;
|
||||||
|
|
||||||
|
import seng302.models.parsers.packets.StreamPacket;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package seng302.models.parsers.packets;
|
||||||
|
|
||||||
|
public class BoatPositionPacket {
|
||||||
|
private long boatId;
|
||||||
|
private long timeValid;
|
||||||
|
private double lat;
|
||||||
|
private double lon;
|
||||||
|
private double heading;
|
||||||
|
private double groundSpeed;
|
||||||
|
|
||||||
|
public BoatPositionPacket(long boatId, long timeValid, double lat, double lon, double heading, double groundSpeed) {
|
||||||
|
this.boatId = boatId;
|
||||||
|
this.timeValid = timeValid;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.heading = heading;
|
||||||
|
this.groundSpeed = groundSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimeValid() {
|
||||||
|
return timeValid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package seng302.models.parsers.packets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package seng302.models.parsers.packets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMessageLength() {
|
||||||
|
return messageLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPayload() {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimeStamp() {
|
||||||
|
return timeStamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user