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 ¶
const ( ProfileCoyote = "coyote3" ProfileHandy = "handy4" )
Built-in profile IDs are stable worker protocol identifiers.
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 ¶
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") 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 ¶
Discoverer scans without connecting to or writing any peripheral.
type Link ¶
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 ¶
LookupProfile returns a fresh descriptor so callers cannot mutate a registry.
func (Profile) MatchesName ¶
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. |