"""ctypes mirror of core/contract/contract.h (plan todo 2). This module hand-mirrors the frozen, packed C struct layout so the Python tracker and the C++ core agree byte-for-byte on the shared-memory frame contract and the control-plane message schema. It is frozen the same way the C header is: any field-shape change here must be paired with the matching C change and a CONTRACT_VERSION bump, and tests/test_contract_py.py checks this mirror against the C header's actual, freshly-compiled layout (never a hardcoded golden copy on either side) so the two cannot silently drift apart. """ import ctypes CONTRACT_VERSION = 1 JOINT_COUNT = 20 FRAME_SLOT_COUNT = 3 class JointTrackingState: NOT_TRACKED = 0 INFERRED = 1 TRACKED = 2 class ControlMessageType: HANDSHAKE_VERSION = 0 CONFIG = 1 CALIBRATION = 2 HEARTBEAT = 3 class Vector4(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("x", ctypes.c_float), ("y", ctypes.c_float), ("z", ctypes.c_float), ("w", ctypes.c_float), ] class JointData(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("position", Vector4), ("tracking_state", ctypes.c_uint32), ] class SkeletonFrame(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("joints", JointData * JOINT_COUNT), ("skeleton_tracking_id", ctypes.c_uint32), ("quality_flags", ctypes.c_uint32), ] class DepthBufferDescriptor(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("width", ctypes.c_uint32), ("height", ctypes.c_uint32), ("pitch", ctypes.c_uint32), ("byte_offset", ctypes.c_uint64), ] class ColorBufferDescriptor(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("width", ctypes.c_uint32), ("height", ctypes.c_uint32), ("pitch", ctypes.c_uint32), ("byte_offset", ctypes.c_uint64), ] class FrameData(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("frame_number", ctypes.c_uint32), ("timestamp_micros", ctypes.c_int64), ("skeleton", SkeletonFrame), ("depth", DepthBufferDescriptor), ("color", ColorBufferDescriptor), ] class FrameSlot(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("sequence", ctypes.c_uint64), ("data", FrameData), ] class FrameContract(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("contract_version", ctypes.c_uint32), ("reserved", ctypes.c_uint32), ("published_sequence", ctypes.c_uint64), ("slots", FrameSlot * FRAME_SLOT_COUNT), ] class ControlMessageHeader(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("message_type", ctypes.c_uint32), ("contract_version", ctypes.c_uint32), ("payload_size", ctypes.c_uint32), ("reserved", ctypes.c_uint32), ] class HandshakeMessage(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("header", ControlMessageHeader), ("client_version", ctypes.c_uint32), ("capabilities", ctypes.c_uint32), ] class ConfigMessage(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("header", ControlMessageHeader), ("depth_width", ctypes.c_uint32), ("depth_height", ctypes.c_uint32), ("color_width", ctypes.c_uint32), ("color_height", ctypes.c_uint32), ] class CalibrationMessage(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("header", ControlMessageHeader), ("z0_meters", ctypes.c_float), ("mirror", ctypes.c_uint32), ("floor_plane", ctypes.c_float * 4), ] class HeartbeatMessage(ctypes.Structure): _pack_ = 1 _layout_ = "ms" _fields_ = [ ("header", ControlMessageHeader), ("timestamp_micros", ctypes.c_int64), ("sequence", ctypes.c_uint64), ]