msg

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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 (
	SessionInvalidMessage = errors.New("invalid message")
	SessionUnknownMessage = errors.New("unknown message")
	SessionEndpointError  = errors.New("endpoint error")
	SessionLockedError    = errors.New("session locked")
	SessionExpectedAck    = 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.

Functions

func ClearParam

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

ClearParam clears the value of the referenced parameter.

func GetParam

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

GetParam returns the value of the named parameter.

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 Update

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

Update performs a firmware update.

func Write

func Write(ch Channel, msg Message) error

Write writes a message to the channel.

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 interface {
	Device() Device
	Subscribe(Queue)
	Unsubscribe(Queue)
	Write([]byte) error
	Close()
}

Channel provides the mechanism to exchange messages between a device and a client.

type Device

type Device interface {
	// ID returns a stable identifier for the device.
	ID() 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.

func NewHTTPDevice

func NewHTTPDevice(host string) Device

NewHTTPDevice creates a new HTTP device.

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

func (d *ManagedDevice) Locked() bool

Locked returns whether the device is locked.

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

func (d *ManagedDevice) UseSession(fn func(*Session) error) error

UseSession uses the managed session.

type Message

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

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

func Read

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

Read reads a message from the queue.

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 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 Queue

type Queue chan []byte

Queue is used to receive messages from a channel.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents a communication session with a NAOS device.

func OpenSession

func OpenSession(channel Channel) (*Session, error)

OpenSession opens a new session using the specified channel.

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)

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.

func (*Session) Send

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

Send sends a message to the specified endpoint.

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.

Jump to

Keyboard shortcuts

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