update byte to int methods in decoders
#story[778]
This commit is contained in:
@@ -6,6 +6,8 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static seng302.Networking.Utils.ByteConverter.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 21/04/17.
|
* Created by hba56 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -63,55 +65,16 @@ public class BoatLocationDecoder {
|
|||||||
bytesToInt(sourceID), bytesToInt(seqNum),
|
bytesToInt(sourceID), bytesToInt(seqNum),
|
||||||
deviceType, bytesToInt(latitude),
|
deviceType, bytesToInt(latitude),
|
||||||
bytesToInt(longitude), bytesToInt(altitude),
|
bytesToInt(longitude), bytesToInt(altitude),
|
||||||
twoByteToInt(heading), bytesToShort(pitch),
|
bytesToInt(heading), bytesToShort(pitch),
|
||||||
bytesToShort(roll), twoByteToInt(boatSpeed),
|
bytesToShort(roll), bytesToInt(boatSpeed),
|
||||||
twoByteToInt(cog), twoByteToInt(sog),
|
bytesToInt(cog), bytesToInt(sog),
|
||||||
twoByteToInt(apparentWindSpeed), bytesToShort(apparentWindAngle),
|
bytesToInt(apparentWindSpeed), bytesToShort(apparentWindAngle),
|
||||||
twoByteToInt(trueWindSpeed), bytesToShort(trueWindDirection),
|
bytesToInt(trueWindSpeed), bytesToShort(trueWindDirection),
|
||||||
bytesToShort(trueWindAngle), twoByteToInt(currentDrift),
|
bytesToShort(trueWindAngle), bytesToInt(currentDrift),
|
||||||
twoByteToInt(currentSet), bytesToShort(rudderAngle)
|
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() {
|
public BoatLocationMessage getMessage() {
|
||||||
return message;
|
return message;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static seng302.Networking.Utils.ByteConverter.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 23/04/17.
|
* Created by hba56 on 23/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -38,48 +40,15 @@ public class CourseWindDecoder {
|
|||||||
byte[] flags = Arrays.copyOfRange(messageBytes, 19, 20);
|
byte[] flags = Arrays.copyOfRange(messageBytes, 19, 20);
|
||||||
|
|
||||||
CourseWind message = new CourseWind(windId[0], bytesToLong(time),
|
CourseWind message = new CourseWind(windId[0], bytesToLong(time),
|
||||||
bytesToInt(raceID), twoByteToInt(windDirection),
|
bytesToInt(raceID), bytesToInt(windDirection),
|
||||||
twoByteToInt(windSpeed), twoByteToInt(bestUpwindAngle),
|
bytesToInt(windSpeed), bytesToInt(bestUpwindAngle),
|
||||||
twoByteToInt(bestDownwindAngle), flags[0]);
|
bytesToInt(bestDownwindAngle), flags[0]);
|
||||||
|
|
||||||
loopMessages.add(message);
|
loopMessages.add(message);
|
||||||
messageLoopIndex += 20;
|
messageLoopIndex += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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[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 ArrayList<CourseWind> getLoopMessages() {
|
public ArrayList<CourseWind> getLoopMessages() {
|
||||||
return loopMessages;
|
return loopMessages;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static seng302.Networking.Utils.ByteConverter.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 21/04/17.
|
* Created by hba56 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -37,44 +39,9 @@ public class RaceStartStatusDecoder {
|
|||||||
ack = bytesToShort(ackNumber);
|
ack = bytesToShort(ackNumber);
|
||||||
startTime = bytesToLong(raceStartTime);
|
startTime = bytesToLong(raceStartTime);
|
||||||
raceID = bytesToInt(raceIdentifier);
|
raceID = bytesToInt(raceIdentifier);
|
||||||
notification = byteToChar(notificationType);
|
notification = bytesToChar(notificationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private char byteToChar(byte bytesInt){
|
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
|
|
||||||
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
||||||
byteBuffer.put((byte)0);
|
|
||||||
byteBuffer.put(bytesInt);
|
|
||||||
char num = byteBuffer.getChar(0);
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
private short bytesToShort(byte[] bytesShort){
|
|
||||||
ByteBuffer wrapped = ByteBuffer.wrap(bytesShort);
|
|
||||||
short num = wrapped.getShort();
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int bytesToInt(byte[] bytesInt){
|
|
||||||
ByteBuffer wrapped = ByteBuffer.wrap(bytesInt);
|
|
||||||
int num = wrapped.getInt();
|
|
||||||
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[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 byte getMessageVersion() {
|
public byte getMessageVersion() {
|
||||||
return messageVersion;
|
return messageVersion;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static seng302.Networking.Utils.ByteConverter.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 21/04/17.
|
* Created by hba56 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -47,11 +49,11 @@ public class RaceStatusDecoder {
|
|||||||
|
|
||||||
time = bytesToLong(timeBytes);
|
time = bytesToLong(timeBytes);
|
||||||
race = bytesToInt(raceID);
|
race = bytesToInt(raceID);
|
||||||
raceState = byteToInt(raceStatus);
|
raceState = bytesToInt(raceStatus);
|
||||||
startTime = bytesToLong(expectedStart);
|
startTime = bytesToLong(expectedStart);
|
||||||
raceWindDir = bytesToShort(raceWind);
|
raceWindDir = bytesToShort(raceWind);
|
||||||
raceWindSpeed = bytesToShort(windSpeed);
|
raceWindSpeed = bytesToShort(windSpeed);
|
||||||
numberOfBoats = byteToInt(numBoats);
|
numberOfBoats = bytesToInt(numBoats);
|
||||||
|
|
||||||
int boatLoopIndex = 0;
|
int boatLoopIndex = 0;
|
||||||
|
|
||||||
@@ -75,39 +77,6 @@ public class RaceStatusDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int byteToInt(byte bytesInt){
|
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
|
|
||||||
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
||||||
byteBuffer.put((byte)0);
|
|
||||||
byteBuffer.put((byte)0);
|
|
||||||
byteBuffer.put((byte)0);
|
|
||||||
byteBuffer.put(bytesInt);
|
|
||||||
int intVal = byteBuffer.getInt(0);
|
|
||||||
return intVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
private short bytesToShort(byte[] bytesShort){
|
|
||||||
ByteBuffer wrapped = ByteBuffer.wrap(bytesShort);
|
|
||||||
short num = wrapped.getShort();
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int bytesToInt(byte[] bytesInt){
|
|
||||||
ByteBuffer wrapped = ByteBuffer.wrap(bytesInt);
|
|
||||||
int num = wrapped.getInt();
|
|
||||||
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);
|
|
||||||
long longVal = byteBuffer.getLong(0);
|
|
||||||
return longVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getVersionNum() {
|
public byte getVersionNum() {
|
||||||
return versionNum;
|
return versionNum;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static seng302.Networking.Utils.ByteConverter.bytesToLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 20/04/17.
|
* Created by hba56 on 20/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -52,29 +54,6 @@ public class XMLMessageDecoder {
|
|||||||
return shortVal;
|
return shortVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
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[0]);
|
|
||||||
byteBuffer.put(bytesLong[1]);
|
|
||||||
byteBuffer.put(bytesLong[2]);
|
|
||||||
byteBuffer.put(bytesLong[3]);
|
|
||||||
byteBuffer.put(bytesLong[4]);
|
|
||||||
byteBuffer.put(bytesLong[5]);
|
|
||||||
|
|
||||||
// System.out.println("====decode====");
|
|
||||||
// for (byte i:byteBuffer.array()
|
|
||||||
// ) {
|
|
||||||
// System.out.println(i);
|
|
||||||
// }
|
|
||||||
// System.out.println("====decode====");
|
|
||||||
|
|
||||||
long longVal = byteBuffer.getLong(0);
|
|
||||||
return longVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getMessageVersionNumber() {
|
public byte getMessageVersionNumber() {
|
||||||
return messageVersionNumber;
|
return messageVersionNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user