refactor: implement packet parsing heuristics and introduce device-level state caching to throttle database writes and vitals updates
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import re
|
||||
import struct
|
||||
|
||||
def read_u16_le(data: bytes, offset: int) -> int:
|
||||
if offset + 2 > len(data):
|
||||
return None
|
||||
return struct.unpack_from('<H', data, offset)[0]
|
||||
|
||||
# Let's read the log line by line and reconstruct packets
|
||||
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/hl7_forwarder.log", "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# We want to find raw reads and buffer state
|
||||
# The server logs:
|
||||
# "Received {len} bytes from ... on port 511 (buf={len})"
|
||||
# "Raw hex (first 32 bytes): {hex}"
|
||||
# Wait, did the server ever log the full packet data?
|
||||
# Let's look at the log lines.
|
||||
print("Searching for raw hex data logs...")
|
||||
hex_patterns = []
|
||||
for line in lines[:5000]:
|
||||
m = re.search(r"Raw hex \(first 32 bytes\): ([0-9a-fA-F]+)", line)
|
||||
if m:
|
||||
hex_patterns.append(m.group(1))
|
||||
|
||||
print(f"Total raw hex logs: {len(hex_patterns)}")
|
||||
if hex_patterns:
|
||||
print(f"Example raw hex: {hex_patterns[0]}")
|
||||
Reference in New Issue
Block a user