|
|
|
@ -43,36 +43,30 @@ public class BinaryMessageDecoder {
|
|
|
|
this.crc = Arrays.copyOfRange(this.fullMessage, this.fullMessage.length - 4, fullMessage.length);
|
|
|
|
this.crc = Arrays.copyOfRange(this.fullMessage, this.fullMessage.length - 4, fullMessage.length);
|
|
|
|
|
|
|
|
|
|
|
|
//run through the checks
|
|
|
|
//run through the checks
|
|
|
|
if (this.message.length != bytesToInt(this.headerMessageLength)){
|
|
|
|
if (this.message.length != bytesToShort(this.headerMessageLength)){
|
|
|
|
System.err.println("message length in header does not equal the message length");
|
|
|
|
System.err.println("message length in header does not equal the message length");
|
|
|
|
System.err.println("message length in header: " + bytesToInt(this.headerMessageLength));
|
|
|
|
System.err.println("message length in header: " + bytesToInt(this.headerMessageLength));
|
|
|
|
System.err.println("message length: " + this.message.length);
|
|
|
|
System.err.println("message length: " + this.message.length);
|
|
|
|
}else if(this.headerSync1 != 0x47){
|
|
|
|
}else if(this.headerSync1 != 0x47){
|
|
|
|
System.err.println("Sync byte 1 is wrong");
|
|
|
|
System.err.println("Sync byte 1 is wrong");
|
|
|
|
}else if(this.headerSync2 != 0x83){
|
|
|
|
}else if(this.headerSync2 !=(byte) 0x83){
|
|
|
|
System.err.println("Sync byte 2 is wrong");
|
|
|
|
System.err.println("Sync byte 2 is wrong");
|
|
|
|
}else if(false){
|
|
|
|
}else if(false){
|
|
|
|
//todo check crc
|
|
|
|
//todo check crc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private short bytesToShort(byte[] bytesShort){
|
|
|
|
private short bytesToShort(byte[] bytesShort){
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.allocate(2);
|
|
|
|
ByteBuffer wrapped = ByteBuffer.wrap(bytesShort);
|
|
|
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
short num = wrapped.getShort();
|
|
|
|
byteBuffer.put(bytesShort[0]);
|
|
|
|
return num;
|
|
|
|
byteBuffer.put(bytesShort[1]);
|
|
|
|
|
|
|
|
short shortVal = byteBuffer.getShort(0);
|
|
|
|
|
|
|
|
return shortVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int bytesToInt(byte[] bytesInt){
|
|
|
|
private int bytesToInt(byte[] bytesInt){
|
|
|
|
ByteBuffer byteBuffer = ByteBuffer.allocate(4);
|
|
|
|
ByteBuffer wrapped = ByteBuffer.wrap(bytesInt);
|
|
|
|
byteBuffer.order(ByteOrder.BIG_ENDIAN);
|
|
|
|
int num = wrapped.getInt();
|
|
|
|
for(int i= 0; i<bytesInt.length;i++){
|
|
|
|
return num;
|
|
|
|
byteBuffer.put(bytesInt[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int intVal = byteBuffer.getShort(0);
|
|
|
|
|
|
|
|
return intVal;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private long bytesToLong(byte[] bytesLong){
|
|
|
|
private long bytesToLong(byte[] bytesLong){
|
|
|
|
@ -90,4 +84,24 @@ public class BinaryMessageDecoder {
|
|
|
|
return longVal;
|
|
|
|
return longVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public long getTimeStamp() {
|
|
|
|
|
|
|
|
return bytesToLong(this.headerTimeStamp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getSourceID() {
|
|
|
|
|
|
|
|
return bytesToInt(this.headerSourceID);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public short getMessageLength() {
|
|
|
|
|
|
|
|
return bytesToShort(this.headerMessageLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getMessageType(){
|
|
|
|
|
|
|
|
return (int) this.headerMessageType;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] getMessage() {
|
|
|
|
|
|
|
|
return message;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|