Skip to content

Commit

Permalink
validate HPMA115xx ACK messages, #26
Browse files Browse the repository at this point in the history
  • Loading branch information
avaldebe committed Nov 16, 2021
1 parent e4acca9 commit d6b2681
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pms/sensors/honeywell/hpma115s0.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ def checksum(self) -> int:

@classmethod
def _validate(cls, message: bytes, header: bytes, length: int) -> base.Message:
# validate ACK message
if header == b"\xA5\xA5" and length == 2:
assert message == header
return cls(message)

# consistency check: bug in message singnature
assert len(header) == 3, f"wrong header length {len(header)}"
assert header[:1] == b"\x40", f"wrong header start {header!r}"
assert length in [5, 8, 16], f"wrong payload length {length}"
assert length in [8, 16], f"wrong payload length {length}"

# validate message: recoverable errors (throw away observation)
msg = cls(message)
Expand Down

0 comments on commit d6b2681

Please sign in to comment.