33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
import sys
|
|
|
|
filepath = "/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin"
|
|
|
|
try:
|
|
with open(filepath, "rb") as f:
|
|
f.seek(0, 2)
|
|
size = f.tell()
|
|
# Read the last 2000 bytes
|
|
f.seek(max(0, size - 2000))
|
|
data = f.read()
|
|
except Exception as e:
|
|
print(f"Error reading file: {e}")
|
|
sys.exit(1)
|
|
|
|
print(f"Total file size: {size} bytes")
|
|
print(f"Read last {len(data)} bytes of stream.")
|
|
|
|
# Let's search for potential packet headers in the last 2000 bytes.
|
|
# Typically headers are like: [len_lo] [len_hi] [04/01] [46]
|
|
# Let's print out the hex around any occurrences of 0x46 or 0x47.
|
|
print("\nScanning for potential 0x46 or 0x47 headers...")
|
|
for i in range(len(data) - 4):
|
|
b0, b1, b2, b3 = data[i], data[i+1], data[i+2], data[i+3]
|
|
if b3 == 0x46:
|
|
pkt_len = b0 | (b1 << 8)
|
|
print(f"Index {i} (absolute {size - 2000 + i}): Header match! Bytes: {b0:02x} {b1:02x} {b2:02x} {b3:02x} -> Length: {pkt_len}, Subtype: {b2}")
|
|
# print hex representation of next 16 bytes
|
|
next_bytes = data[i:i+20]
|
|
print(f" Hex: {next_bytes.hex()}")
|
|
elif b3 == 0x47:
|
|
print(f"Index {i} (absolute {size - 2000 + i}): End-marker? Bytes: {b0:02x} {b1:02x} {b2:02x} {b3:02x}")
|