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
andE2E_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
andE2E_P01_DATAID_NIBBLE
.
- Returns:
True if CRC is valid, otherwise return False
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 –
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
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
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
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
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
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
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