Skip to content

Commit

Permalink
Fix SAE-J1850 Configuration
Browse files Browse the repository at this point in the history
Update the SAE-J1850 configuration to align with the specification.
Additionally, introduce a configuration named SAE-J1850_ZERO as a replacement
for users who might rely on the previously misconfigured SAE-J1850 configuration.
  • Loading branch information
Nicoretti committed Dec 2, 2023
1 parent e8ba719 commit 5242af5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/docs/changelog/unreleased.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Unreleased

## 🐞 Bug Fix
* Adjusted the SAE-J1850 configuration to match the specification

🚨️ For users which do rely on the previously misconfigured `SAEJ1850` settings a configuration named `SAE_J1850_ZERO` was added.

## Breaking Changes
* Remove Python 3.7 support

## 🔩 Internal / Development
* Add `python 3.12` to test matrix
* Re-lock dev dependencies

13 changes: 11 additions & 2 deletions src/crc/_crc.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class Configuration:
saej1850 = Configuration(
width=8,
polynomial=0x1D,
init_value=0,
final_xor_value=0,
init_value=0xFF,
final_xor_value=0xFF,
reverse_input=False,
reverse_output=False
)
Expand Down Expand Up @@ -435,6 +435,15 @@ class Crc8(enum.Enum):
)

SAEJ1850 = Configuration(
width=8,
polynomial=0x1D,
init_value=0xFF,
final_xor_value=0xFF,
reverse_input=False,
reverse_output=False,
)

SAEJ1850_ZERO = Configuration(
width=8,
polynomial=0x1D,
init_value=0x00,
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test_crc.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ def test_crc8_ccitt(self):

def test_crc8_saej1850(self):
config = Crc8.SAEJ1850
for register_type in self._register_types:
crc_register = register_type(config)
test_suit = [
Fixture(data="", checksum=0x00),
Fixture(data=string.digits[1:], checksum=0x4B),
Fixture(data=string.digits[1:][::-1], checksum=0xD6),
Fixture(data=string.digits, checksum=0x74),
Fixture(data=string.digits[::-1], checksum=0xC7),
]
for test in test_suit:
crc_register.init()
crc_register.update(test.data.encode("utf-8"))
self.assertEqual(test.checksum, crc_register.digest())

def test_crc8_saej1850_zero(self):
config = Crc8.SAEJ1850_ZERO
for register_type in self._register_types:
crc_register = register_type(config)
test_suit = [
Expand Down

0 comments on commit 5242af5

Please sign in to comment.