usb connection improved
This commit is contained in:
@ -427,8 +427,8 @@ class Protocol:
|
||||
)
|
||||
|
||||
words = _unpack_words(data)
|
||||
expected_crc = _payload_checksum(list(words[1:14]))
|
||||
if words[14] != expected_crc:
|
||||
if not Protocol.has_valid_response_crc(data):
|
||||
expected_crc = _payload_checksum(list(words[1:14]))
|
||||
raise CRCError(expected=expected_crc, received=words[14])
|
||||
|
||||
return Measurements(
|
||||
@ -448,6 +448,15 @@ class Protocol:
|
||||
timestamp=datetime.now(),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def has_valid_response_crc(data: bytes) -> bool:
|
||||
"""Return True when a telemetry frame has the expected length and CRC."""
|
||||
if len(data) != GET_DATA_TOTAL_LENGTH:
|
||||
return False
|
||||
words = _unpack_words(data)
|
||||
expected_crc = _payload_checksum(list(words[1:14]))
|
||||
return words[14] == expected_crc
|
||||
|
||||
@staticmethod
|
||||
def decode_status(data: bytes) -> tuple[DeviceState, int]:
|
||||
"""Decode the two-byte firmware status response into flags and detail."""
|
||||
|
||||
Reference in New Issue
Block a user