Files
ContecMonitor/fiveparaminte-main/scratch/dump_packets.py
T

79 lines
2.9 KiB
Python

"""
Search the entire 286-byte and 989-byte packets for the ECG HR value (88).
The ECG HR must be somewhere in the packet data.
"""
import struct
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin", "rb") as f:
stream = f.read()
# Find all 286-byte packets with SpO2=98 at offset 264
# (indicating a time when the monitor was showing ECG=88, SpO2=98)
packets = []
i = 0
while i < len(stream) - 8:
if (stream[i + 2] == 0x04 or stream[i + 2] == 0x01) and stream[i + 3] == 0x46:
pkt_len = struct.unpack_from('<H', stream, i)[0]
if 30 < pkt_len < 1050 and i + pkt_len <= len(stream):
packets.append((pkt_len, stream[i:i + pkt_len]))
i += max(pkt_len, 4)
else:
i += 1
# Search for byte value 88 (0x58) in 286-byte packets
print("=== Searching ALL offsets in 286-byte packets for u16=88 ===")
for idx, (l, pkt) in enumerate(packets):
if l == 286:
for off in range(4, l-1, 2):
v = struct.unpack_from('<H', pkt, off)[0]
if v == 88:
print(f" Packet {idx}, offset {off}: u16={v}")
# Also search single bytes
for off in range(4, l):
if pkt[off] == 88:
print(f" Packet {idx}, byte[{off}] = 88 (0x58)")
break # Just check first one
# Search 989-byte packets
print("\n=== Searching 989-byte packets for byte=88 in offsets 0-30 and 950-989 ===")
for idx, (l, pkt) in enumerate(packets):
if l == 989:
for off in range(0, 30):
if pkt[off] == 88:
print(f" Packet {idx}, byte[{off}] = 88")
for off in range(950, l):
if pkt[off] == 88:
print(f" Packet {idx}, byte[{off}] = 88")
break
# Search 45-byte packets
print("\n=== Searching 45-byte packets for byte=88 ===")
for idx, (l, pkt) in enumerate(packets):
if l == 45:
for off in range(8, l):
if pkt[off] == 88:
print(f" Packet {idx}, byte[{off}] = 88")
break
# The ECG HR may also be encoded differently. Let's check what's at byte
# positions right before the alarm limits in the 45-byte packet
print("\n=== 45-byte packet: All non-zero bytes with their positions ===")
for idx, (l, pkt) in enumerate(packets):
if l == 45:
for off in range(8, l):
if pkt[off] != 0:
print(f" byte[{off}] = {pkt[off]} (0x{pkt[off]:02x})")
break
# Check the 45-byte packet at index 147 specifically (when NIBP was 110/67/82)
print("\n=== 45-byte packet at the time of NIBP 110/67/82 ===")
count = 0
for idx, (l, pkt) in enumerate(packets):
if l == 45:
count += 1
if count > 36: # Skip to around packet index 147
for off in range(8, l):
if pkt[off] != 0:
print(f" byte[{off}] = {pkt[off]} (0x{pkt[off]:02x})")
break