Documentation
¶
Overview ¶
Package shm provides POSIX shared memory ring buffers and snapshot regions compatible with the Python spu_sensor.py layout.
Index ¶
Constants ¶
const ( RingCap = 8000 RingEntry = 12 // 3x int32: x, y, z SHMHeader = 16 // [0..3] write_idx u32, [4..11] total u64, [12..15] restarts u32 SHMSize = SHMHeader + RingCap*RingEntry SnapHeader = 8 // [0..3] update_count u32, [4..7] pad AccelScale = 65536.0 // Q16 raw -> g GyroScale = 65536.0 // Q16 raw -> deg/s NameAccel = "vib_detect_shm" NameGyro = "vib_detect_shm_gyro" NameALS = "vib_detect_shm_als" NameLid = "vib_detect_shm_lid" ALSReportLen = 122 LidReportLen = 3 ALSSize = SnapHeader + ALSReportLen LidSize = SnapHeader + 4 )
Ring buffer and snapshot constants matching the Python layout.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a shared memory ring buffer for high-rate IMU data.
func CreateRing ¶
func CreateRing(name string) (*RingBuffer, error)
CreateRing creates a new POSIX shared memory ring buffer.
func OpenRing ¶
func OpenRing(name string) (*RingBuffer, error)
OpenRing opens an existing POSIX shared memory ring buffer (read-only).
func (*RingBuffer) Close ¶
func (r *RingBuffer) Close() error
Close unmaps and closes the shared memory (does not unlink).
func (*RingBuffer) ReadNew ¶
func (r *RingBuffer) ReadNew(lastTotal uint64, scale float64) ([]Sample, uint64)
ReadNew reads new samples since lastTotal, scaling by the given factor. Returns the samples and the new total.
func (*RingBuffer) SetRestarts ¶
func (r *RingBuffer) SetRestarts(count uint32)
SetRestarts writes the restart counter in the header.
func (*RingBuffer) Unlink ¶
func (r *RingBuffer) Unlink() error
Unlink removes the named shared memory segment.
func (*RingBuffer) WriteSample ¶
func (r *RingBuffer) WriteSample(x, y, z int32)
WriteSample writes a raw int32 XYZ sample into the ring buffer.
type Sample ¶
type Sample struct {
X, Y, Z float64
}
Sample holds a 3-axis reading scaled to real units (g or deg/s).
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is a shared memory region for low-rate sensors (latest value only).
func CreateSnapshot ¶
CreateSnapshot creates a new POSIX shared memory snapshot region.
func OpenSnapshot ¶
OpenSnapshot opens an existing shared memory snapshot region (read-only).
func (*Snapshot) Read ¶
Read reads the snapshot payload if the counter has changed since lastCount. Returns nil payload if unchanged.
func (*Snapshot) ReadFloat32 ¶
ReadFloat32 reads a float32 value from the snapshot if the counter changed.
func (*Snapshot) Write ¶
Write writes a payload into the snapshot region and increments the counter.
func (*Snapshot) WriteFloat32 ¶
WriteFloat32 writes a single float32 value to the snapshot payload.