bleworker

package
v0.1.0-alpha.85 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: GPL-3.0 Imports: 12 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 bleworker is the radio side of the native Bluetooth worker. It speaks workerproto over stdin and stdout and drives an Adapter. The concrete Bluetooth adapter lives in cmd/bluetooth-worker, so the core binary never links a radio stack (AGENTS.md section 3).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("device not found")
	ErrUnavailable = errors.New("bluetooth unavailable")
	ErrUnsupported = errors.New("device does not offer the required GATT service")
	ErrAmbiguous   = errors.New("more than one matching Bluetooth device was found; turn off the others and try again")
)

Adapter failures that map to protocol error codes.

Functions

func Serve

func Serve(ctx context.Context, input io.Reader, output io.Writer, adapter Adapter, info Info) error

Serve runs the protocol until shutdown or the end of input. When input ends without a shutdown, the core is gone: the worker writes the stored last-will packet, disconnects and returns.

Types

type Adapter

type Adapter interface {
	Enable() error
	ConnectAddress(ctx context.Context, address string, profile ble.Profile) (Peripheral, error)
	ScanName(ctx context.Context, profile ble.Profile) (string, error)
}

Adapter finds and connects devices.

type Handlers

type Handlers struct {
	Notify  func([]byte)
	Battery func(int)
	Lost    func(error)
}

Handlers receive radio callbacks. They may run on adapter goroutines.

type Info

type Info struct {
	Worker   string
	Platform string
}

Info identifies the worker in its hello reply.

type Peripheral

type Peripheral interface {
	Open(handlers Handlers) error
	Write(payload []byte, withResponse bool) error
	ReadBattery() (int, error)
	Address() string
	Name() string
	MaxWriteBytes() int
	Close() error
}

Peripheral is one connected device. Open discovers the pulse service and subscribes to notifications; it returns ErrUnsupported when the service or either characteristic is missing.

type SimulatedAdapter

type SimulatedAdapter struct {
	Connectors map[string]ble.Connector
}

SimulatedAdapter models named device profiles behind the worker protocol. It backs the worker's -simulate flag and the process-level tests; no radio is used.

func NewSimulatedAdapter

func NewSimulatedAdapter(connectors map[string]ble.Connector) *SimulatedAdapter

NewSimulatedAdapter returns an adapter over a fresh simulated connector.

func (*SimulatedAdapter) ConnectAddress

func (a *SimulatedAdapter) ConnectAddress(ctx context.Context, address string, profile ble.Profile) (Peripheral, error)

ConnectAddress connects to the simulated device.

func (*SimulatedAdapter) Discover

func (a *SimulatedAdapter) Discover(_ context.Context, profile ble.Profile) ([]ble.Candidate, error)

Discover returns only the configured simulation without opening a link.

func (*SimulatedAdapter) Enable

func (a *SimulatedAdapter) Enable() error

Enable always succeeds.

func (*SimulatedAdapter) ScanName

func (a *SimulatedAdapter) ScanName(ctx context.Context, profile ble.Profile) (string, error)

ScanName finds only profiles supplied by the test host.

Jump to

Keyboard shortcuts

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