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;
+2 -2
View File
@@ -6,8 +6,8 @@
<name type="start-line">Start</name>
<mark>
<name>Start1</name>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
<latitude>57.6703330</latitude>
<longitude>57.6703330</longitude>
</mark>
<mark>
<name>Start2</name>
+6
View File
@@ -5,30 +5,36 @@
<name>Oracle Team USA</name>
<alias>USA</alias>
<velocity>12.9</velocity>
<id>102</id>
</team>
<team>
<name>Artemis Racing</name>
<alias>ART</alias>
<velocity>13.1</velocity>
<id>101</id>
</team>
<team>
<name>Emirates Team New Zealand</name>
<alias>NZL</alias>
<velocity>15.6</velocity>
<id>103</id>
</team>
<team>
<name>Land Rover BAR</name>
<alias>BAR</alias>
<velocity>13.3</velocity>
<id>104</id>
</team>
<team>
<name>SoftBank Team Japan</name>
<alias>JAP</alias>
<velocity>14.7</velocity>
<id>105</id>
</team>
<team>
<name>Groupama Team France</name>
<alias>FRC</alias>
<velocity>11.4</velocity>
<id>106</id>
</team>
</teams>