xbserial

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ATSH = ATCommand{0x53, 0x48}
	ATSL = ATCommand{0x53, 0x4C}
)

Functions

This section is empty.

Types

type ATCommand

type ATCommand [2]byte

type PacketConn

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

PacketConn wraps a xbee serial connection into a packet conn. Assumes only one reader at a time to eliminate a mutex lock

func NewPacketConn

func NewPacketConn(ctx context.Context, xb *XBeeSerial) (*PacketConn, error)

NewPacketConn creates a PacketConn by looking up the local address.

func NewPacketConnWithAddr

func NewPacketConnWithAddr(ctx context.Context, xb *XBeeSerial, localAddr XBeeAddr) *PacketConn

NewPacketConnWithAddr constructs a PacketConn with addresses.

func (*PacketConn) Close

func (c *PacketConn) Close() error

Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.

func (*PacketConn) LocalAddr

func (c *PacketConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*PacketConn) ReadFrom

func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

ReadFrom reads a packet from the connection, copying the payload into p. Respects deadlines. If Close() is called, return an error.

func (*PacketConn) SetDeadline

func (c *PacketConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to ReadFrom or WriteTo. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.

A zero value for t means I/O operations will not time out.

func (*PacketConn) SetReadDeadline

func (c *PacketConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.

func (*PacketConn) SetWriteDeadline

func (c *PacketConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.

func (*PacketConn) WriteTo

func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with payload p to addr. Addr is expected to be a XBeeAddr (will return an error otherwise) WriteTo can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline. On packet-oriented connections, write timeouts are rare.

type XBeeAddr

type XBeeAddr uint64

XBeeAddr is the xbee address.

func ParseXBeeAddr

func ParseXBeeAddr(adr string) (XBeeAddr, error)

ParseXBeeAddr parses a hex xbee address.

func (XBeeAddr) Network

func (a XBeeAddr) Network() string

Network is the name of the network (tcp uses "tcp")

func (XBeeAddr) String

func (a XBeeAddr) String() string

string form of address (for example, "192.0.2.1:25", "[2001:db8::1]:80")

type XBeeSerial

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

XBeeSerial communicates with a xbee over a serial line. Implements net.PacketConn

func NewXBeeSerial

func NewXBeeSerial(
	le *logrus.Entry,
	serialPort *serial.Port,
) *XBeeSerial

NewXBeeSerial builds a xbee serial wrapper from a serial port.

func (*XBeeSerial) ReadLocalAddress

func (x *XBeeSerial) ReadLocalAddress(ctx context.Context) (XBeeAddr, error)

ReadLocalAddress reads the local address.

func (*XBeeSerial) ReadPump

func (x *XBeeSerial) ReadPump() error

ReadPump is a goroutine that reads data from the xbee.

func (*XBeeSerial) SetDataHandler

func (x *XBeeSerial) SetDataHandler(handler func(data []byte, addr XBeeAddr))

SetDataHandler sets the data handling function.

func (*XBeeSerial) TxToAddr

func (x *XBeeSerial) TxToAddr(
	ctx context.Context,
	addr64 uint64, addr16 uint16,

	sourceEndpoint byte,

	destinationEndpoint byte,

	clusterID uint16,

	profileID uint16,

	broadcastRadius byte,

	options byte,

	data []byte,
) error

TxToAddr transmits data to a 64 bit peer address.

Use addr64 or addr16, not both. Special addr values: - 0x0 - Coordinator address - 0x000000000000FFFF - Broadcast address (64-bit only)

https://www.digi.com/resources/documentation/Digidocs/90001942-13/reference/r_zigbee_frame_examples.htm

func (*XBeeSerial) WriteFrame

func (x *XBeeSerial) WriteFrame(frame tx.Frame) (int, error)

WriteFrame attempts to write a frame to the xbee.

type XmitToAddr

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

XmitToAddr transmit to 64 bit address frame

func (*XmitToAddr) Bytes

func (f *XmitToAddr) Bytes() ([]byte, error)

Bytes turn XmitToAddr frame into bytes

Jump to

Keyboard shortcuts

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