Documentation
¶
Overview ¶
Package device owns the single serialized BUSY Bar output boundary.
Index ¶
- Constants
- Variables
- func RunAssetRetry(ctx context.Context, runtime AssetRuntime, reconciler AssetReconciler, ...) error
- type AssetReconciler
- type AssetResolver
- type AssetRetryOptions
- type AssetRetryTimer
- type AssetRuntime
- type AudioAssetResolver
- type AudioBackend
- type AudioClient
- type AudioDisplay
- type AudioStatus
- type BusyTimerBackend
- type BusyTimerClient
- type BusyTimerDisplay
- type Client
- type ClientFactory
- type DelayFunc
- type DeviceIdentity
- type Display
- type Gateway
- type Output
- func (o *Output) BusySnapshot(ctx context.Context) (busylib.BusySnapshot, error)
- func (o *Output) Clear(ctx context.Context, application string) error
- func (o *Output) Close(ctx context.Context) error
- func (o *Output) DeviceTime(ctx context.Context) (busylib.TimestampInfo, error)
- func (o *Output) Draw(ctx context.Context, value busylib.DisplayElements) error
- func (o *Output) PlayAudio(ctx context.Context, value busylib.PlayAudio) error
- func (o *Output) ReadTo(ctx context.Context, path string, writer io.Writer) (int64, error)
- func (o *Output) Remove(ctx context.Context, path string) error
- func (o *Output) SetBusySnapshot(ctx context.Context, value busylib.BusySnapshot) error
- func (o *Output) Status() OutputStatus
- func (o *Output) UploadFile(ctx context.Context, application, path, localPath string) error
- type OutputBackend
- type OutputOptions
- type OutputPhase
- type OutputStatus
- type Phase
- type Runtime
- func (r *Runtime) BusySnapshot(ctx context.Context) (busylib.BusySnapshot, error)
- func (r *Runtime) Changes() <-chan struct{}
- func (r *Runtime) Clear(ctx context.Context, applicationName string) error
- func (r *Runtime) DeviceIdentity(ctx context.Context) (DeviceIdentity, error)
- func (r *Runtime) DeviceTime(ctx context.Context) (busylib.TimestampInfo, error)
- func (r *Runtime) Draw(ctx context.Context, request busylib.DisplayElements) error
- func (r *Runtime) NewStatusStream() (publicstream.Stream, error)
- func (r *Runtime) ObserveStatusStream(update StreamHealth)
- func (r *Runtime) PlayAudio(ctx context.Context, value busylib.PlayAudio) error
- func (r *Runtime) ReadTo(ctx context.Context, path string, writer io.Writer) (int64, error)
- func (r *Runtime) Remove(ctx context.Context, path string) error
- func (r *Runtime) Run(ctx context.Context) error
- func (r *Runtime) SetBusySnapshot(ctx context.Context, value busylib.BusySnapshot) error
- func (r *Runtime) Status() RuntimeStatus
- func (r *Runtime) UploadFile(ctx context.Context, applicationName, path, localPath string) error
- type RuntimeConfig
- type RuntimeStatus
- type SecretResolver
- type StatusStreamFactory
- type StatusSubscriber
- type StatusSubscriberOptions
- type StreamHealth
- type StreamHealthObserver
- type StreamHealthPhase
Constants ¶
const (
ApplicationName = "bsbctl"
)
const DefaultOutputReadLimit int64 = 64 << 20
Variables ¶
var ( ErrOutputClosed = errors.New("device output is closed") ErrOutputReadLimit = errors.New("device readback exceeds limit") )
Functions ¶
func RunAssetRetry ¶
func RunAssetRetry(ctx context.Context, runtime AssetRuntime, reconciler AssetReconciler, options AssetRetryOptions) error
RunAssetRetry retries asset reconciliation only while the device client is ready. Runtime and WebSocket edges wake it immediately; RetryAt drives endpoint recovery without depending on status-stream traffic.
Types ¶
type AssetReconciler ¶
type AssetResolver ¶
type AssetResolver interface {
ResolveScene(string, presentation.Scene) (presentation.ResolvedScene, error)
}
type AssetRetryOptions ¶
type AssetRetryOptions struct {
Wake <-chan struct{}
Now func() time.Time
NewTimer func(time.Duration) AssetRetryTimer
}
type AssetRetryTimer ¶
type AssetRuntime ¶
type AssetRuntime interface {
Status() RuntimeStatus
Changes() <-chan struct{}
}
type AudioAssetResolver ¶
type AudioAssetResolver interface {
ResolveAudioCue(string, presentation.AudioCue) (presentation.ResolvedAudioCue, error)
}
type AudioBackend ¶
type AudioClient ¶
type AudioDisplay ¶
type AudioStatus ¶
type AudioStatus struct {
Attempts uint64 `json:"attempts"`
LastErrorCode string `json:"last_error_code,omitempty"`
}
AudioStatus reports redacted diagnostics for best-effort audio delivery. Attempts advances only when the gateway issues a distinct audio write.
type BusyTimerBackend ¶
type BusyTimerBackend interface {
BusySnapshot(context.Context) (busylib.BusySnapshot, error)
SetBusySnapshot(context.Context, busylib.BusySnapshot) error
DeviceTime(context.Context) (busylib.TimestampInfo, error)
}
type BusyTimerClient ¶
type BusyTimerClient interface {
BusySnapshot(context.Context) (busylib.BusySnapshot, error)
SetBusySnapshot(context.Context, busylib.BusySnapshot) error
DeviceTime(context.Context) (busylib.TimestampInfo, error)
}
type BusyTimerDisplay ¶
type BusyTimerDisplay interface {
BusySnapshot(context.Context) (busylib.BusySnapshot, error)
SetBusySnapshot(context.Context, busylib.BusySnapshot) error
DeviceTime(context.Context) (busylib.TimestampInfo, error)
}
BusyTimerDisplay is implemented by the process-wide device output owner. It is separate from Display so scene-only test and alternate displays stay narrow.
type Client ¶
type Client interface {
Draw(context.Context, busylib.DisplayElements) error
Clear(context.Context, string) error
UploadFile(context.Context, string, string, string) error
ReadTo(context.Context, string, io.Writer) (int64, error)
Remove(context.Context, string) error
NewStatusStream() (publicstream.Stream, error)
}
Client is the complete device surface shared by every runtime proxy.
type DeviceIdentity ¶
type DeviceIdentity struct {
APISemVer string
SerialNumber string
OTPModel string
OTPValid bool
FirmwareTarget int
FirmwareVersion string
FirmwareCommit string
FirmwareDirty string
Uptime string
}
DeviceIdentity is the bounded diagnostic tuple read on each connection.
type Display ¶
type Display interface {
Draw(context.Context, busylib.DisplayElements) error
Clear(context.Context, string) error
}
Display is the narrow busylib-go surface required by the output worker.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway serializes output, suppresses identical scenes, updates stable element topologies in place, and clears before structural replacements.
func NewGateway ¶
func NewGateway(display Display, resolver AssetResolver) (*Gateway, error)
func (*Gateway) InvalidateCanvas ¶
func (g *Gateway) InvalidateCanvas()
InvalidateCanvas forgets the cached HTTP scene after a physical selector transition or Back press. Firmware closes that canvas before the matching input event is handled, so the next selected scene must be drawn even when its digest is unchanged.
func (*Gateway) InvalidateConnection ¶
func (g *Gateway) InvalidateConnection()
InvalidateConnection forgets physical-delivery proofs after reconnect while retaining ownership and structure for clearing a scene or timer that survived.
func (*Gateway) Render ¶
func (g *Gateway) Render(ctx context.Context, candidate *presentation.Candidate) (attention.DeliveryOutcome, error)
Render updates a structurally compatible bsbctl canvas in place. A nil candidate clears it; structural changes and priority drops replace it.
func (*Gateway) Status ¶
func (g *Gateway) Status() AudioStatus
Status returns the gateway-owned best-effort audio diagnostics. Visual delivery is returned directly by Render.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output is the sole serialized owner of physical display and asset I/O. Callers wait for their command only; a slow device never occupies their subsystem's actor or lock while another command is admitted.
func NewOutput ¶
func NewOutput(backend OutputBackend, options OutputOptions) *Output
func (*Output) BusySnapshot ¶
func (*Output) Close ¶
Close rejects new work, drains already admitted commands, and joins the actor. Its context bounds admission and joining but does not reorder work.
func (*Output) DeviceTime ¶
func (*Output) SetBusySnapshot ¶
func (*Output) Status ¶
func (o *Output) Status() OutputStatus
type OutputBackend ¶
type OutputOptions ¶
type OutputPhase ¶
type OutputPhase string
const ( OutputReady OutputPhase = "ready" OutputBusy OutputPhase = "busy" OutputClosed OutputPhase = "closed" )
type OutputStatus ¶
type OutputStatus struct {
Phase OutputPhase `json:"phase"`
QueueDepth int `json:"queue_depth"`
LastErrorCode string `json:"last_error_code,omitempty"`
}
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime resolves device credentials and constructs the process-wide client without coupling transient device failure to daemon availability.
func NewRuntime ¶
func NewRuntime(config RuntimeConfig) *Runtime
func (*Runtime) BusySnapshot ¶
func (*Runtime) Changes ¶
func (r *Runtime) Changes() <-chan struct{}
Changes is a coalesced edge signal. Consumers read Status after each edge. Buffering preserves a transition that occurs before consumer startup.
func (*Runtime) DeviceIdentity ¶
func (r *Runtime) DeviceIdentity(ctx context.Context) (DeviceIdentity, error)
func (*Runtime) DeviceTime ¶
func (*Runtime) NewStatusStream ¶
func (r *Runtime) NewStatusStream() (publicstream.Stream, error)
func (*Runtime) ObserveStatusStream ¶
func (r *Runtime) ObserveStatusStream(update StreamHealth)
func (*Runtime) SetBusySnapshot ¶
func (*Runtime) Status ¶
func (r *Runtime) Status() RuntimeStatus
type RuntimeConfig ¶
type RuntimeConfig struct {
BaseURL string
AccessTokenReference string
Resolver SecretResolver
Factory ClientFactory
Delay DelayFunc
Clock func() time.Time
Jitter func() float64
}
type RuntimeStatus ¶
type RuntimeStatus struct {
Phase Phase `json:"phase"`
Attempt int `json:"attempt"`
RetryAt time.Time `json:"retry_at,omitempty"`
LastErrorCode string `json:"last_error_code,omitempty"`
LastConnectedAt time.Time `json:"last_connected_at,omitempty"`
LastStateAt time.Time `json:"last_state_at,omitempty"`
}
RuntimeStatus is deliberately safe for local diagnostics. It never contains device addresses, secret references or values, or raw dependency errors.
func (RuntimeStatus) MarshalJSON ¶
func (s RuntimeStatus) MarshalJSON() ([]byte, error)
type SecretResolver ¶
type StatusStreamFactory ¶
type StatusStreamFactory func() (publicstream.Stream, error)
type StatusSubscriber ¶
type StatusSubscriber struct {
// contains filtered or unexported fields
}
StatusSubscriber continuously drains the one-shot busylib status stream and recreates it after terminal failure. Draining is immediate so firmware input cannot be blocked by rendering or plugin work.
func NewStatusSubscriber ¶
func NewStatusSubscriber(options StatusSubscriberOptions) (*StatusSubscriber, error)
type StatusSubscriberOptions ¶
type StatusSubscriberOptions struct {
Factory StatusStreamFactory
Submit func(*inputpb.InputEvent) bool
Backoff time.Duration
OnConnected func()
Observer StreamHealthObserver
}
type StreamHealth ¶
type StreamHealth struct {
Phase StreamHealthPhase
Lifecycle publicstream.Lifecycle
Access publicstream.AccessStatus
Attempt int
RetryAt time.Time
ConnectedAt time.Time
LastStateAt time.Time
ErrorCode string
}
type StreamHealthObserver ¶
type StreamHealthObserver interface {
ObserveStatusStream(StreamHealth)
}
type StreamHealthPhase ¶
type StreamHealthPhase string
const ( StreamCreating StreamHealthPhase = "creating" StreamStarting StreamHealthPhase = "starting" StreamStatusTransition StreamHealthPhase = "status" StreamTerminal StreamHealthPhase = "terminal" StreamBackoff StreamHealthPhase = "backoff" )