From 57e7225a6270c9ddd854a238645e1a1d0069c9d1 Mon Sep 17 00:00:00 2001 From: Brian Harrison Date: Mon, 6 Apr 2026 03:02:36 -0400 Subject: [PATCH] fix: correct DLE-stuffing handling in build_5a_frame function and update parameter description --- minimateplus/framing.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/minimateplus/framing.py b/minimateplus/framing.py index 4f0949c..a7ad295 100644 --- a/minimateplus/framing.py +++ b/minimateplus/framing.py @@ -112,10 +112,13 @@ def build_5a_frame(offset_word: int, raw_params: bytes) -> bytes: Args: offset_word: 16-bit offset (0x1004 for probe/chunks, 0x005A for term). - raw_params: 10 params bytes (from bulk_waveform_params or - bulk_waveform_term_params). 0x10 bytes in params ARE - DLE-stuffed (BW confirmed this for counter=0x1000 and - counter=0x1004 in the capture). + raw_params: 10 or 11 params bytes (from bulk_waveform_params or + bulk_waveform_term_params). 0x10 bytes in params are + written RAW — NOT DLE-stuffed. Confirmed 2026-04-06 by + comparing wire bytes: BW sends bare `10 04` for chunk 1 + (counter=0x1004), not stuffed `10 10 04`. Device reads + params at fixed byte positions; stuffing shifts the bytes + and corrupts the counter, causing device to ignore the frame. Returns: Complete frame bytes: [ACK][STX][stuffed_section][chk][ETX] @@ -131,9 +134,7 @@ def build_5a_frame(offset_word: int, raw_params: bytes) -> bytes: s += b"\x00" # field3 s += bytes([(offset_word >> 8) & 0xFF, # offset_hi — raw, NOT stuffed offset_word & 0xFF]) # offset_lo - for b in raw_params: # params — DLE-stuffed - if b == DLE: - s.append(DLE) + for b in raw_params: # params — NOT DLE-stuffed (raw bytes, match BW wire format) s.append(b) # DLE-aware checksum: for 0x10 XX pairs count XX; for lone bytes count them