Added CRC
- CRC checking now works #story[782]
This commit is contained in:
@@ -49,11 +49,13 @@ public class BinaryMessageDecoder {
|
||||
|
||||
//get crc
|
||||
this.crc = Arrays.copyOfRange(this.fullMessage, this.fullMessage.length - 4, fullMessage.length);
|
||||
|
||||
ByteBuffer bytes = ByteBuffer.allocate(this.header.length + this.message.length);
|
||||
bytes.put(this.header);
|
||||
bytes.put(this.message);
|
||||
|
||||
CRC32 crc = new CRC32();
|
||||
crc.reset();
|
||||
crc.update(this.fullMessage);
|
||||
crc.update(bytes.array(), 0, bytes.array().length);
|
||||
|
||||
//run through the checks
|
||||
if (this.message.length != ByteConverter.bytesToShort(this.headerMessageLength)){//keep like this - hba65
|
||||
@@ -67,11 +69,11 @@ public class BinaryMessageDecoder {
|
||||
}else if(this.headerSync2 !=(byte) 0x83){
|
||||
System.err.println("Sync byte 2 is wrong: " + this.headerSync2);
|
||||
return null;
|
||||
}/*else if(crc.getValue() != 0){
|
||||
}else if(crc.getValue() != ByteConverter.bytesToLong(this.crc)){
|
||||
//todo check crc
|
||||
System.err.println("CRC is not 0 and is instead:" + crc.getValue());
|
||||
return;
|
||||
}*/
|
||||
System.err.println("CRC is not "+ByteConverter.bytesToLong(this.crc)+" and is instead:" + crc.getValue());
|
||||
return null;
|
||||
}
|
||||
|
||||
MessageType mType = MessageType.valueOf(this.headerMessageType);
|
||||
AC35Data data = null;
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
|
||||
Reference in New Issue
Block a user