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]
This commit is contained in:
Kusal Ekanayake
2017-04-24 16:47:41 +12:00
parent 403dc480c4
commit 71e14259f6
3 changed files with 35 additions and 19 deletions
@@ -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);
}
}
@@ -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<Long> 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)));
extractTimeStamp(Arrays.copyOfRange(payload,1,7));
// int boatSeq = ByteBuffer.wrap(seqBytes).getInt();
long seq = StreamReceiver.bytesToLong(seqBytes);
long boatId = StreamReceiver.bytesToLong(boatIdBytes);
long lat = StreamReceiver.bytesToLong(latBytes);
long lon = StreamReceiver.bytesToLong(lonBytes);
if (!ids.contains(boatId)) {
ids.add(boatId);
}
if (boatId != 0){
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)));
}
public static int toInt(byte[] bytes, int offset) {
}
int ret = 0;
for (int i=0; i<4 && i+offset<bytes.length; i++) {
ret <<= 8;
ret |= (int)bytes[i] & 0xFF;
private static void extractTimeStamp(byte[] timeStampBytes){
long timeStamp = 0;
long multiplier=1;
for(int i = 0;i < 6;i++) {
timeStamp += timeStampBytes[i]*multiplier;
multiplier *= 256;
}
return ret;
System.out.println("timeStamp = " + timeStamp);
}
}
@@ -103,7 +103,6 @@ public class StreamReceiver {
e.printStackTrace();
}
}
private static byte[] getBytes(int n){
@@ -124,7 +123,7 @@ public class StreamReceiver {
*
* @return a positive long if there is less than 4 bytes -1 otherwise
*/
private static long bytesToLong(byte[] bytes){
static long bytesToLong(byte[] bytes){
long partialLong = 0;
int index = 0;
for (byte b: bytes){