import mmap
import struct
import time

shm = mmap.mmap(-1, 4 * 1024 * 1024, tagname="Local\\POE2_Auto_SharedMem_v1")
data = shm[:64]
magic, proto, is_running, telem_seq, cmd_seq, cmd_read, core_hb, agent_hb, res = struct.unpack("<QIIQQQQQQ", data)
print(f"magic: {hex(magic)}")
print(f"proto: {hex(proto)}")
print(f"is_running: {is_running}")
print(f"telem_seq: {telem_seq}")
print(f"cmd_seq: {cmd_seq}")
print(f"cmd_read: {cmd_read}")
print(f"core_hb: {core_hb}")
print(f"agent_hb: {agent_hb}")
now = int(time.time() * 1000)
print(f"now: {now}, diff={now - core_hb} ms")
shm.close()
