50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import sys
|
|
import struct
|
|
sys.path.insert(0, "/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main")
|
|
|
|
from contec_parser import parse_contec_binary_packet
|
|
|
|
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin", "rb") as f:
|
|
stream = f.read()
|
|
|
|
i = 0
|
|
pkts = []
|
|
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):
|
|
pkts.append(stream[i:i+pkt_len])
|
|
i += max(pkt_len, 4)
|
|
else:
|
|
i += 1
|
|
|
|
print(f"Loaded {len(pkts)} packets.")
|
|
|
|
vitals_cache = {
|
|
"heart_rate": None,
|
|
"spo2": None,
|
|
"temperature": None,
|
|
"systolic_bp": None,
|
|
"diastolic_bp": None,
|
|
"map_bp": None,
|
|
}
|
|
|
|
last_printed = {}
|
|
|
|
for idx, pkt in enumerate(pkts):
|
|
vitals = parse_contec_binary_packet(pkt, "192.168.100.120")
|
|
if vitals:
|
|
# Merge like contec_server.py
|
|
changed = False
|
|
for field in vitals.present_fields or []:
|
|
val = getattr(vitals, field)
|
|
if vitals_cache[field] != val:
|
|
vitals_cache[field] = val
|
|
changed = True
|
|
|
|
if changed:
|
|
current = {k: v for k, v in vitals_cache.items()}
|
|
if current != last_printed:
|
|
print(f"Pkt #{idx} (len={len(pkt)}) -> Cache: {current}")
|
|
last_printed = current
|