From 71e14259f6bae7bd335e7307f435cc56a5b07b71 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Mon, 24 Apr 2017 16:47:41 +1200 Subject: [PATCH] Started looking into boat location packets, am able to extract the lats an lons but needs validations. Can also see the device type, timestamp, and sequence number. Code needs to be cleaned up and will need to start looking into the set up packets, specifically the packets containing xml data so the course can be created. #story[820] --- .../seng302/models/parsers/StreamPacket.java | 1 - .../seng302/models/parsers/StreamParser.java | 50 +++++++++++++------ .../models/parsers/StreamReceiver.java | 3 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/seng302/models/parsers/StreamPacket.java b/src/main/java/seng302/models/parsers/StreamPacket.java index b1e24a68..4afd51f5 100644 --- a/src/main/java/seng302/models/parsers/StreamPacket.java +++ b/src/main/java/seng302/models/parsers/StreamPacket.java @@ -19,7 +19,6 @@ public class StreamPacket { this.payload = payload; // System.out.println("type = " + type); if (this.type == PacketType.BOAT_LOCATION){ - System.out.println(this.type.toString()); StreamParser.extractBoatLocation(payload); } } diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index 65598693..44321c9a 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -9,7 +9,10 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Map; /** * Created by kre39 on 23/04/17. @@ -17,7 +20,7 @@ import java.util.Arrays; public class StreamParser { private static boolean isWithinTag; - + public static ArrayList ids = new ArrayList<>(); static void parseLine(byte[] bytes) { //TODO overhaul all of this to treat packets as appropriate @@ -43,26 +46,41 @@ public class StreamParser { } static void extractBoatLocation(byte[] payload){ + byte deviceType = payload[15]; + 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); - int boatId = ByteBuffer.wrap(boatIdBytes).getInt(); - int lat = ByteBuffer.wrap(latBytes).getInt(); - int lon = ByteBuffer.wrap(lonBytes).getInt(); -// System.out.println("boatId = " + boatId); -// System.out.println("lon = " + 180 * (lon/Math.pow(2,31))); -// System.out.println("lat = " + 180 * (lat/Math.pow(2,31))); - } - - public static int toInt(byte[] bytes, int offset) { - - int ret = 0; - for (int i=0; i<4 && i+offset