shm

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package shm provides POSIX shared memory ring buffers and snapshot regions compatible with the Python spu_sensor.py layout.

Index

Constants

View Source
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 (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

func CreateSnapshot(name string, size int) (*Snapshot, error)

CreateSnapshot creates a new POSIX shared memory snapshot region.

func OpenSnapshot

func OpenSnapshot(name string, size int) (*Snapshot, error)

OpenSnapshot opens an existing shared memory snapshot region (read-only).

func (*Snapshot) Close

func (s *Snapshot) Close() error

Close unmaps and closes the snapshot shared memory.

func (*Snapshot) Read

func (s *Snapshot) Read(lastCount uint32, payloadLen int) ([]byte, uint32)

Read reads the snapshot payload if the counter has changed since lastCount. Returns nil payload if unchanged.

func (*Snapshot) ReadFloat32

func (s *Snapshot) ReadFloat32(lastCount uint32) (float32, uint32, bool)

ReadFloat32 reads a float32 value from the snapshot if the counter changed.

func (s *Snapshot) Unlink() error

Unlink removes the named shared memory segment.

func (*Snapshot) Write

func (s *Snapshot) Write(payload []byte)

Write writes a payload into the snapshot region and increments the counter.

func (*Snapshot) WriteFloat32

func (s *Snapshot) WriteFloat32(v float32)

WriteFloat32 writes a single float32 value to the snapshot payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL