handyble

package
v0.1.0-alpha.78 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: GPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package handyble implements firmware-4 Handy RPC over a byte-oriented BLE link. It knows the device protocol, not the motion engine or the native radio stack.

Index

Constants

View Source
const MaxFrameBytes = 512

MaxFrameBytes is the firmware RPC frame ceiling, before negotiated MTU limits.

Variables

View Source
var ErrInterrupted = errors.New("handy command interrupted by Stop")

ErrInterrupted marks queued work invalidated by Stop.

Functions

func Encode

func Encode(r Request) ([]byte, error)

Encode returns a complete protobuf RPC envelope. GATT frames must never be formed by splitting this byte slice; split Add point lists before encoding.

Types

type HSPState

type HSPState struct {
	PlayState   string
	StreamID    uint32
	Points      uint32
	CurrentTime int32
	Tail        int32
}

HSPState contains observed firmware state, not a commanded-position estimate.

type Message

type Message struct {
	Notification bool
	ID           uint32
	Method       Method
	State        *HSPState
	DeviceTime   *uint32
	ErrorCode    *uint64
}

Message is a decoded response or notification with optional firmware feedback.

func Decode

func Decode(data []byte) (Message, error)

Decode is bounded and accepts protobuf's omitted zero fields and unknown fields, while rejecting truncated/overflowed frames. Error presence matters even when firmware omits its message text or returns code zero.

type Method

type Method uint32

Method is a firmware RPC field number from handy-public-rpc commit 2398008c.

const (
	StopCurrentMode Method = 715 // firmware 4.0.13+: Stop regardless of the active mode
	ClockSet        Method = 709
	ClockGet        Method = 712
	Stroke          Method = 841
	Setup           Method = 860
	Add             Method = 861
	Play            Method = 863
	Stop            Method = 864
	State           Method = 867
)

Supported RPC methods use the same wire contract as Browser Bluetooth.

type Point

type Point struct {
	Time     uint32
	Position uint32
}

Point carries an integer percentage and an absolute stream time in milliseconds.

type Request

type Request struct {
	Method      Method
	ID          uint32
	StreamID    uint32
	Min, Max    float32 // normalized 0..1 stroke window, not point positions
	Points      []Point
	Tail        uint32
	Flush       bool
	Start       int32
	ServerTime  *uint64
	ClockOffset int64
	RoundTrip   int32
}

Request is a device command, after shared transport validation and quantization. Looping is deliberately not exposed: loss of the controller must exhaust a finite buffer. Play always pauses on starvation.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session owns RPC ordering and correlation on one immutable BLE link. The operation gate covers a whole point batch; Interrupt fences the next chunk without canceling a healthy native write halfway through Stop.

func NewSession

func NewSession(link ble.Link) (*Session, error)

NewSession attaches RPC correlation to an already-open immutable BLE link.

func (*Session) Close

func (s *Session) Close() error

Close retires the session and waits for the worker and event reader.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done closes when the event reader stops; Close also waits for link teardown.

func (*Session) Execute

func (s *Session) Execute(ctx context.Context, request Request) (Message, error)

Execute serializes one command, including all of an Add operation's chunks.

func (*Session) Initialize

func (s *Session) Initialize(ctx context.Context) error

Initialize sends only Stop and optional clock commands. It never starts motion.

func (*Session) Interrupt

func (s *Session) Interrupt()

Interrupt prevents further chunks or Play from an operation admitted before Stop. A native write already in progress has at most writeTimeout to finish.

func (*Session) Snapshot

func (s *Session) Snapshot() Snapshot

Snapshot returns a copy of the current RPC session status.

type SimulatedConnector

type SimulatedConnector struct {
	WriteOnly  bool
	WriteLimit int
	// contains filtered or unexported fields
}

SimulatedConnector exercises the RPC path without a radio or a second motion engine. It acknowledges bytes and records requests; it does not move anything.

func NewSimulatedConnector

func NewSimulatedConnector() *SimulatedConnector

NewSimulatedConnector creates an RPC-only simulator with no radio access.

func (*SimulatedConnector) Connect

Connect opens a fresh in-memory link without starting motion.

func (c *SimulatedConnector) LastLink() *SimulatedLink

LastLink returns the most recently created link for test inspection.

func (*SimulatedConnector) Simulated

func (*SimulatedConnector) Simulated() bool

Simulated always reports true.

type SimulatedLink struct {
	// contains filtered or unexported fields
}

SimulatedLink records wire requests and emits optional RPC acknowledgments.

func (*SimulatedLink) Close

func (l *SimulatedLink) Close() error

Close retires the simulated link and ends its event stream.

func (*SimulatedLink) Device

func (l *SimulatedLink) Device() ble.DeviceInfo

Device reports a synthetic identity and write limit.

func (*SimulatedLink) Emit

func (l *SimulatedLink) Emit(payload []byte)

Emit injects firmware feedback for isolated protocol tests.

func (*SimulatedLink) Events

func (l *SimulatedLink) Events() <-chan ble.LinkEvent

Events supplies the simulated notification stream.

func (*SimulatedLink) ReadBattery

func (l *SimulatedLink) ReadBattery(context.Context) (int, error)

ReadBattery reports that the Handy profile has no battery characteristic.

func (*SimulatedLink) SetLastWill

func (l *SimulatedLink) SetLastWill([]byte) error

SetLastWill is inert because this simulator has no physical output.

func (*SimulatedLink) Write

func (l *SimulatedLink) Write(ctx context.Context, data []byte, _ bool) error

func (*SimulatedLink) Writes

func (l *SimulatedLink) Writes() [][]byte

Writes returns independent copies of recorded frames.

type Snapshot

type Snapshot struct {
	Ready         bool
	ClockSynced   bool
	PlaybackState string
	Error         string
}

Snapshot reports connection health and the latest accepted playback feedback.

Jump to

Keyboard shortcuts

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