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,39 @@
import re
import struct
# Helper to read uint16 from bytes
def read_u16_le(data: bytes, offset: int) -> int:
if offset + 2 > len(data):
return None
return struct.unpack_from('<H', data, offset)[0]
# Read the log file
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/hl7_forwarder.log", "r") as f:
content = f.read()
# Find all occurrences of Hex head logging
hex_heads = re.findall(r"Raw hex \(first 32 bytes\): ([0-9a-fA-F]+)", content)
warnings = re.findall(r"unrecognized. Len: (\d+), Hex head: ([0-9a-fA-F]+)", content)
print(f"Found {len(hex_heads)} hex heads from server logging")
print(f"Found {len(warnings)} unrecognized packet hex heads")
# Also find all data packets printed or parsed in logs
# Let's inspect some of the unrecognized packets of size 56 and 45
print("\nSample of Len 56 packets:")
count = 0
for len_str, hex_str in warnings:
if len_str == "56":
print(f" {hex_str}")
count += 1
if count >= 5:
break
print("\nSample of Len 45 packets:")
count = 0
for len_str, hex_str in warnings:
if len_str == "45":
print(f" {hex_str}")
count += 1
if count >= 5:
break