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

41 lines
1.2 KiB
Python

import struct
def read_f32_le(data: bytes, offset: int) -> float:
if offset + 4 > len(data):
return None
return struct.unpack_from('<f', data, offset)[0]
with open("/home/prathiyuman/Prathiyuman/ContecMonitor/fiveparaminte-main/scratch/raw_contec_stream.bin", "rb") as f:
stream = f.read()
# Extract 56-byte packets (subtype 23)
packets = []
consumed = 0
while consumed < len(stream) - 4:
b0 = stream[consumed]
b1 = stream[consumed + 1]
b2 = stream[consumed + 2]
b3 = stream[consumed + 3]
if (b2 == 0x04 or b2 == 0x01) and b3 == 0x46:
pkt_len = b0 | (b1 << 8)
if pkt_len == 56 and consumed + pkt_len <= len(stream):
packets.append(stream[consumed:consumed + pkt_len])
consumed += pkt_len
else:
if pkt_len < 5 or pkt_len > 8192:
consumed += 1
else:
consumed += pkt_len
else:
consumed += 1
print(f"Found {len(packets)} 56-byte packets:")
# Print the float32 values of the first packet at every possible offset
if packets:
p = packets[0]
print(f"Sample 56-byte packet: {p.hex()}")
for offset in range(8, len(p) - 3, 4):
val = read_f32_le(p, offset)
print(f" Offset {offset:02d}: {val}")