StreamingDecoder: - CRC calculation for MagFlux protocol "l" identical to Genesis protocol "h" and "f"

This commit is contained in:
Thomas Wiedebusch
2023-03-20 13:19:56 +01:00
parent 8a1b3d84d7
commit 8aee7994f5
@@ -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
//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
//dec_AT_l, 29200671, 149.7219849, 6.487714767, 0, 4.59406E+25, 0, 22627
//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 (0x5863)
//DN50
//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
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++)
{
rawRecordForCrc += rawMsgFields[x];
// add the field delimiter from raw data
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 byteArray = new Byte[byteArraySize];
for (var i = 0; i < byteArraySize; i++)
@@ -190,14 +191,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol
byteArray[i] = (Byte)rawRecordForCrc[i];
}
var calculatedCrc = rawMsgFields[0] == "@l" ? // for MagFlux protocol "l" (small L)
Crc16Ccitt.ModbusRtuLsbA001(byteArray) :
Crc16Ccitt.CalculateMsb1021(byteArray);
// calculate the CRC from the received data
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(byteArray);
//extract received CRC
// extract received CRC
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;
switch (rawMsgFields[0])