msg

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ParamModeVolatile    = ParamMode(1 << 0)
	ParamModeSystem      = ParamMode(1 << 1)
	ParamModeApplication = ParamMode(1 << 2)
	ParamModeLocked      = ParamMode(1 << 4)
)

The available parameter modes.

View Source
const (
	StatusLocked = Status(1 << 0)
)

The available session status flags.

View Source
const SystemEndpoint = 0xFD

The SystemEndpoint number.

Variables

View Source
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.

View Source
var Ack = errors.New("acknowledgement")

Ack is an error returned when an acknowledgement is received.

View Source
var ErrManagedStopped = errors.New("managed device stopped")

ErrManagedStopped is returned when using a stopped managed device.

View Source
var ErrMetricNotFound = errors.New("metric not found")
View Source
var ErrParamNotFound = errors.New("param not found")
View Source
var ErrShortBuffer = errors.New("short buffer")

ErrShortBuffer is returned when the buffer is too short for unpacking.

View Source
var ErrTimeout = errors.New("timeout")

ErrTimeout is returned when a timeout occurs.

Functions

func CheckCoredump added in v0.14.0

func CheckCoredump(s *Session, timeout time.Duration) (uint32, string, error)

CheckCoredump returns the size and reason of the coredump.

func ClearParam

func ClearParam(s *Session, ref uint8, timeout time.Duration) error

ClearParam clears the value of the referenced parameter.

func DeleteCoredump added in v0.14.0

func DeleteCoredump(s *Session, timeout time.Duration) error

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 GetParam

func GetParam(s *Session, name string, timeout time.Duration) ([]byte, error)

GetParam returns the value of the named parameter.

func MakePath added in v0.13.2

func MakePath(s *Session, path string, timeout time.Duration) error

MakePath creates a directory path.

func Pack added in v0.13.2

func Pack(fmt string, args ...any) []byte

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

func ReadCoredump(s *Session, offset, length uint32, timeout time.Duration) ([]byte, error)

ReadCoredump reads the coredump.

func ReadDoubleMetrics

func ReadDoubleMetrics(s *Session, ref uint8, timeout time.Duration) ([]float64, error)

ReadDoubleMetrics reads double metrics.

func ReadFile

func ReadFile(s *Session, file string, report func(uint32), timeout time.Duration) ([]byte, error)

ReadFile reads the contents of a file.

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

func ReadFloatMetrics(s *Session, ref uint8, timeout time.Duration) ([]float32, error)

ReadFloatMetrics reads float metrics.

func ReadLongMetrics

func ReadLongMetrics(s *Session, ref uint8, timeout time.Duration) ([]int32, error)

ReadLongMetrics reads long metrics.

func ReadMetrics

func ReadMetrics(s *Session, ref uint8, timeout time.Duration) ([]byte, error)

ReadMetrics reads metrics.

func ReadParam

func ReadParam(s *Session, ref uint8, timeout time.Duration) ([]byte, error)

ReadParam return the value of the referenced parameter.

func RemovePath

func RemovePath(s *Session, path string, timeout time.Duration) error

RemovePath removes a file system entry.

func RenamePath

func RenamePath(s *Session, from, to string, timeout time.Duration) error

RenamePath renames a file system entry.

func SHA256File

func SHA256File(s *Session, file string, timeout time.Duration) ([]byte, error)

SHA256File retrieves the SHA-256 hash of a file.

func SetParam

func SetParam(s *Session, name string, value []byte, timeout time.Duration) error

SetParam sets the value of the named parameter.

func StartTrace added in v0.15.0

func StartTrace(s *Session, timeout time.Duration) error

StartTrace begins trace recording.

func StopTrace added in v0.15.0

func StopTrace(s *Session, timeout time.Duration) error

StopTrace stops trace recording.

func StreamLog added in v0.14.0

func StreamLog(s *Session, stop chan struct{}, fn func(string)) error

StreamLog streams log messages and calls the provided function for each message until the stop channel is closed.

func Unpack added in v0.13.2

func Unpack(fmt string, buffer []byte) ([]any, error)

Unpack a byte buffer as specified by the format.

func Update

func Update(s *Session, image []byte, report func(int), timeout time.Duration) error

Update performs a firmware update.

func WriteFile

func WriteFile(s *Session, file string, data []byte, report func(uint32), timeout time.Duration) error

WriteFile writes data to a file.

func WriteParam

func WriteParam(s *Session, ref uint8, value []byte, timeout time.Duration) error

WriteParam sets the value of the referenced parameter.

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

func NewChannel(tr Transport, dev Device, width int) *Channel

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) Device

func (c *Channel) Device() Device

Device returns the underlying device if available.

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) Subscribe

func (c *Channel) Subscribe(queue Queue)

Subscribe registers a queue to receive incoming messages.

func (*Channel) Unsubscribe

func (c *Channel) Unsubscribe(queue Queue)

Unsubscribe removes a queue from the subscriber list.

func (*Channel) Width added in v0.13.2

func (c *Channel) Width() int

Width returns the maximum number of inflight messages.

func (*Channel) Write

func (c *Channel) Write(queue Queue, msg Message) error

Write sends a single framed message on behalf of a specific queue. A nil queue means the write has no subscriber ownership context.

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

type FSInfo struct {
	Name  string
	IsDir bool
	Size  uint32
}

FSInfo describes a file system entry.

func ListDir

func ListDir(s *Session, dir string, timeout time.Duration) ([]FSInfo, error)

ListDir retrieves a list of file system entries in a directory.

func StatPath

func StatPath(s *Session, path string, timeout time.Duration) (*FSInfo, error)

StatPath retrieves information about 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) Stop

func (d *ManagedDevice) Stop()

Stop stops device management.

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

type Message struct {
	Session  uint16
	Endpoint uint8
	Data     []byte
}

Message represents a message exchanged between a device and a client.

func Parse added in v0.15.0

func Parse(data []byte) (Message, bool)

Parse decodes raw message bytes.

func (*Message) Build added in v0.15.0

func (m *Message) Build() []byte

Build encodes the message to its wire format.

func (*Message) Size

func (m *Message) Size() int

Size returns the size of the message.

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

type MetricLayout struct {
	Keys   []string
	Values [][]string
}

MetricLayout describes a metric layout.

func DescribeMetric

func DescribeMetric(s *Session, ref uint8, timeout time.Duration) (*MetricLayout, error)

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 (*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

func (*MetricsService) Read added in v0.14.0

func (s *MetricsService) Read(name string) ([]float64, error)

type ParamInfo

type ParamInfo struct {
	Ref  uint8
	Type ParamType
	Mode ParamMode
	Name string
}

ParamInfo describes a parameter.

func ListParams

func ListParams(s *Session, timeout time.Duration) ([]ParamInfo, error)

ListParams returns a list of all parameters.

type ParamMode

type ParamMode uint8

ParamMode represents a parameter mode.

func (ParamMode) Valid

func (m ParamMode) Valid() bool

Valid returns whether the parameter mode is valid.

type ParamType

type ParamType uint8

ParamType represents a parameter type.

const (
	ParamTypeRaw ParamType = iota
	ParamTypeString
	ParamTypeBool
	ParamTypeLong
	ParamTypeDouble
	ParamTypeAction
)

The available parameter types.

func (ParamType) Valid

func (t ParamType) Valid() bool

Valid returns whether the parameter type is valid.

type ParamUpdate

type ParamUpdate struct {
	Ref   uint8
	Age   uint64
	Value []byte
}

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 (*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

func (*ParamsService) Read added in v0.14.0

func (s *ParamsService) Read(name string, reload bool) ([]byte, error)

func (*ParamsService) Write added in v0.14.0

func (s *ParamsService) Write(name string, value []byte) error

type Queue

type Queue chan Message

Queue is used to receive messages from a channel.

func (Queue) Read added in v0.15.0

func (q Queue) Read(timeout time.Duration) (Message, error)

Read reads a message from the queue.

type Result added in v0.14.0

type Result struct {
	Value any
	Error error
}

Result represents the result of a command execution.

func Execute added in v0.14.0

func Execute(list []Device, parallel int, fn func(s *Session) (any, error)) []Result

Execute will run the provided function for all devices in the list with the specified level of parallelism. It will return a list of results in the same order as the provided device list.

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

func OpenSession(channel *Channel, timeout time.Duration) (*Session, error)

OpenSession opens a new session using the specified channel and waits up to the provided timeout for the initial session reply.

func (*Session) Channel added in v0.13.2

func (s *Session) Channel() *Channel

Channel returns the channel used by the session.

func (*Session) End

func (s *Session) End(timeout time.Duration) error

End closes the session.

func (*Session) GetMTU

func (s *Session) GetMTU(timeout time.Duration) (uint16, error)

GetMTU returns the maximum transmission unit of the session. The value is cached after the first successful retrieval.

func (*Session) ID

func (s *Session) ID() uint16

ID returns the session ID.

func (*Session) Ping

func (s *Session) Ping(timeout time.Duration) error

Ping verifies and keeps the session alive.

func (*Session) Query

func (s *Session) Query(endpoint uint8, timeout time.Duration) (bool, error)

Query tests existence of an endpoint.

func (*Session) Receive

func (s *Session) Receive(endpoint uint8, expectAck bool, timeout time.Duration) ([]byte, error)

Receive waits for a message on the specified endpoint.

Receive must not be called concurrently with any other Session method.

func (*Session) Send

func (s *Session) Send(endpoint uint8, data []byte, ackTimeout time.Duration) error

Send sends a message to the specified endpoint.

Send must not be called concurrently with any other Session method.

func (*Session) Status

func (s *Session) Status(timeout time.Duration) (Status, error)

Status returns the status of the session.

func (*Session) Unlock

func (s *Session) Unlock(password string, timeout time.Duration) (bool, error)

Unlock unlocks the session with the specified password.

type Status

type Status uint8

Status represents the status of a session.

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.

func ReadTrace added in v0.15.0

func ReadTrace(s *Session, timeout time.Duration) (*TraceData, error)

ReadTrace reads buffered trace events and any new task/label mappings.

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

type TraceLabel struct {
	ID   uint8
	Text string
}

TraceLabel describes a label in the trace label table.

type TraceStatus added in v0.15.0

type TraceStatus struct {
	Active  bool
	BufSize uint32
	BufUsed uint32
	Dropped uint32
}

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.

type TraceTask added in v0.15.0

type TraceTask struct {
	ID   uint8
	Name string
}

TraceTask describes a task in the trace task table.

type Transport added in v0.15.0

type Transport interface {
	Read() ([]byte, error)
	Write([]byte) error
	Close()
}

Transport exchanges raw messages with a device or peer.

Jump to

Keyboard shortcuts

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