The 1.0 Python client, mirroring the Rust client 1.0 API and the DongLoRa Protocol v2 wire format. * Module split: monolithic protocol.py / client.py replaced with dongle.py (high-level async Dongle), session.py (reader task + tag routing), frame.py (streaming FrameDecoder + encode_frame), commands.py / events.py / errors.py / modulation.py / info.py / crc.py / chip_id (re-export) matching the donglora-protocol Rust crate. * Async API throughout. Serial I/O via asyncio-serial; mux connections via asyncio streams. The blocking client surface is gone. * thiserror-equivalent error hierarchy (DongloraError base with Timeout, TransportClosed, ReaderExited, BadFrame, ErrClientError variants mirroring the Rust ClientError). * Tag-aware dispatch with concurrent in-flight commands: TagAllocator hands out 16-bit device tags, Session routes each response back to the originating coroutine. * Auto-recovery from ERR(ENOTCONFIGURED): the Dongle caches the last SET_CONFIG and silently re-applies on timeout. * 500 ms background keepalive task per PROTOCOL.md §3.4. * Tests rewritten: test_dongle, test_session, test_frame, test_events, test_modulation, test_crc, test_ergonomics; old test_client / test_protocol removed. * Sticky mux reconnect (from the prior fix commit) is preserved: once a mux socket is in use, reconnects commit to it instead of falling back to USB.
24 lines
603 B
Python
24 lines
603 B
Python
"""CRC-16/CCITT-FALSE conformance tests."""
|
|
|
|
from donglora.crc import crc16
|
|
|
|
|
|
def test_check_value_matches_spec():
|
|
# PROTOCOL.md §2.2 / Appendix B.
|
|
assert crc16(b"123456789") == 0x29B1
|
|
|
|
|
|
def test_empty_input_is_initial_value():
|
|
# No reflection, no XOR-out: empty leaves init untouched.
|
|
assert crc16(b"") == 0xFFFF
|
|
|
|
|
|
def test_single_null_byte():
|
|
# A naive init=0 impl would yield 0; correct init=0xFFFF yields 0xE1F0.
|
|
assert crc16(b"\x00") == 0xE1F0
|
|
|
|
|
|
def test_differs_from_kermit_variant():
|
|
# CRC-16/KERMIT of "123456789" is 0x2189.
|
|
assert crc16(b"123456789") != 0x2189
|