From d6b2681bb33f30bd941636ebb5cc70f0457cfee4 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Tue, 16 Nov 2021 10:44:30 +0100 Subject: [PATCH] validate HPMA115xx ACK messages, #26 --- src/pms/sensors/honeywell/hpma115s0.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pms/sensors/honeywell/hpma115s0.py b/src/pms/sensors/honeywell/hpma115s0.py index ba4635a..172da16 100644 --- a/src/pms/sensors/honeywell/hpma115s0.py +++ b/src/pms/sensors/honeywell/hpma115s0.py @@ -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)