moteconnection

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 19 Imported by: 7 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

This section is empty.

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 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 *Message) *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 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 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
sforwarder module

Jump to

Keyboard shortcuts

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