refactor: implement packet parsing heuristics and introduce device-level state caching to throttle database writes and vitals updates

This commit is contained in:
2026-07-11 14:24:14 +05:30
parent a4972b3251
commit 84b8acc904
32 changed files with 3499 additions and 180 deletions
@@ -0,0 +1,41 @@
import struct
filepath = "/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin"
try:
with open(filepath, "rb") as f:
stream = f.read()
except Exception as e:
print(f"Error: {e}")
import sys
sys.exit(1)
# Find latest 288-byte and 989-byte packets
pkt_288 = None
pkt_989 = None
i = 0
while i < len(stream) - 4:
b0, b1, b2, b3 = stream[i], stream[i+1], stream[i+2], stream[i+3]
if b3 == 0x46:
pkt_len = b0 | (b1 << 8)
if pkt_len == 288 and i + pkt_len <= len(stream):
pkt_288 = stream[i:i + pkt_len]
elif pkt_len == 989 and i + pkt_len <= len(stream):
pkt_989 = stream[i:i + pkt_len]
i += max(pkt_len, 4)
else:
i += 1
if pkt_288:
print("=== Scanning 288-byte packet (tail, offsets 250-287) for values 75-90 ===")
for off in range(250, len(pkt_288) - 1, 2):
val = struct.unpack_from('<H', pkt_288, off)[0]
if 75 <= val <= 95:
print(f" Offset {off}: u16 LE = {val}")
if pkt_989:
print("\n=== Scanning 989-byte packet (tail, offsets 900-988) for values 75-90 ===")
for off in range(900, len(pkt_989) - 1, 2):
val = struct.unpack_from('<H', pkt_989, off)[0]
if 75 <= val <= 95:
print(f" Offset {off}: u16 LE = {val}")