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

52 lines
1.7 KiB
Python
Raw Normal View History

import struct
def search_scaled_values(p: bytes, val_sys: int, val_dia: int, val_map: int):
# We will search for scaled values: val, val * 10, val * 100
targets = [
(val_sys, "Sys"), (val_sys * 10, "Sys*10"), (val_sys * 100, "Sys*100"),
(val_dia, "Dia"), (val_dia * 10, "Dia*10"), (val_dia * 100, "Dia*100"),
(val_map, "Map"), (val_map * 10, "Map*10"), (val_map * 100, "Map*100")
]
for offset in range(len(p) - 1):
v = struct.unpack_from('<H', p, offset)[0]
for target_val, name in targets:
if v == target_val:
print(f" Found {name} ({target_val}) at offset {offset}")
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin", "rb") as f:
stream = f.read()
consumed = 0
packets = []
while consumed < len(stream) - 4:
b0, b1, b2, b3 = stream[consumed:consumed+4]
if (b2 == 0x04 or b2 == 0x01) and b3 == 0x46:
pkt_len = b0 | (b1 << 8)
packets.append(stream[consumed:consumed+pkt_len])
consumed += pkt_len
else:
consumed += 1
print(f"Scanning {len(packets)} packets for scaled BP (108, 53, 75)...")
for idx, p in enumerate(packets):
l = len(p)
subtype = p[6] if l > 6 else -1
# We want to print only if something is found
# Redirect output internally
import io
import sys
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout
search_scaled_values(p, 108, 53, 75)
output = new_stdout.getvalue()
sys.stdout = old_stdout
if output.strip():
print(f"Packet #{idx} (Len={l}, Subtype={subtype}):")
print(output, end="")