Skip to content

Commit

Permalink
Restore DSMR-reader fix for CRC hex in favor of developing
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Feb 1, 2023
1 parent cc0db7f commit 0d1a971
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dsmr_parser/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ def validate_checksum(telegram):

calculated_crc = TelegramParser.crc16(checksum_contents.group(0))
expected_crc = int(checksum_hex.group(0), base=16)
# @TODO DSMR-reader additions. Should eventually be pushed upstream.
calculated_crc_hex = "{:0>4}".format(hex(calculated_crc)[2:].upper())
expected_crc_hex = "{:0>4}".format(hex(expected_crc)[2:].upper())

if calculated_crc != expected_crc:
raise InvalidChecksumError(
"Invalid telegram. The CRC checksum '{}' does not match the "
"expected '{}'".format(calculated_crc, expected_crc)
"Invalid telegram CRC. The calculated checksum '{}' ({}) does not match the "
"telegram checksum '{}' ({})".format(
calculated_crc, calculated_crc_hex, expected_crc, expected_crc_hex
)
)

@staticmethod
Expand Down

0 comments on commit 0d1a971

Please sign in to comment.