StreamingDecoder: - CRC calculation for MagFlux protocol "l" identical to Genesis protocol "h" and "f"
This commit is contained in:
@@ -150,8 +150,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol
|
|||||||
|
|
||||||
//MagFlux test string from Jan Bennett 2023-03-14_16-16-31_fromTO.log
|
//MagFlux test string from Jan Bennett 2023-03-14_16-16-31_fromTO.log
|
||||||
//rawMsg = "@l 1bd911f 95b8d4 40cf9b5c 0 26004f5232500120373235 0 5863"
|
//rawMsg = "@l 1bd911f 95b8d4 40cf9b5c 0 26004f5232500120373235 0 5863"
|
||||||
//DUT:Debug version,DUT:Vol FWD [mL],DUT:Time [s],DUT:Flow_LPS,DUT:StatusBitsHex,DUT:UniqueId,DUT:SensorId,DUT:CRC
|
//DUT:Debug version, DUT:Vol FWD [mL], DUT:Time [s], DUT:Flow_LPS, DUT:StatusBitsHex, DUT:UniqueId, DUT:SensorId, DUT:CRC
|
||||||
//dec_AT_l, 29200671, 149.7219849, 6.487714767, 0, 4.59406E+25, 0, 22627
|
//dec_AT_l, 29200671, 149.7219849, 6.487714767, 0, 4.59406E+25, 0, 22627 (0x5863)
|
||||||
|
|
||||||
//DN50
|
//DN50
|
||||||
//2022-07-21 07:22:06.9871 | @f 8497D 062E4216 9B2A
|
//2022-07-21 07:22:06.9871 | @f 8497D 062E4216 9B2A
|
||||||
@@ -175,14 +175,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol
|
|||||||
|
|
||||||
// The last element is the CRC, the CRC can be separated, calculated and validated before trying to decode the content
|
// The last element is the CRC, the CRC can be separated, calculated and validated before trying to decode the content
|
||||||
var rawRecordForCrc = "";
|
var rawRecordForCrc = "";
|
||||||
// get all fields excluding the CRC
|
// get all fields excluding the CRC (length - 1)
|
||||||
for (var x = 0; x < rawMsgFields.Length - 1; x++)
|
for (var x = 0; x < rawMsgFields.Length - 1; x++)
|
||||||
{
|
{
|
||||||
rawRecordForCrc += rawMsgFields[x];
|
rawRecordForCrc += rawMsgFields[x];
|
||||||
// add the field delimiter from raw data
|
// add the field delimiter from raw data
|
||||||
rawRecordForCrc += " ";
|
rawRecordForCrc += " ";
|
||||||
}
|
}
|
||||||
//extract bytes of raw message for CRC calculation each character, CRC field is already removed
|
|
||||||
|
// extract bytes of raw message for CRC calculation each character, CRC field is already removed
|
||||||
var byteArraySize = rawRecordForCrc.Length;
|
var byteArraySize = rawRecordForCrc.Length;
|
||||||
var byteArray = new Byte[byteArraySize];
|
var byteArray = new Byte[byteArraySize];
|
||||||
for (var i = 0; i < byteArraySize; i++)
|
for (var i = 0; i < byteArraySize; i++)
|
||||||
@@ -190,14 +191,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol
|
|||||||
byteArray[i] = (Byte)rawRecordForCrc[i];
|
byteArray[i] = (Byte)rawRecordForCrc[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
var calculatedCrc = rawMsgFields[0] == "@l" ? // for MagFlux protocol "l" (small L)
|
// calculate the CRC from the received data
|
||||||
Crc16Ccitt.ModbusRtuLsbA001(byteArray) :
|
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(byteArray);
|
||||||
Crc16Ccitt.CalculateMsb1021(byteArray);
|
|
||||||
|
|
||||||
//extract received CRC
|
// extract received CRC
|
||||||
var receivedCrc = UInt16.Parse(rawMsgFields[rawMsgFields.Length - 1], NumberStyles.HexNumber);
|
var receivedCrc = UInt16.Parse(rawMsgFields[rawMsgFields.Length - 1], NumberStyles.HexNumber);
|
||||||
|
|
||||||
//compare received with calculated CRC and remind valid decoding
|
// compare received with calculated CRC and remind valid decoding
|
||||||
rawRecordIsValid = calculatedCrc == receivedCrc;
|
rawRecordIsValid = calculatedCrc == receivedCrc;
|
||||||
|
|
||||||
switch (rawMsgFields[0])
|
switch (rawMsgFields[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user