From: Gerhard Sittig Date: Mon, 17 May 2021 20:14:50 +0000 (+0200) Subject: dmm/bm86x: check more bytes in DMM packet (undocumented by vendor) X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=f12591299ee58dec8cbbada4c0073b34f9359c75;p=libsigrok.git dmm/bm86x: check more bytes in DMM packet (undocumented by vendor) User johnch reported via IRC that bm86x meters can lose sync to the packet stream which goes unnoticed and tries to process invalid data. Tighten the packet validity check, compare four bytes of the third chunk in the DMM packet. This improves reliability, but isn't backed by vendor documentation. It's yet to get determined whether other existing devices don't provide the four-byte magic pattern. --- diff --git a/src/dmm/bm86x.c b/src/dmm/bm86x.c index b38c3123..ea260d8f 100644 --- a/src/dmm/bm86x.c +++ b/src/dmm/bm86x.c @@ -59,6 +59,22 @@ SR_PRIV gboolean sr_brymen_bm86x_packet_valid(const uint8_t *buf) if (buf[19] != 0x86) return FALSE; + /* + * 2021-05 update: The devices that we have seen in the field do + * provide four bytes which we can synchronize to. Which happens + * to match the bm52x and bm82x devices' protocol. This condition + * is not documented by the vendor, but improves reliability of + * the re-synchronization for slight offsets, which were seen + * in the field, and which would have kept failing in an earlier + * implementation. + */ + if (buf[16] != 0x86) + return FALSE; + if (buf[17] != 0x86) + return FALSE; + if (buf[18] != 0x86) + return FALSE; + return TRUE; }