transport

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WaitAfterWake is the amount of time to wait after sending the wake message before sending the first message.
	WaitAfterWake = 100 * time.Millisecond
	// Start1 is a magic byte used in the meshtastic stream protocol.
	// Start1 is sent at the beginning of a message to indicate the start of a new message.
	Start1 = 0x94
	// Start2 is a magic byte used in the meshtastic stream protocol.
	// It is sent after Start1 to indicate the start of a new message.
	Start2 = 0xc3
	// PacketMTU is the maximum size of the protobuf message which can be sent within the header.
	PacketMTU = 512
)

Variables

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

Functions

This section is empty.

Types

type Client

type Client struct {
	State State
	// contains filtered or unexported fields
}

func NewClient

func NewClient(sc *StreamConn, errorOnNoHandler bool) *Client

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Handle

func (c *Client) Handle(kind proto.Message, handler MessageHandler)

func (*Client) SendToRadio

func (c *Client) SendToRadio(msg *meshtastic.ToRadio) error

type HandlerFunc

type HandlerFunc func(message proto.Message)

type HandlerRegistry

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

HandlerRegistry holds registered handlers for protobuf messages.

func NewHandlerRegistry

func NewHandlerRegistry(errorOnNoHandler bool) *HandlerRegistry

New creates a new instance of HandlerRegistry. Set errorOnNoHandler to true if you want HandleMessage to return an error if there are no handlers registered for a given msg when HandleMessage is called.

func (*HandlerRegistry) HandleMessage

func (r *HandlerRegistry) HandleMessage(msg proto.Message) error

HandleMessage invokes all registered handlers for the provided protobuf message, in the order they were registered.

func (*HandlerRegistry) RegisterHandler

func (r *HandlerRegistry) RegisterHandler(msg proto.Message, handler MessageHandler)

RegisterHandler registers a handler for a specific protobuf message type.

type MessageHandler

type MessageHandler func(msg proto.Message)

MessageHandler defines the function signature for a handler that processes a protobuf message.

type State

type State struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*State) AddChannel

func (s *State) AddChannel(channel *meshtastic.Channel)

func (*State) AddConfig

func (s *State) AddConfig(config *meshtastic.Config)

func (*State) AddModule

func (s *State) AddModule(module *meshtastic.ModuleConfig)

func (*State) AddNode

func (s *State) AddNode(node *meshtastic.NodeInfo)

func (*State) Channels

func (s *State) Channels() []*meshtastic.Channel

func (*State) Complete

func (s *State) Complete() bool

func (*State) ConfigID

func (s *State) ConfigID() uint32

func (*State) Configs

func (s *State) Configs() []*meshtastic.Config

func (*State) DeviceMetadata

func (s *State) DeviceMetadata() *meshtastic.DeviceMetadata

func (*State) Modules

func (s *State) Modules() []*meshtastic.ModuleConfig

func (*State) NodeInfo

func (s *State) NodeInfo() *meshtastic.MyNodeInfo

func (*State) Nodes

func (s *State) Nodes() []*meshtastic.NodeInfo

func (*State) SetComplete

func (s *State) SetComplete(complete bool)

func (*State) SetConfigID

func (s *State) SetConfigID(configID uint32)

func (*State) SetDeviceMetadata

func (s *State) SetDeviceMetadata(deviceMetadata *meshtastic.DeviceMetadata)

func (*State) SetNodeInfo

func (s *State) SetNodeInfo(nodeInfo *meshtastic.MyNodeInfo)

type StreamConn

type StreamConn struct {

	// DebugWriter is an optional writer that is used when a non-protobuf message is sent over the connection.
	DebugWriter io.Writer
	// contains filtered or unexported fields
}

StreamConn implements the meshtastic client API stream protocol. This protocol is used to send and receive protobuf messages over a serial or TCP connection. See https://meshtastic.org/docs/development/device/client-api#streaming-version for additional information.

func NewClientStreamConn

func NewClientStreamConn(conn io.ReadWriteCloser) (*StreamConn, error)

NewClientStreamConn creates a new StreamConn with the provided io.ReadWriteCloser. Once an io.ReadWriteCloser is provided, the StreamConn should be used read, write and close operations.

func NewRadioStreamConn

func NewRadioStreamConn(conn io.ReadWriteCloser) *StreamConn

NewRadioStreamConn creates a new StreamConn with the provided io.ReadWriteCloser. Once an io.ReadWriteCloser is provided, the StreamConn should be used read, write and close operations.

func (*StreamConn) Close

func (c *StreamConn) Close() (err error)

Close closes the connection.

func (*StreamConn) Read

func (c *StreamConn) Read(out proto.Message) error

Read reads a protobuf message from the connection.

func (*StreamConn) ReadBytes

func (c *StreamConn) ReadBytes() ([]byte, error)

ReadBytes reads a byte message from the connection. Prefer using Read if you have a protobuf message.

func (*StreamConn) Write

func (c *StreamConn) Write(in proto.Message) error

Write writes a protobuf message to the connection.

func (*StreamConn) WriteBytes

func (c *StreamConn) WriteBytes(data []byte) error

WriteBytes writes a byte slice to the connection. Prefer using Write if you have a protobuf message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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