Skip to content

Commit

Permalink
Use correct terminology.
Browse files Browse the repository at this point in the history
Rename crc to bcc in util.
  • Loading branch information
denpamusic committed Oct 20, 2023
1 parent a425a52 commit 8763bc0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyplumio/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def bytes(self) -> bytes:
data = self.header
data.append(self.frame_type)
data += self.message
data.append(util.crc(data))
data.append(util.bcc(data))
data.append(FRAME_END)
return bytes(data)

Expand Down
2 changes: 1 addition & 1 deletion pyplumio/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def read(self) -> Frame | None:
+ f"'{length - HEADER_SIZE}' bytes"
) from e

if payload[-2] != util.crc(header + payload[:-2]):
if payload[-2] != util.bcc(header + payload[:-2]):
raise ChecksumError(f"Incorrect frame checksum ({payload[-2]})")

frame = factory(
Expand Down
4 changes: 2 additions & 2 deletions pyplumio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def unpack_string(data: bytearray, offset: int = 0) -> str:
unpack_header = struct.Struct("<BH4B").unpack_from


def crc(data: bytes) -> int:
"""Return a checksum."""
def bcc(data: bytes) -> int:
"""Return a block check character."""
return functools.reduce(lambda x, y: x ^ y, data)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def test_frame_reader_with_incomplete_read(
return_value=b"\x31\xfe\x00\xc9\x16",
new_callable=AsyncMock,
)
async def test_frame_reader_with_incorrect_crc(
async def test_frame_reader_with_incorrect_bcc(
mock_readexactly, mock_read, frame_reader: FrameReader
) -> None:
"""Test reader on frame with incorrect checksum."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from pyplumio import util


def test_crc() -> None:
def test_bcc() -> None:
"""Test CRC checksum calculation."""
assert util.crc(b"\x68\x0a\x00\x00\x56\x30\x05\x40") == 0x41
assert util.bcc(b"\x68\x0a\x00\x00\x56\x30\x05\x40") == 0x41


def test_to_camelcase() -> None:
Expand Down

0 comments on commit 8763bc0

Please sign in to comment.