moteconnection

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 27 Imported by: 2

README

go-moteconnection

SmartDust mote serial and SerialForwarder connection library for go.

Supports the TinyOS-inspired serial and serial-forwarder transports.

sforwarder

sforwarder is a go implementation of the serial-forwarder application with some additional features:

  • sforwarder correctly increments sequence numbers
  • sforwarder will recover from a UART/USB disconnect
  • sforwarder can act as a server or client on both ends
  • sforwarder can also forward a TCP source connection

sforwarder can be cross-compiled (see the sforwarder/Makefile) and packaged as a Debian package with dpkg-buildpackage -b --no-sign.

sfserver

sfserver creates a serial-forwarder server that prints out received packets. May be useful for debugging other applications wanting to connect to a network.

amlistener

amlistener connects to a serial-forwarder server and prints out received ActiveMessage packets (dispatcher 0x00).

https://github.com/proactivity-lab/go-amlistener

Documentation

Overview

Serial Smart Dust Mote connection.

Package moteconnection - A SerialForwarder connection library.

Package moteconnection - A SerialForwarder connection library.

Index

Constants

View Source
const IncomingBufferSize = 10

Variables

View Source
var File_mist_cloud_comm_mist_proto protoreflect.FileDescriptor

Functions

func DeserializePacket

func DeserializePacket(m interface{}, data []byte) error

DeserializePacket turns a bunch of bytes into the provided structure, if possible

func ListSerialPorts

func ListSerialPorts() ([]string, error)

func SerializePacket

func SerializePacket(m interface{}) []byte

SerializePacket turns a relatively generic structure into a bunch of bytes

Types

type AMAddr

type AMAddr uint16

AMAddr an address that should be represented as %04X

func (AMAddr) MarshalFlag

func (addr AMAddr) MarshalFlag() (string, error)

MarshalFlag marshals AMAddr for the flags library

func (AMAddr) String

func (addr AMAddr) String() string

func (*AMAddr) UnmarshalFlag

func (addr *AMAddr) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals AMAddr for the flags library

type AMGroup

type AMGroup uint8

AMGroup a group ID that should be represented as %02X

func (AMGroup) MarshalFlag

func (grp AMGroup) MarshalFlag() (string, error)

MarshalFlag marshals AMGroup for the flags library

func (AMGroup) String

func (grp AMGroup) String() string

func (*AMGroup) UnmarshalFlag

func (grp *AMGroup) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals AMGroup for the flags library

type AMID

type AMID uint8

AMID an ID that should be represented as %02X

func (AMID) MarshalFlag

func (aid AMID) MarshalFlag() (string, error)

MarshalFlag marshals AMID for the flags library

func (AMID) String

func (aid AMID) String() string

func (*AMID) UnmarshalFlag

func (aid *AMID) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals AMID for the flags library

type BaseMoteConnection

type BaseMoteConnection struct {
	loggers.DIWEloggers
	// contains filtered or unexported fields
}

BaseMoteConnection structure

func (*BaseMoteConnection) AddDispatcher

func (bmc *BaseMoteConnection) AddDispatcher(dispatcher Dispatcher) error

AddDispatcher adds a dispatcher to the connection

func (*BaseMoteConnection) Connected

func (bmc *BaseMoteConnection) Connected() bool

Connected checks if the connection is connected

func (*BaseMoteConnection) Disconnect

func (bmc *BaseMoteConnection) Disconnect()

Disconnect disconnects the connection or stops a server

func (*BaseMoteConnection) RemoveDispatcher

func (bmc *BaseMoteConnection) RemoveDispatcher(dispatcher Dispatcher) error

RemoveDispatcher removes a dispatcher from the connection

func (*BaseMoteConnection) Send

func (bmc *BaseMoteConnection) Send(msg Packet) error

Send sends a packet

type Dispatcher

type Dispatcher interface {
	Dispatch() byte
	Receive([]byte) error
	NewPacket() Packet
}

Dispatcher interface

type EUI64

type EUI64 uint64

EUI64 address %016X

func (EUI64) MarshalFlag

func (eui64 EUI64) MarshalFlag() (string, error)

MarshalFlag marshals EUI64 for the flags library

func (EUI64) String

func (eui64 EUI64) String() string

func (*EUI64) UnmarshalFlag

func (eui64 *EUI64) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals EUI64 for the flags library

type HexByte

type HexByte byte

HexByte a byte object that should be converted to string with %02X

func (HexByte) MarshalFlag

func (hxb HexByte) MarshalFlag() (string, error)

MarshalFlag marshals HexByte for the flags library

func (HexByte) String

func (hxb HexByte) String() string

func (*HexByte) UnmarshalFlag

func (hxb *HexByte) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals HexByte for the flags library

type HexString

type HexString []byte

HexString a bunch of bytes that should be converted to string with %02X

func (HexString) MarshalFlag

func (hxs HexString) MarshalFlag() (string, error)

MarshalFlag marshals HexStrings for the flags library

func (HexString) String

func (hxs HexString) String() string

func (*HexString) UnmarshalFlag

func (hxs *HexString) UnmarshalFlag(value string) error

UnmarshalFlag unmarshals HexByte for the flags library

type LinkQualitySignalStrengthFooter

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

type Message

type Message struct {
	Payload []byte
	Footer  []byte

	LQI  uint8 // LQI is set if footer is exactly 2 bytes long
	RSSI int8  // RSSI is set if footer is exactly 2 bytes long
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(defaultGroup AMGroup, defaultSource AMAddr) *Message

func (*Message) Deserialize

func (self *Message) Deserialize(data []byte) error

func (*Message) Destination

func (self *Message) Destination() AMAddr

func (*Message) Dispatch

func (self *Message) Dispatch() byte

func (*Message) GetPayload

func (self *Message) GetPayload() []byte

func (*Message) Group

func (self *Message) Group() AMGroup

func (*Message) NewPacket

func (self *Message) NewPacket() Packet

Message also serves as a factory.

func (*Message) Serialize

func (self *Message) Serialize() ([]byte, error)

func (*Message) SetDestination

func (self *Message) SetDestination(destination AMAddr)

func (*Message) SetDispatch

func (self *Message) SetDispatch(dispatch byte)

func (*Message) SetGroup

func (self *Message) SetGroup(group AMGroup)

func (*Message) SetPayload

func (self *Message) SetPayload(payload []byte) error

func (*Message) SetSource

func (self *Message) SetSource(source AMAddr)

func (*Message) SetType

func (self *Message) SetType(ptype AMID)

func (*Message) Source

func (self *Message) Source() AMAddr

func (*Message) String

func (self *Message) String() string

func (*Message) Type

func (self *Message) Type() AMID

type MessageDispatcher

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

MessageDispatcher structure

func NewMessageDispatcher

func NewMessageDispatcher(packetfactory MessageDispatcherMessage) *MessageDispatcher

NewMessageDispatcher creates a new dispatcher

func (*MessageDispatcher) DeregisterMessageReceiver

func (md *MessageDispatcher) DeregisterMessageReceiver(amid AMID) error

DeregisterMessageReceiver removes a receiver

func (*MessageDispatcher) Dispatch

func (md *MessageDispatcher) Dispatch() byte

Dispatch returns the dispatch ID of the dispatcher instance

func (*MessageDispatcher) NewMessage

func (md *MessageDispatcher) NewMessage() *Message

NewMessage initializes a new message for use with this dispatcher

func (*MessageDispatcher) NewPacket

func (md *MessageDispatcher) NewPacket() Packet

NewPacket initializes a new packet for use with this dispatcher

func (*MessageDispatcher) Receive

func (md *MessageDispatcher) Receive(msg []byte) error

Receive distributes a packet to receivers and snoopers

func (*MessageDispatcher) RegisterMessageReceiver

func (md *MessageDispatcher) RegisterMessageReceiver(amid AMID, receiver chan Packet) error

RegisterMessageReceiver registers a receiver

func (*MessageDispatcher) RegisterMessageSnooper

func (md *MessageDispatcher) RegisterMessageSnooper(receiver chan Packet) error

RegisterMessageSnooper registers a snooper

type MessageDispatcherMessage

type MessageDispatcherMessage interface {
	Packet
	Type() AMID
	NewPacket() Packet
}

type MistCloudConnection

type MistCloudConnection struct {
	BaseMoteConnection
	// contains filtered or unexported fields
}

The MistCloudConnection object structure

func NewMistCloudConnection

func NewMistCloudConnection(rabbiturl string) *MistCloudConnection

NewMistCloudConnection - Create a new MistCloudConnection

func (*MistCloudConnection) AddNode

func (mcc *MistCloudConnection) AddNode(eui EUI64)

func (*MistCloudConnection) Autoconnect

func (mcc *MistCloudConnection) Autoconnect(period time.Duration)

func (*MistCloudConnection) Configure

func (mcc *MistCloudConnection) Configure(name string, gateway EUI64)

func (*MistCloudConnection) Connect

func (mcc *MistCloudConnection) Connect() error

Connect to the cloud

func (*MistCloudConnection) Listen

func (mcc *MistCloudConnection) Listen() error

func (*MistCloudConnection) RegisterReceiver

func (mdr *MistCloudConnection) RegisterReceiver(rchan chan Packet)

func (*MistCloudConnection) RemoveNode

func (mcc *MistCloudConnection) RemoveNode(eui EUI64)

func (*MistCloudConnection) Send

func (mcc *MistCloudConnection) Send(msg Packet) error

type MistMessage

type MistMessage struct {
	Gateway     uint64               `protobuf:"fixed64,1,opt,name=gateway,proto3" json:"gateway,omitempty"`         // EUI64 of the gateway that the message is travelling through
	Destination uint64               `protobuf:"fixed64,2,opt,name=destination,proto3" json:"destination,omitempty"` // EUI64 of the destination
	Source      uint64               `protobuf:"fixed64,3,opt,name=source,proto3" json:"source,omitempty"`           // EUI64 of the source
	Payload     []byte               `protobuf:"bytes,4,opt,name=payload,proto3" json:"payload,omitempty"`           // Message payload
	Amid        uint32               `protobuf:"varint,5,opt,name=amid,proto3" json:"amid,omitempty"`                // uint16 - extended Active Message ID
	Rssi        int32                `protobuf:"varint,6,opt,name=rssi,proto3" json:"rssi,omitempty"`                // int8 - message RSSI (dB), -128 when not available
	Lqi         uint32               `protobuf:"varint,7,opt,name=lqi,proto3" json:"lqi,omitempty"`                  // uint8 - message LQI (0-255), 0 when not available
	Group       uint32               `protobuf:"varint,8,opt,name=group,proto3" json:"group,omitempty"`              // uint16 - extended Active Message Group or PAN ID
	Channel     uint32               `protobuf:"varint,9,opt,name=channel,proto3" json:"channel,omitempty"`          // uint8 - radio channel
	Timestamp   *timestamp.Timestamp `protobuf:"bytes,10,opt,name=timestamp,proto3" json:"timestamp,omitempty"`      // Timestamp of the message as it entered the Mist daemon
	// contains filtered or unexported fields
}

[START messages]

func (*MistMessage) Descriptor deprecated

func (*MistMessage) Descriptor() ([]byte, []int)

Deprecated: Use MistMessage.ProtoReflect.Descriptor instead.

func (*MistMessage) GetAmid

func (x *MistMessage) GetAmid() uint32

func (*MistMessage) GetChannel

func (x *MistMessage) GetChannel() uint32

func (*MistMessage) GetDestination

func (x *MistMessage) GetDestination() uint64

func (*MistMessage) GetGateway

func (x *MistMessage) GetGateway() uint64

func (*MistMessage) GetGroup

func (x *MistMessage) GetGroup() uint32

func (*MistMessage) GetLqi

func (x *MistMessage) GetLqi() uint32

func (*MistMessage) GetPayload

func (x *MistMessage) GetPayload() []byte

func (*MistMessage) GetRssi

func (x *MistMessage) GetRssi() int32

func (*MistMessage) GetSource

func (x *MistMessage) GetSource() uint64

func (*MistMessage) GetTimestamp

func (x *MistMessage) GetTimestamp() *timestamp.Timestamp

func (*MistMessage) ProtoMessage

func (*MistMessage) ProtoMessage()

func (*MistMessage) ProtoReflect

func (x *MistMessage) ProtoReflect() protoreflect.Message

func (*MistMessage) Reset

func (x *MistMessage) Reset()

func (*MistMessage) String

func (x *MistMessage) String() string

type MistMessageDispatcher

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

MessageDispatcher structure

func (*MistMessageDispatcher) Dispatch

func (md *MistMessageDispatcher) Dispatch() byte

Dispatch returns the dispatch ID of the dispatcher instance

func (*MistMessageDispatcher) NewPacket

func (md *MistMessageDispatcher) NewPacket() Packet

NewPacket initializes a new packet for use with this dispatcher

type MoteConnection

type MoteConnection interface {
	loggers.DIWElog
	Listen() error
	Connect() error
	Autoconnect(period time.Duration)
	Send(msg Packet) error
	AddDispatcher(dispatcher Dispatcher) error
	RemoveDispatcher(dispatch Dispatcher) error
	Connected() bool
	Disconnect()
}

MoteConnection interface

func CreateConnection

func CreateConnection(connectionstring string) (MoteConnection, string, error)

CreateConnection - create a connection based on the format string

type MoteMistMessage

type MoteMistMessage struct {
	Payload []byte
	Footer  []byte

	LQI  uint8
	RSSI int8

	Timestamp time.Time
	// contains filtered or unexported fields
}

func NewMoteMistMessage

func NewMoteMistMessage(defaultGroup AMGroup, defaultGateway EUI64, defaultSource EUI64) *MoteMistMessage

func (*MoteMistMessage) Deserialize

func (mmm *MoteMistMessage) Deserialize(data []byte) error

func (*MoteMistMessage) Destination

func (mmm *MoteMistMessage) Destination() EUI64

func (*MoteMistMessage) Dispatch

func (mmm *MoteMistMessage) Dispatch() byte

func (*MoteMistMessage) Gateway

func (mmm *MoteMistMessage) Gateway() EUI64

func (*MoteMistMessage) GetPayload

func (mmm *MoteMistMessage) GetPayload() []byte

func (*MoteMistMessage) Group

func (mmm *MoteMistMessage) Group() AMGroup

func (*MoteMistMessage) NewPacket

func (mmm *MoteMistMessage) NewPacket() Packet

Implement Packet

func (*MoteMistMessage) Serialize

func (mmm *MoteMistMessage) Serialize() ([]byte, error)

func (*MoteMistMessage) SetDestination

func (mmm *MoteMistMessage) SetDestination(destination EUI64)

func (*MoteMistMessage) SetDispatch

func (mmm *MoteMistMessage) SetDispatch(dispatch byte)

func (*MoteMistMessage) SetGateway

func (mmm *MoteMistMessage) SetGateway(gateway EUI64)

func (*MoteMistMessage) SetGroup

func (mmm *MoteMistMessage) SetGroup(group AMGroup)

func (*MoteMistMessage) SetPayload

func (mmm *MoteMistMessage) SetPayload(payload []byte) error

func (*MoteMistMessage) SetSource

func (mmm *MoteMistMessage) SetSource(source EUI64)

func (*MoteMistMessage) SetType

func (mmm *MoteMistMessage) SetType(amid AMID)

func (*MoteMistMessage) Source

func (mmm *MoteMistMessage) Source() EUI64

func (*MoteMistMessage) Type

func (mmm *MoteMistMessage) Type() AMID

type Packet

type Packet interface {
	Dispatch() byte
	Serialize() ([]byte, error)
	Deserialize([]byte) error
	SetPayload([]byte) error
	GetPayload() []byte
}

Packet interface

type PacketDispatcher

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

PacketDispatcher structure

func NewPacketDispatcher

func NewPacketDispatcher(packetfactory PacketFactory) *PacketDispatcher

NewPacketDispatcher creates a new dispatcher

func (*PacketDispatcher) Dispatch

func (pd *PacketDispatcher) Dispatch() byte

Dispatch returns the dispatch ID of the dispatcher instance

func (*PacketDispatcher) NewPacket

func (pd *PacketDispatcher) NewPacket() Packet

NewPacket initializes a new packet for use with this dispatcher

func (*PacketDispatcher) Receive

func (pd *PacketDispatcher) Receive(msg []byte) error

Receive distributes a packet to receivers

func (*PacketDispatcher) RegisterReceiver

func (pd *PacketDispatcher) RegisterReceiver(receiver chan Packet) error

RegisterReceiver registers a receiver

type PacketFactory

type PacketFactory interface {
	Dispatch() byte
	NewPacket() Packet
}

PacketFactory interface

type RawPacket

type RawPacket struct {
	Payload []byte
	// contains filtered or unexported fields
}

func NewRawPacket

func NewRawPacket(dispatch byte) *RawPacket

func (*RawPacket) Deserialize

func (self *RawPacket) Deserialize(data []byte) error

func (*RawPacket) Dispatch

func (self *RawPacket) Dispatch() byte

func (*RawPacket) GetPayload

func (self *RawPacket) GetPayload() []byte

func (*RawPacket) NewPacket

func (self *RawPacket) NewPacket() Packet

func (*RawPacket) Serialize

func (self *RawPacket) Serialize() ([]byte, error)

func (*RawPacket) SetPayload

func (self *RawPacket) SetPayload(payload []byte) error

func (*RawPacket) String

func (self *RawPacket) String() string

type SerialConnection

type SerialConnection struct {
	BaseMoteConnection

	Port string
	Baud int
	// contains filtered or unexported fields
}

func NewSerialConnection

func NewSerialConnection(port string, baud int) *SerialConnection

func (*SerialConnection) Autoconnect

func (self *SerialConnection) Autoconnect(period time.Duration)

func (*SerialConnection) Connect

func (self *SerialConnection) Connect() error

func (*SerialConnection) Listen

func (self *SerialConnection) Listen() error

type SfConnection

type SfConnection struct {
	BaseMoteConnection

	Host string
	Port uint16

	Protocol string
	// contains filtered or unexported fields
}

SfConnection - A SerialForwarder connection

func NewSfConnection

func NewSfConnection(host string, port uint16) *SfConnection

NewSfConnection - create a new connection

func (*SfConnection) Autoconnect

func (sfc *SfConnection) Autoconnect(period time.Duration)

Autoconnect - initiate an asynchronous and self-maintaining connection

func (*SfConnection) Connect

func (sfc *SfConnection) Connect() error

Connect - initiate a synchronous connect

func (*SfConnection) Listen

func (sfc *SfConnection) Listen() error

Listen - Start a server and listen for incoming SF connections

type UDPConnection

type UDPConnection struct {
	BaseMoteConnection

	Host string
	Port uint16
	// contains filtered or unexported fields
}

UDPConnection - A SerialForwarder connection

func NewUDPConnection

func NewUDPConnection(host string, port uint16) *UDPConnection

NewUDPConnection - create a new connection

func (*UDPConnection) Autoconnect

func (sfc *UDPConnection) Autoconnect(period time.Duration)

Autoconnect - initiate an asynchronous and self-maintaining connection

func (*UDPConnection) Connect

func (sfc *UDPConnection) Connect() error

Connect - initiate a synchronous connect

func (*UDPConnection) Listen

func (sfc *UDPConnection) Listen() error

Listen - Start a server and listen for incoming SF connections

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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