|
|
|
|
@ -6,6 +6,8 @@ import java.nio.ByteBuffer;
|
|
|
|
|
import java.nio.ByteOrder;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
import static seng302.Networking.Utils.ByteConverter.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by hba56 on 21/04/17.
|
|
|
|
|
*/
|
|
|
|
|
@ -63,55 +65,16 @@ public class BoatLocationDecoder {
|
|
|
|
|
bytesToInt(sourceID), bytesToInt(seqNum),
|
|
|
|
|
deviceType, bytesToInt(latitude),
|
|
|
|
|
bytesToInt(longitude), bytesToInt(altitude),
|
|
|
|
|
twoByteToInt(heading), bytesToShort(pitch),
|
|
|
|
|
bytesToShort(roll), twoByteToInt(boatSpeed),
|
|
|
|
|
twoByteToInt(cog), twoByteToInt(sog),
|
|
|
|
|
twoByteToInt(apparentWindSpeed), bytesToShort(apparentWindAngle),
|
|
|
|
|
twoByteToInt(trueWindSpeed), bytesToShort(trueWindDirection),
|
|
|
|
|
bytesToShort(trueWindAngle), twoByteToInt(currentDrift),
|
|
|
|
|
twoByteToInt(currentSet), bytesToShort(rudderAngle)
|
|
|
|
|
bytesToInt(heading), bytesToShort(pitch),
|
|
|
|
|
bytesToShort(roll), bytesToInt(boatSpeed),
|
|
|
|
|
bytesToInt(cog), bytesToInt(sog),
|
|
|
|
|
bytesToInt(apparentWindSpeed), bytesToShort(apparentWindAngle),
|
|
|
|
|
bytesToInt(trueWindSpeed), bytesToShort(trueWindDirection),
|
|
|
|
|
bytesToShort(trueWindAngle), bytesToInt(currentDrift),
|
|
|
|
|
bytesToInt(currentSet), bytesToShort(rudderAngle)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int twoByteToInt(byte[] bytesInt){
|
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
|
|
|
|
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
|
byteBuffer.put((byte)0);
|
|
|
|
|
byteBuffer.put((byte)0);
|
|
|
|
|
byteBuffer.put(bytesInt);
|
|
|
|
|
int num = byteBuffer.getInt(0);
|
|
|
|
|
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int bytesToInt(byte[] bytesInt){
|
|
|
|
|
ByteBuffer wrapped = ByteBuffer.wrap(bytesInt);
|
|
|
|
|
int num = wrapped.getInt();
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private short bytesToShort(byte[] bytesShort){
|
|
|
|
|
ByteBuffer wrapped = ByteBuffer.wrap(bytesShort);
|
|
|
|
|
short num = wrapped.getShort();
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long bytesToLong(byte[] bytesLong){
|
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.allocate(8);
|
|
|
|
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
|
byteBuffer.put((byte)0);
|
|
|
|
|
byteBuffer.put((byte)0);
|
|
|
|
|
byteBuffer.put(bytesLong);
|
|
|
|
|
// byteBuffer.put(bytesLong[0]);
|
|
|
|
|
// byteBuffer.put(bytesLong[1]);
|
|
|
|
|
// byteBuffer.put(bytesLong[2]);
|
|
|
|
|
// byteBuffer.put(bytesLong[3]);
|
|
|
|
|
// byteBuffer.put(bytesLong[4]);
|
|
|
|
|
// byteBuffer.put(bytesLong[5]);
|
|
|
|
|
long longVal = byteBuffer.getLong(0);
|
|
|
|
|
return longVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BoatLocationMessage getMessage() {
|
|
|
|
|
return message;
|
|
|
|
|
|