""" Verify the new parser offsets on the raw captured stream. New mappings: - HR: 989-byte packet, offset 904 (u16 LE) - SpO2: 286-byte packet, offset 264 (u16 LE) - Temperature: 56-byte packet, offset 8 (float32) - NIBP: 45-byte packet, offset 15, 17, 19 (u16 LE) """ import struct def read_u16_le(data, offset): if offset + 2 > len(data): return None return struct.unpack_from(' len(data): return None return struct.unpack_from(' 1.0 and 30.0 < temp < 45.0: if vitals_cache["temperature"] != round(temp, 1): vitals_cache["temperature"] = round(temp, 1) changed = True elif temp is not None and abs(temp - 9999.0) <= 1.0: if vitals_cache["temperature"] is not None: vitals_cache["temperature"] = None changed = True elif pkt_len == 45: sys_bp = read_u16_le(pkt, 15) dia_bp = read_u16_le(pkt, 17) map_bp = read_u16_le(pkt, 19) # 9999 means no NIBP measurement active if sys_bp is not None and sys_bp != 9999 and sys_bp > 0: vitals_cache["systolic_bp"] = float(sys_bp) changed = True elif sys_bp == 9999 or sys_bp == 0: if vitals_cache["systolic_bp"] is not None: vitals_cache["systolic_bp"] = None changed = True if dia_bp is not None and dia_bp != 9999 and dia_bp > 0: vitals_cache["diastolic_bp"] = float(dia_bp) changed = True elif dia_bp == 9999 or dia_bp == 0: if vitals_cache["diastolic_bp"] is not None: vitals_cache["diastolic_bp"] = None changed = True if map_bp is not None and map_bp != 9999 and map_bp > 0: vitals_cache["map_bp"] = float(map_bp) changed = True elif map_bp == 9999 or map_bp == 0: if vitals_cache["map_bp"] is not None: vitals_cache["map_bp"] = None changed = True if changed: current_vitals = {k: v for k, v in vitals_cache.items()} if current_vitals != last_printed: print(f"Pkt #{idx} (len={pkt_len}) -> Vitals: {current_vitals}") last_printed = current_vitals