Library API#

E2E Profiles#

Profile 01#

e2e.p01.e2e_p01_protect(data: bytearray, length: int, data_id: int, *, data_id_mode: int = 0, increment_counter: bool = True) None#

Calculate CRC inplace according to AUTOSAR E2E Profile 1.

Parameters:
  • data (bytearray) – Mutable bytes-like object starting with the CRC byte. This CRC byte will be updated inplace.

  • length (int) – Number of data bytes which are considered for CRC calculation. length must fulfill the following condition: 1 <= length <= len(data) - 1

  • data_id (int) – A unique identifier which is used to protect against masquerading. The data_id is a 16bit unsigned integer.

  • data_id_mode (int) – This attribute describes the inclusion mode that is used to include the data_id. The possible inclusion modes are E2E_P01_DATAID_BOTH, E2E_P01_DATAID_ALT, E2E_P01_DATAID_LOW and E2E_P01_DATAID_NIBBLE.

  • increment_counter (bool) – If True the counter in byte 1 will be incremented before calculating the CRC.

e2e.p01.e2e_p01_check(data: bytearray, length: int, data_id: int, *, data_id_mode: int = E2E_P01_DATAID_BOTH) bool#

Return True if CRC is correct according to AUTOSAR E2E Profile 1.

Parameters:
  • data (bytearray) –

    Mutable bytes-like object starting with the CRC byte. This CRC byte will be updated inplace.

  • length (int) – Number of data bytes which are considered for CRC calculation. length must fulfill the following condition: 1 <= length < len(data)

  • data_id (int) – A unique identifier which is used to protect against masquerading. The data_id is a 16bit unsigned integer.

  • data_id_mode (int) – This attribute describes the inclusion mode that is used to include the data_id. The possible inclusion modes are E2E_P01_DATAID_BOTH, E2E_P01_DATAID_ALT, E2E_P01_DATAID_LOW and E2E_P01_DATAID_NIBBLE.

Returns:

True if CRC is valid, otherwise return False

e2e.p01.E2E_P01_DATAID_BOTH: Final[int] = 0x00#
e2e.p01.E2E_P01_DATAID_ALT: Final[int] = 0x01#
e2e.p01.E2E_P01_DATAID_LOW: Final[int] = 0x02#
e2e.p01.E2E_P01_DATAID_NIBBLE: Final[int] = 0x03#

Profile 02#

e2e.p02.e2e_p02_protect(data: bytearray, length: int, data_id_list: bytes, *, increment_counter: bool = True) None#

Calculate CRC inplace according to AUTOSAR E2E Profile 2.

Parameters:
  • data (bytearray) –

    Mutable bytes-like object starting with the CRC byte. This CRC byte will be updated inplace.

  • length (int) – Number of data bytes which are considered for CRC calculation. length must fulfill the following condition: 1 <= length <= len(data) - 1

  • data_id_list (bytes) –

    A bytes-like object of length 16 which is used to protect against masquerading.

  • increment_counter (bool) – If True the counter in byte 1 will be incremented before calculating the CRC.

e2e.p02.e2e_p02_check(data: bytes, length: int, data_id_list: bytes) bool#

Return True if CRC is correct according to AUTOSAR E2E Profile 2.

Parameters:
  • data

    bytes-like object starting with the CRC byte.

  • length – Data byte count over which the CRC must be calculated. length must fulfill the following condition: 1 <= length <= len(data) - 1

  • data_id_list

    A bytes-like object of length 16 which is used to protect against masquerading.

Returns:

True if CRC is valid, otherwise return False

Profile 05#

e2e.p05.e2e_p05_protect(data: bytearray, length: int, data_id: int, *, offset: int = 0, increment_counter: bool = True) None#

Calculate CRC inplace according to AUTOSAR E2E Profile 5.

Parameters:
  • data (bytearray) –

    Mutable bytes-like object.

  • length (int) – Number of data bytes which are considered for CRC calculation. length must fulfill the following condition: 1 <= length <= len(data) - 2

  • data_id (int) – A unique identifier which is used to protect against masquerading. The data_id is a 16bit unsigned integer.

  • offset (int) – Byte offset of the E2E header.

  • increment_counter (bool) – If True the counter will be incremented before calculating the CRC.

e2e.p05.e2e_p05_check(data: bytes, length: int, data_id: int, *, offset: int = 0) bool#

Return True if CRC is correct according to AUTOSAR E2E Profile 5.

Parameters:
  • data

    bytes-like object.

  • length – Data byte count over which the CRC must be calculated. length must fulfill the following condition: 1 <= length <= len(data) - 2

  • data_id (int) – A unique identifier which is used to protect against masquerading. The data_id is a 16bit unsigned integer.

  • offset (int) – Byte offset of the E2E header.

Returns:

True if CRC is valid, otherwise return False

CRC Functions#

8-bit SAE J1850 CRC Calculation#

e2e.crc.calculate_crc8(data: bytes, start_value: int = 0xFF, first_call: bool = True) int#

8-bit SAE J1850 CRC Calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC8_INITIAL_VALUE: Final[int] = 0xFF#
e2e.crc.CRC8_XOR_VALUE: Final[int] = 0xFF#
e2e.crc.CRC8_CHECK: Final[int] = 0x4B#
e2e.crc.CRC8_MAGIC_CHECK: Final[int] = 0xC4#

8-bit 0x2F polynomial CRC Calculation#

e2e.crc.calculate_crc8_h2f(data: bytes, start_value: int = 0xFF, first_call: bool = True) int#

8-bit 0x2F polynomial CRC Calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC8H2F_INITIAL_VALUE: Final[int] = 0xFF#
e2e.crc.CRC8H2F_XOR_VALUE: Final[int] = 0xFF#
e2e.crc.CRC8H2F_CHECK: Final[int] = 0xDF#
e2e.crc.CRC8H2F_MAGIC_CHECK: Final[int] = 0x42#

16-bit CCITT-FALSE CRC16#

e2e.crc.calculate_crc16(data: bytes, start_value: int = 0xFFFF, first_call: bool = True) int#

16-bit CCITT-FALSE CRC16

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC16_INITIAL_VALUE: Final[int] = 0xFFFF#
e2e.crc.CRC16_XOR_VALUE: Final[int] = 0x0000#
e2e.crc.CRC16_CHECK: Final[int] = 0x29B1#
e2e.crc.CRC16_MAGIC_CHECK: Final[int] = 0x0000#

16-bit 0x8005 polynomial CRC calculation#

e2e.crc.calculate_crc16_arc(data: bytes, start_value: int = 0x0000, first_call: bool = True) int#

16-bit 0x8005 polynomial CRC calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC16ARC_INITIAL_VALUE: Final[int] = 0x0000#
e2e.crc.CRC16ARC_XOR_VALUE: Final[int] = 0x0000#
e2e.crc.CRC16ARC_CHECK: Final[int] = 0xBB3D#
e2e.crc.CRC16ARC_MAGIC_CHECK: Final[int] = 0x0000#

32-bit Ethernet CRC Calculation#

e2e.crc.calculate_crc32(data: bytes, start_value: int = 0xFFFFFFFF, first_call: bool = True) int#

32-bit Ethernet CRC Calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC32_INITIAL_VALUE: Final[int] = 0xFFFFFFFF#
e2e.crc.CRC32_XOR_VALUE: Final[int] = 0xFFFFFFFF#
e2e.crc.CRC32_CHECK: Final[int] = 0xCBF43926#
e2e.crc.CRC32_MAGIC_CHECK: Final[int] = 0xDEBB20E3#

32-bit 0xF4ACFB13 polynomial CRC calculation#

e2e.crc.calculate_crc32_p4(data: bytes, start_value: int = 0xFFFFFFFF, first_call: bool = True) int#

32-bit 0xF4ACFB13 polynomial CRC calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC32P4_INITIAL_VALUE: Final[int] = 0xFFFFFFFF#
e2e.crc.CRC32P4_XOR_VALUE: Final[int] = 0xFFFFFFFF#
e2e.crc.CRC32P4_CHECK: Final[int] = 0x1697D06A#
e2e.crc.CRC32P4_MAGIC_CHECK: Final[int] = 0x904CDDBF#

64-bit 0x42F0E1EBA9EA3693 polynomial CRC calculation#

e2e.crc.calculate_crc64(data: bytes, start_value: int = 0xFFFFFFFFFFFFFFFF, first_call: bool = True) int#

64-bit 0x42F0E1EBA9EA3693 polynomial CRC calculation

Parameters:
  • data (bytes) –

    bytes-like object which contains the data for CRC calculation

  • start_value (int) – First CRC of the algorithm (ignored when first_call is True). In a sequence, this is expected to be the return value of the previous function call.

  • first_call (bool) – True if this is the first call of a sequence or an individual function call. False if this is a subsequent call in a sequence.

Returns:

CRC value

e2e.crc.CRC64_INITIAL_VALUE: Final[int] = 0xFFFFFFFFFFFFFFFF#
e2e.crc.CRC64_XOR_VALUE: Final[int] = 0xFFFFFFFFFFFFFFFF#
e2e.crc.CRC64_CHECK: Final[int] = 0x995DC9BBDF1939FA#
e2e.crc.CRC64_MAGIC_CHECK: Final[int] = 0x49958C9ABD7D353F#