sesn

package
v0.0.0-...-cf9985f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 93

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DfltTxOptions = TxOptions{
	Timeout: 10 * time.Second,
	Tries:   1,
}

Functions

func RxCoap

func RxCoap(cl *nmcoap.Listener, timeout time.Duration) (coap.Message, error)

RxCoap performs a blocking receive of a CoAP message. It returns a nil message if the specified listener is closed while the function is running.

func TxCoap

func TxCoap(s Sesn, mp nmcoap.MsgParams) error

TxCoap transmits a single CoAP message over the provided session.

func TxRxCoap

func TxRxCoap(s Sesn, mp nmcoap.MsgParams,
	opts TxOptions) (coap.Message, error)

TxRxMgmt sends a CoAP request and listens for the response.

func TxRxMgmt

func TxRxMgmt(s Sesn, m *nmp.NmpMsg, o TxOptions) (nmp.NmpRsp, error)

TxRxMgmt sends a management command (NMP / OMP) and listens for the response.

func TxRxMgmtAsync

func TxRxMgmtAsync(s Sesn, m *nmp.NmpMsg, o TxOptions, ch chan nmp.NmpRsp, errc chan error) error

Types

type MgmtProto

type MgmtProto int
const (
	MGMT_PROTO_NMP MgmtProto = iota
	MGMT_PROTO_OMP
	MGMT_PROTO_COAP_SERVER
)

func (MgmtProto) String

func (r MgmtProto) String() string

type NotifyCb

type NotifyCb func(msg coap.Message, err error)

type OnCloseFn

type OnCloseFn func(s Sesn, err error)

type PeerSpec

type PeerSpec struct {
	Ble bledefs.BleDev
	Udp string
}

type Sesn

type Sesn interface {

	// Initiates communication with the peer.  For connection-oriented
	// transports, this creates a connection.
	// Returns:
	//     * nil: success.
	//     * nmxutil.SesnAlreadyOpenError: session already open.
	//     * other error
	Open() error

	// Ends communication with the peer.  For connection-oriented transports,
	// this closes the connection.
	//     * nil: success.
	//     * nmxutil.SesnClosedError: session not open.
	//     * other error
	Close() error

	// Indicates whether the session is currently open.
	IsOpen() bool

	// Retrieves the maximum data payload for incoming data packets.
	MtuIn() int

	// Retrieves the maximum data payload for outgoing data packets.
	MtuOut() int

	MgmtProto() MgmtProto

	// Indicates whether the session uses the TCP form of CoAP.
	CoapIsTcp() bool

	// Stops a receive operation in progress.  This must be called from a
	// separate thread, as sesn receive operations are blocking.
	AbortRx(nmpSeq uint8) error

	RxAccept() (Sesn, *SesnCfg, error)
	RxCoap(opt TxOptions) (coap.Message, error)

	// Performs a blocking transmit a single management request (NMP / OMP) and
	// listens for the response.
	//     * nil: success.
	//     * nmxutil.SesnClosedError: session not open.
	//     * other error
	TxRxMgmt(m *nmp.NmpMsg, timeout time.Duration) (nmp.NmpRsp, error)
	TxRxMgmtAsync(m *nmp.NmpMsg, timeout time.Duration, ch chan nmp.NmpRsp, errc chan error) error

	// Creates a listener for incoming CoAP messages matching the specified
	// criteria.
	ListenCoap(mc nmcoap.MsgCriteria) (*nmcoap.Listener, error)

	// Cancels the CoAP listener with the specified criteria.
	StopListenCoap(mc nmcoap.MsgCriteria)

	// Transmits a CoAP message.
	TxCoap(m coap.Message) error

	// Returns a transmit and a receive callback used to manipulate CoAP
	// messages
	Filters() (nmcoap.TxMsgFilter, nmcoap.RxMsgFilter)

	// Sets the transmit and a receive callback used to manipulate CoAP
	// messages
	SetFilters(txFilter nmcoap.TxMsgFilter, rxFilter nmcoap.RxMsgFilter)
}

Represents a communication session with a specific peer. The particulars vary according to protocol and transport. Several Sesn instances can use the same Xport.

type SesnCfg

type SesnCfg struct {
	// General configuration.
	MgmtProto MgmtProto
	PeerSpec  PeerSpec
	OnCloseCb OnCloseFn

	// Transport-specific configuration.
	Ble  SesnCfgBle
	Lora SesnCfgLora

	// Filters
	TxFilter nmcoap.TxMsgFilter
	RxFilter nmcoap.RxMsgFilter
}

func NewSesnCfg

func NewSesnCfg() SesnCfg

type SesnCfgBle

type SesnCfgBle struct {
	// General configuration.
	OwnAddrType  bledefs.BleAddrType
	EncryptWhen  bledefs.BleEncryptWhen
	CloseTimeout time.Duration
	WriteRsp     bool

	// Central configuration.
	Central SesnCfgBleCentral
}

type SesnCfgBleCentral

type SesnCfgBleCentral struct {
	ConnTries   int
	ConnTimeout time.Duration
}

type SesnCfgLora

type SesnCfgLora struct {
	Addr        string
	SegSz       int
	ConfirmedTx bool
	Port        uint8
}

type TxOptions

type TxOptions struct {
	Timeout time.Duration
	Tries   int
}

func NewTxOptions

func NewTxOptions() TxOptions

func (*TxOptions) AfterTimeout

func (opt *TxOptions) AfterTimeout() <-chan time.Time

Jump to

Keyboard shortcuts

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