ble

package
v0.1.0-alpha.82 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 4 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 ble defines the byte-oriented contract between a device driver and an isolated native Bluetooth worker. It contains no motion or radio code.

Index

Constants

View Source
const (
	ProfileCoyote = "coyote3"
	ProfileHandy  = "handy4"
)

Built-in profile IDs are stable worker protocol identifiers.

View Source
const DefaultConnectTimeout = 12 * time.Second

DefaultConnectTimeout includes fresh advertisement discovery and native link readiness. Windows can spend about seven seconds on one uncached GATT attempt; the previous six-second budget could expire while a visible device connected. This is a deadline, not a delay, and caller cancellation still wins.

Variables

View Source
var (
	// ErrDiscoveryFailed is a transient failure before any device command was
	// admitted; it is distinct from a device that lacks the required service.
	ErrDiscoveryFailed      = errors.New("bluetooth service discovery did not complete; retry the connection")
	ErrNotFound             = errors.New("no matching Bluetooth device was found")
	ErrBluetoothUnavailable = errors.New("bluetooth is off or this PC has no Bluetooth adapter")
	ErrUnsupportedDevice    = errors.New("the device does not offer the required Bluetooth service")
	ErrHelperMissing        = errors.New("the native Bluetooth helper is missing or incompatible; update this installation")
	ErrLinkClosed           = errors.New("the Bluetooth connection is closed")
)

Actionable connection failures. Device-specific UI supplies pairing guidance.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Address string `json:"address"`
	Name    string `json:"name"`
	RSSI    int    `json:"rssi"`
}

Candidate is an unverified advertisement. Address stays on the host and must not appear in logs or diagnostics. Signal strength is not device identity.

type ConnectRequest

type ConnectRequest struct {
	RememberedAddress string
	// SelectedAddress forbids falling back to another device if this address fails.
	SelectedAddress bool
	ConnectTimeout  time.Duration
	ScanTimeout     time.Duration
}

ConnectRequest supplies private reconnection identity and bounded deadlines.

type Connector

type Connector interface {
	Connect(context.Context, ConnectRequest) (Link, error)
	Simulated() bool
}

Connector creates one independently owned byte link.

type DeviceInfo

type DeviceInfo struct {
	Name          string
	Address       string
	MaxWriteBytes int
	// UnacknowledgedWrites means GATT accepts only Write Without Response.
	// Native completion then confirms queuing, never delivery to the device.
	UnacknowledgedWrites bool
}

DeviceInfo contains a private hardware identifier; never export Address in diagnostics or expose it to clients without host configuration permission.

type Discoverer

type Discoverer interface {
	Discover(context.Context, time.Duration) ([]Candidate, error)
}

Discoverer scans without connecting to or writing any peripheral.

type Link interface {
	Write(context.Context, []byte, bool) error
	ReadBattery(context.Context) (int, error)
	// SetLastWill is best effort on stdin EOF; process termination may prevent it.
	SetLastWill([]byte) error
	Events() <-chan LinkEvent
	Device() DeviceInfo
	Close() error
}

Link owns one connection. Write waits for native API completion, not motor feedback or a firmware response. A canceled uncertain write retires the link.

type LinkEvent

type LinkEvent struct {
	Kind    LinkEventKind
	Payload []byte
	Battery int
	Err     error
}

LinkEvent carries raw device bytes or a connection lifecycle change.

type LinkEventKind

type LinkEventKind string

LinkEventKind identifies a native connection event.

const (
	LinkNotification LinkEventKind = "notification"
	LinkBattery      LinkEventKind = "battery"
	LinkLost         LinkEventKind = "lost"
	LinkWriteFailed  LinkEventKind = "write_failed"
)

Link event kinds contain no device protocol semantics.

type Profile

type Profile struct {
	ID, Name                           string
	ServiceUUID, WriteUUID, NotifyUUID string
	BatteryServiceUUID, BatteryUUID    string
	MaxWriteBytes                      int
	ExactName                          bool
	NamePrefixes                       []string
	RememberedOnly                     bool
	StopOnDisconnect                   bool
	WriteWithoutResponseFallback       bool
	WriteWithoutResponseOnly           bool
}

Profile describes GATT discovery and framing bounds, never device commands. Profiles are allowlisted by ID rather than accepting arbitrary UUIDs over IPC.

func LookupProfile

func LookupProfile(id string) (Profile, bool)

LookupProfile returns a fresh descriptor so callers cannot mutate a registry.

func (Profile) MatchesName

func (p Profile) MatchesName(name string) bool

MatchesName filters advertisements; GATT discovery still verifies the device.

Directories

Path Synopsis
Package bleworker is the radio side of the native Bluetooth worker.
Package bleworker is the radio side of the native Bluetooth worker.
Package workerclient starts the shared native Bluetooth worker process and adapts it to ble.Connector and ble.Link.
Package workerclient starts the shared native Bluetooth worker process and adapts it to ble.Connector and ble.Link.
Package workerproto defines the NDJSON protocol between the MagicHandy core and the native Bluetooth worker process.
Package workerproto defines the NDJSON protocol between the MagicHandy core and the native Bluetooth worker process.

Jump to

Keyboard shortcuts

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