ecom.checksum

Module Contents

Classes

ChecksumVerifier

A checksum verifier that can add and verify a CRC16 checksum.

Functions

calculateChecksum(→ int)

Calculate a CRC16 checksum from the data.

ecom.checksum.calculateChecksum(data: bytes, polynomial: int = 34833) int[source]

Calculate a CRC16 checksum from the data.

Parameters:
  • data – The data to calculate the checksum from.

  • polynomial – The polynomial to use for the crc calculation in nominal form.

Returns:

The calculated checksum.

class ecom.checksum.ChecksumVerifier(database: ecom.database.CommunicationDatabase, checksumDatapointName='checksum')[source]

Bases: ecom.verification.MessageVerifier

A checksum verifier that can add and verify a CRC16 checksum.

verify(data: bytes, message: ecom.message.MessageType, header: ecom.datatypes.TypeInfo[ecom.datatypes.StructType], messageSize: int)[source]

Verify the integrity of the message.

Raises:

VerificationError – if the message fails the verification check and the original data can’t be recovered.

Parameters:
  • data – The raw data of the message. May also include other trailing data.

  • message – The type of message.

  • header – The header type information of the message.

  • messageSize – The size of the message, as calculated with the unverified data.

Returns:

None if the message was verified successfully or the bytes of the error corrected message and any bytes from the given data that were not part of the message.

addVerificationData(data: bytes, message: ecom.message.MessageType, header: ecom.datatypes.TypeInfo[ecom.datatypes.StructType]) bytes[source]

Add extra verification data to a message.

Parameters:
  • data – The message data.

  • message – The type of message.

  • header – The header type information of the message.

Returns:

The message with verification data.

addPlaceholderVerificationData(data: Dict[str, Any])[source]

When constructing a message, this allows to add a placeholder value to the header that will be filled later by addVerificationData.

Parameters:

data – A dictionary to store the placeholder verification data to.