Started merging received packets from the sample stream and reading lats and lons to move boats from them.

#story[820]
This commit is contained in:
Kusal Ekanayake
2017-04-26 15:51:15 +12:00
parent a3ae015be8
commit c73bf7dd3e
7 changed files with 29 additions and 11 deletions
@@ -159,6 +159,8 @@ public class CanvasController {
leftToRight = nextMark.getX() < boatGroup.getLayoutX();
boatGroup.updatePosition(1000 / 60);
// Point2D p = latLonToXY(lat, lon);
// boatGroup.setDestination(p.getX(), p.getY());
if (descending && nextMark.getY() < boatGroup.getLayoutY()) {
currentRaceMarker[boatIndex]++;
boatGroup.setDestination(
+3 -1
View File
@@ -12,6 +12,7 @@ import javafx.scene.transform.Translate;
* Created by CJIRWIN on 25/04/2017.
*/
public class BoatGroup extends Group{
private static final double TEAMNAME_X_OFFSET = 15d;
private static final double TEAMNAME_Y_OFFSET = -20d;
private static final double VELOCITY_X_OFFSET = 15d;
@@ -98,7 +99,8 @@ public class BoatGroup extends Group{
* @param y The Y coordinate to move the boat to
*/
public void moveBoatTo(Double x, Double y, Double rotation) {
super.relocate(x, y);
super.setLayoutX(x);
super.setLayoutY(y);
currentRotation = 0;
rotateBoat(rotation);
}
@@ -17,9 +17,11 @@ public class StreamPacket {
this.messageLength = messageLength;
this.timeStamp = timeStamp;
this.payload = payload;
// System.out.println("type = " + type);
// 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.AVG_WIND){
if (this.type == PacketType.XML_MESSAGE){
System.out.println("--------");
System.out.println(new String(payload));
StreamParser.parsePacket(this);
}
}
@@ -19,6 +19,7 @@ import java.util.Arrays;
*/
public class StreamParser {
private static ArrayList<Long> boat_IDS = new ArrayList<>();
static void parsePacket(StreamPacket packet) {
switch (packet.getType()){
case HEARTBEAT:
@@ -189,7 +190,7 @@ public class StreamParser {
byte[] seqBytes = Arrays.copyOfRange(payload,11,15);
byte[] latBytes = Arrays.copyOfRange(payload,16,20);
byte[] lonBytes = Arrays.copyOfRange(payload,20,24);
byte[] boatIdBytes = Arrays.copyOfRange(payload,8,12);
byte[] boatIdBytes = Arrays.copyOfRange(payload,7,11);
long timeStamp = extractTimeStamp(Arrays.copyOfRange(payload,1,7), 6);
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
long seq = bytesToLong(seqBytes);
@@ -197,15 +198,20 @@ public class StreamParser {
long lat = bytesToLong(latBytes);
long lon = bytesToLong(lonBytes);
if (boatId != 0){
// System.out.println("boatId = " + boatId);
// System.out.println("deviceType = " + (long)deviceType);
// System.out.println("seq = " + seq);
if ((int)deviceType == 1){
if (!boat_IDS.contains(boatId)){
boat_IDS.add(boatId);
}
System.out.println("boatId = " + boatId);
System.out.println("deviceType = " + (long)deviceType);
System.out.println("seq = " + seq);
//needs to be validated
System.out.println("lon = " + ((180d * (double)lon)/Math.pow(2,31)));
System.out.println("lat = " + ((180d *(double)lat)/Math.pow(2,31)));
}
System.out.println("boat_IDS = " + boat_IDS);
System.out.println("boat_IDS = " + boat_IDS.size());
}
@@ -44,11 +44,11 @@ public class TeamsParser extends FileParser {
*/
public ArrayList<Boat> getBoats() {
ArrayList<Boat> boats = new ArrayList<>();
try {
NodeList nodes = this.doc.getElementsByTagName("team");
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
boats.add(parseBoat(node));
}
return boats;