Documentation
¶
Index ¶
- Constants
- Variables
- func CheckCoredump(s *Session, timeout time.Duration) (uint32, string, error)
- func ClearParam(s *Session, ref uint8, timeout time.Duration) error
- func DeleteCoredump(s *Session, timeout time.Duration) error
- func GeneratePerfetto(tasks map[uint8]string, labels map[uint8]string, events []TraceEvent) ([]byte, error)
- func GetParam(s *Session, name string, timeout time.Duration) ([]byte, error)
- func MakePath(s *Session, path string, timeout time.Duration) error
- func Pack(fmt string, args ...any) []byte
- func ReadCoredump(s *Session, offset, length uint32, timeout time.Duration) ([]byte, error)
- func ReadDoubleMetrics(s *Session, ref uint8, timeout time.Duration) ([]float64, error)
- func ReadFile(s *Session, file string, report func(uint32), timeout time.Duration) ([]byte, error)
- func ReadFileRange(s *Session, file string, offset, length uint32, report func(uint32), ...) ([]byte, error)
- func ReadFloatMetrics(s *Session, ref uint8, timeout time.Duration) ([]float32, error)
- func ReadLongMetrics(s *Session, ref uint8, timeout time.Duration) ([]int32, error)
- func ReadMetrics(s *Session, ref uint8, timeout time.Duration) ([]byte, error)
- func ReadParam(s *Session, ref uint8, timeout time.Duration) ([]byte, error)
- func RemovePath(s *Session, path string, timeout time.Duration) error
- func RenamePath(s *Session, from, to string, timeout time.Duration) error
- func SHA256File(s *Session, file string, timeout time.Duration) ([]byte, error)
- func SetParam(s *Session, name string, value []byte, timeout time.Duration) error
- func StartTrace(s *Session, timeout time.Duration) error
- func StopTrace(s *Session, timeout time.Duration) error
- func StreamLog(s *Session, stop chan struct{}, fn func(string)) error
- func Unpack(fmt string, buffer []byte) ([]any, error)
- func Update(s *Session, image []byte, report func(int), timeout time.Duration) error
- func WriteFile(s *Session, file string, data []byte, report func(uint32), ...) error
- func WriteParam(s *Session, ref uint8, value []byte, timeout time.Duration) error
- type Channel
- type Device
- type FSInfo
- type ManagedDevice
- func (d *ManagedDevice) Activate() error
- func (d *ManagedDevice) Active() bool
- func (d *ManagedDevice) Deactivate()
- func (d *ManagedDevice) Device() Device
- func (d *ManagedDevice) Events() (<-chan ManagedEvent, func())
- func (d *ManagedDevice) HasSession() bool
- func (d *ManagedDevice) Locked() bool
- func (d *ManagedDevice) NewSession() (*Session, error)
- func (d *ManagedDevice) Stop()
- func (d *ManagedDevice) Unlock(password string) (bool, error)
- func (d *ManagedDevice) UseSession(fn func(*Session) error) error
- type ManagedEvent
- type ManagedEventType
- type Message
- type MetricInfo
- type MetricKind
- type MetricLayout
- type MetricType
- type MetricsService
- type ParamInfo
- type ParamMode
- type ParamType
- type ParamUpdate
- type ParamsService
- func (s *ParamsService) All() iter.Seq2[ParamInfo, ParamUpdate]
- func (s *ParamsService) Collect(names ...string) error
- func (s *ParamsService) Get(name string) (ParamInfo, bool)
- func (s *ParamsService) Has(name string) bool
- func (s *ParamsService) List() error
- func (s *ParamsService) Read(name string, reload bool) ([]byte, error)
- func (s *ParamsService) Write(name string, value []byte) error
- type Queue
- type Result
- type Session
- func (s *Session) Channel() *Channel
- func (s *Session) End(timeout time.Duration) error
- func (s *Session) GetMTU(timeout time.Duration) (uint16, error)
- func (s *Session) ID() uint16
- func (s *Session) Ping(timeout time.Duration) error
- func (s *Session) Query(endpoint uint8, timeout time.Duration) (bool, error)
- func (s *Session) Receive(endpoint uint8, expectAck bool, timeout time.Duration) ([]byte, error)
- func (s *Session) Send(endpoint uint8, data []byte, ackTimeout time.Duration) error
- func (s *Session) Status(timeout time.Duration) (Status, error)
- func (s *Session) Unlock(password string, timeout time.Duration) (bool, error)
- type Status
- type TraceData
- type TraceEvent
- type TraceEventType
- type TraceLabel
- type TraceStatus
- type TraceTask
- type Transport
Constants ¶
const ( ParamModeVolatile = ParamMode(1 << 0) ParamModeSystem = ParamMode(1 << 1) ParamModeApplication = ParamMode(1 << 2) ParamModeLocked = ParamMode(1 << 4) )
The available parameter modes.
const (
StatusLocked = Status(1 << 0)
)
The available session status flags.
const SystemEndpoint = 0xFD
The SystemEndpoint number.
Variables ¶
var ( ErrSessionInvalidMessage = errors.New("invalid message") ErrSessionUnknownMessage = errors.New("unknown message") ErrSessionEndpointError = errors.New("endpoint error") ErrSessionLockedError = errors.New("session locked") ErrSessionWrongOwner = errors.New("wrong owner") ErrSessionExpectedAck = errors.New("expected ack") )
The available session errors.
var Ack = errors.New("acknowledgement")
Ack is an error returned when an acknowledgement is received.
var ErrManagedStopped = errors.New("managed device stopped")
ErrManagedStopped is returned when using a stopped managed device.
var ErrMetricNotFound = errors.New("metric not found")
var ErrParamNotFound = errors.New("param not found")
var ErrShortBuffer = errors.New("short buffer")
ErrShortBuffer is returned when the buffer is too short for unpacking.
var ErrTimeout = errors.New("timeout")
ErrTimeout is returned when a timeout occurs.
Functions ¶
func CheckCoredump ¶ added in v0.14.0
CheckCoredump returns the size and reason of the coredump.
func ClearParam ¶
ClearParam clears the value of the referenced parameter.
func DeleteCoredump ¶ added in v0.14.0
DeleteCoredump deletes the coredump.
func GeneratePerfetto ¶ added in v0.15.0
func GeneratePerfetto(tasks map[uint8]string, labels map[uint8]string, events []TraceEvent) ([]byte, error)
GeneratePerfetto converts trace data into the Chrome Trace Event Format (compatible with Perfetto). Task names and labels are provided as maps built from accumulated reads during the trace recording.
func Pack ¶ added in v0.13.2
Pack a byte buffer as specified by the format. The 's' format code does not write a null terminator; it must be the last code or followed by a field whose first byte is zero (e.g. a uint8 zero) to allow correct unpacking.
func ReadCoredump ¶ added in v0.14.0
ReadCoredump reads the coredump.
func ReadDoubleMetrics ¶
ReadDoubleMetrics reads double metrics.
func ReadFileRange ¶
func ReadFileRange(s *Session, file string, offset, length uint32, report func(uint32), timeout time.Duration) ([]byte, error)
ReadFileRange reads a range of bytes from a file.
func ReadFloatMetrics ¶
ReadFloatMetrics reads float metrics.
func ReadLongMetrics ¶
ReadLongMetrics reads long metrics.
func ReadMetrics ¶
ReadMetrics reads metrics.
func RemovePath ¶
RemovePath removes a file system entry.
func RenamePath ¶
RenamePath renames a file system entry.
func SHA256File ¶
SHA256File retrieves the SHA-256 hash of a file.
func StartTrace ¶ added in v0.15.0
StartTrace begins trace recording.
func StreamLog ¶ added in v0.14.0
StreamLog streams log messages and calls the provided function for each message until the stop channel is closed.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel routes raw transport traffic to subscribers based on session ownership.
func NewChannel ¶ added in v0.15.0
NewChannel wraps the provided transport in a session-aware channel.
func (*Channel) Close ¶
func (c *Channel) Close()
Close closes the channel and the underlying transport.
func (*Channel) Done ¶ added in v0.15.0
func (c *Channel) Done() <-chan struct{}
Done is closed when the underlying transport reader exits.
func (*Channel) Unsubscribe ¶
Unsubscribe removes a queue from the subscriber list.
type Device ¶
type Device interface {
// ID returns a stable identifier for the device.
ID() string
// Type returns the device transport type.
Type() string
// Name returns a user-facing device name.
Name() string
// Open opens a channel to the device. An opened channel must fail or be
// closed before another channel can be opened.
Open() (*Channel, error)
}
Device represents a device that can be communicated with.
type FSInfo ¶
FSInfo describes a file system entry.
type ManagedDevice ¶
type ManagedDevice struct {
// contains filtered or unexported fields
}
ManagedDevice represents a managed device.
func NewManagedDevice ¶
func NewManagedDevice(dev Device) *ManagedDevice
NewManagedDevice creates a new managed device.
func (*ManagedDevice) Activate ¶
func (d *ManagedDevice) Activate() error
Activate activates the device.
func (*ManagedDevice) Active ¶
func (d *ManagedDevice) Active() bool
Active returns whether the device is active.
func (*ManagedDevice) Deactivate ¶
func (d *ManagedDevice) Deactivate()
Deactivate deactivates the device.
func (*ManagedDevice) Device ¶
func (d *ManagedDevice) Device() Device
Device returns the underlying device.
func (*ManagedDevice) Events ¶ added in v0.15.0
func (d *ManagedDevice) Events() (<-chan ManagedEvent, func())
Events returns a new event channel and a cancel function. The channel is buffered (4) and drops events if the consumer is too slow. Call cancel to unsubscribe and close the channel.
func (*ManagedDevice) HasSession ¶ added in v0.15.0
func (d *ManagedDevice) HasSession() bool
HasSession returns whether the device has a managed session.
func (*ManagedDevice) Locked ¶
func (d *ManagedDevice) Locked() bool
Locked returns whether the device is locked. The value is determined during session opening and may not reflect the current state.
func (*ManagedDevice) NewSession ¶
func (d *ManagedDevice) NewSession() (*Session, error)
NewSession creates a new session.
func (*ManagedDevice) Unlock ¶ added in v0.15.0
func (d *ManagedDevice) Unlock(password string) (bool, error)
Unlock will attempt to unlock the device and returns its success. The password is stored for auto-unlock on success.
func (*ManagedDevice) UseSession ¶
func (d *ManagedDevice) UseSession(fn func(*Session) error) error
UseSession uses the managed session.
type ManagedEvent ¶ added in v0.15.0
type ManagedEvent struct {
Type ManagedEventType
}
ManagedEvent represents a lifecycle event from a managed device.
type ManagedEventType ¶ added in v0.15.0
type ManagedEventType int
ManagedEventType represents the type of a managed device event.
const ( // ManagedConnected is emitted after a successful activate transition. ManagedConnected ManagedEventType = iota // ManagedDisconnected is emitted on unexpected transport loss. ManagedDisconnected )
type Message ¶
Message represents a message exchanged between a device and a client.
type MetricInfo ¶
type MetricInfo struct {
Ref uint8
Kind MetricKind
Type MetricType
Name string
Size uint8
}
MetricInfo describes a metric.
func ListMetrics ¶
func ListMetrics(s *Session, timeout time.Duration) ([]MetricInfo, error)
ListMetrics lists all metrics.
type MetricKind ¶
type MetricKind uint8
MetricKind represents a metric kind.
const ( MetricKindCounter MetricKind = iota MetricKindGauge )
The available metric kinds.
type MetricLayout ¶
MetricLayout describes a metric layout.
func DescribeMetric ¶
DescribeMetric describes a metric.
type MetricType ¶
type MetricType uint8
MetricType represents a metric type.
const ( MetricTypeLong MetricType = iota MetricTypeFloat MetricTypeDouble )
The available metric types.
type MetricsService ¶ added in v0.14.0
type MetricsService struct {
// contains filtered or unexported fields
}
func NewMetricsService ¶ added in v0.14.0
func NewMetricsService(session *Session) *MetricsService
func (*MetricsService) All ¶ added in v0.14.0
func (s *MetricsService) All() iter.Seq2[MetricInfo, MetricLayout]
func (*MetricsService) Get ¶ added in v0.14.0
func (s *MetricsService) Get(name string) (MetricInfo, bool)
func (*MetricsService) Has ¶ added in v0.14.0
func (s *MetricsService) Has(name string) bool
func (*MetricsService) List ¶ added in v0.14.0
func (s *MetricsService) List() error
type ParamType ¶
type ParamType uint8
ParamType represents a parameter type.
type ParamUpdate ¶
ParamUpdate describes a parameter update.
func CollectParams ¶
func CollectParams(s *Session, refs []uint8, since uint64, timeout time.Duration) ([]ParamUpdate, error)
CollectParams returns a list of parameter updates.
type ParamsService ¶ added in v0.14.0
type ParamsService struct {
// contains filtered or unexported fields
}
func NewParamsService ¶ added in v0.14.0
func NewParamsService(session *Session) *ParamsService
func (*ParamsService) All ¶ added in v0.14.0
func (s *ParamsService) All() iter.Seq2[ParamInfo, ParamUpdate]
func (*ParamsService) Collect ¶ added in v0.14.0
func (s *ParamsService) Collect(names ...string) error
func (*ParamsService) Get ¶ added in v0.14.0
func (s *ParamsService) Get(name string) (ParamInfo, bool)
func (*ParamsService) Has ¶ added in v0.14.0
func (s *ParamsService) Has(name string) bool
func (*ParamsService) List ¶ added in v0.14.0
func (s *ParamsService) List() error
type Result ¶ added in v0.14.0
Result represents the result of a command execution.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a communication session with a NAOS device.
A Session must not be used concurrently from multiple goroutines. The internal mutex only serializes individual queue operations; multi-step request/response exchanges must still be driven by a single caller.
func OpenSession ¶
OpenSession opens a new session using the specified channel and waits up to the provided timeout for the initial session reply.
func (*Session) GetMTU ¶
GetMTU returns the maximum transmission unit of the session. The value is cached after the first successful retrieval.
func (*Session) Receive ¶
Receive waits for a message on the specified endpoint.
Receive must not be called concurrently with any other Session method.
func (*Session) Send ¶
Send sends a message to the specified endpoint.
Send must not be called concurrently with any other Session method.
type TraceData ¶ added in v0.15.0
type TraceData struct {
Tasks []TraceTask
Labels []TraceLabel
Events []TraceEvent
}
TraceData holds the result of a trace read operation.
type TraceEvent ¶ added in v0.15.0
type TraceEvent struct {
Timestamp uint32 // microseconds since trace start
Type TraceEventType // event type
Core uint8 // CPU core (SWITCH only)
Task uint8 // task ID (SWITCH only)
Cat uint8 // category label ID (INSTANT/BEGIN only)
Name uint8 // name label ID (INSTANT/BEGIN/VALUE only)
Arg uint16 // user argument (INSTANT/BEGIN only)
Span uint8 // span instance ID (BEGIN/END only)
Value int32 // counter/gauge value (VALUE only)
}
TraceEvent represents a single trace event.
type TraceEventType ¶ added in v0.15.0
type TraceEventType uint8
TraceEventType represents a trace event type.
const ( TraceTaskSwitch TraceEventType = 1 TraceInstant TraceEventType = 2 TraceBegin TraceEventType = 3 TraceEnd TraceEventType = 4 TraceValue TraceEventType = 5 )
The available trace event types.
type TraceLabel ¶ added in v0.15.0
TraceLabel describes a label in the trace label table.
type TraceStatus ¶ added in v0.15.0
TraceStatus represents the trace buffer status.
func GetTraceStatus ¶ added in v0.15.0
func GetTraceStatus(s *Session, timeout time.Duration) (*TraceStatus, error)
GetTraceStatus returns the current trace buffer status.