privatestaticfinalintCRCLength=4;//TODO these should probably be static defined somewhere else to be shared.
/**
*LengthoftheCRC.
*/
privatestaticfinalintCRCLength=4;
///The value the first sync byte should have.
/**
*Thevaluethefirstsyncbyteshouldhave.
*/
privatestaticfinalbytesyncByte1=(byte)0x47;
//The value the second sync byte should have.
/**
*Thevaluethesecondsyncbyteshouldhave.
*/
privatestaticfinalbytesyncByte2=(byte)0x83;
///The full message.
/**
*Thefullmessage.
*/
privatebyte[]fullMessage;
///The messageHeader.
/**
*ThemessageHeader.
*/
privatebyte[]messageHeader;
///The messageBody.
/**
*ThemessageBody.
*/
privatebyte[]messageBody;
///The sync bytes from the header..
/**
*Thesyncbytesfromtheheader.
*/
privatebyteheaderSync1;
privatebyteheaderSync2;
///The message type from the header.
/**
*Themessagetypefromtheheader.
*/
privatebyteheaderMessageType;
///The timestamp from the header.
/**
*Thetimestampfromtheheader.
*/
privatelongheaderTimeStamp;
///The source ID from the header.
/**
*ThesourceIDfromtheheader.
*/
privateintheaderSourceID;
///The message body length from the header.
/**
*Themessagebodylengthfromtheheader.
*/
privateintmessageBodyLength;
///CRC value read from message header.
/**
*CRCvaluereadfrommessageheader.
*/
privatelongmessageCRCValue;
///Calculated CRC value from message.
/**
*CalculatedCRCvaluefrommessage.
*/
privatelongcalculatedCRCValue;
@ -114,105 +143,35 @@ public class BinaryMessageDecoder {
//Check the message body length.
thrownewInvalidMessageException("MessageBody length in header does not equal the messageBody length. MessageBody length in header is: "+messageBodyLength+", should be: "+messageBody.length);
}elseif(headerSync1!=syncByte1){
}elseif(headerSync1!=syncByte1){
//Check the first sync byte.
thrownewInvalidMessageException("Sync byte 1 is wrong. Sync byte is: "+headerSync1+", should be: "+syncByte1);
}elseif(headerSync2!=syncByte2){
}elseif(headerSync2!=syncByte2){
//Check the second sync byte.
thrownewInvalidMessageException("Sync byte 2 is wrong. Sync byte is: "+headerSync2+", should be: "+syncByte2);
}elseif(calculatedCRCValue!=messageCRCValue){
}elseif(calculatedCRCValue!=messageCRCValue){
//Check the CRC value.
thrownewInvalidMessageException("CRC value is wrong. The calculated value is: "+calculatedCRCValue+", should be: "+messageCRCValue);
}
//Now we create the message object based on what is actually in the message body.