controller

package
v0.0.0-...-ae9fff6 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorClosed is returned when the device has already been closed.
	ErrorClosed = errors.New("Device has been closed")
)

Functions

This section is empty.

Types

type BusDevice

type BusDevice struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BusDevice represents a device on the BattGO compatible bus.

func (*BusDevice) CommandExec

func (d *BusDevice) CommandExec(ctx context.Context, payload []byte, response []byte) ([]byte, error)

CommandExec sends a message to the device and returns the response. You can provide a slice that will be used to store the response.

func (*BusDevice) CommandExecTimeout

func (d *BusDevice) CommandExecTimeout(timeout time.Duration, payload []byte, response []byte) ([]byte, error)

CommandExecTimeout sends a message to the device and returns the response. You can provide a slice that will be used to store the response. Convenience logic is provided to handle timeouts. When the timeout value is 0, a reasonable default is used.

func (*BusDevice) GetAddress

func (d *BusDevice) GetAddress() uint8

GetAddres returns the physical address of the device.

func (*BusDevice) GetSerial

func (d *BusDevice) GetSerial() []byte

GetSerial returns the serial of the device.

type Controller

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

Controller is a module that runs as the host of the BattGO compatible network.

func New

func New(phy *phy.PHY, numDevices int, newDev func(device *BusDevice) FunctionalDevice) *Controller

New creates a controller. You need to specify a PHY, the amount of devices on the bus and a callback that will be called when a new device is detected. If the number of devices is not known two special values can be given:

 0: Scan continuously for new devices
-1: Scan periodically and whenever the number of visible devices is less than the maximum.

func (*Controller) Close

func (c *Controller) Close() error

Make Run() return and close the underlying PHY.

func (*Controller) GetMaxDevices

func (c *Controller) GetMaxDevices() int

GetMaxDevices returns the highest amount of devices ever seen.

func (*Controller) Run

func (c *Controller) Run() error

Run starts the controller and will return on an error or when Close() is called.

type FunctionalDevice

type FunctionalDevice interface {
	// Access is called periodically by the controller. The module should perform periodic actions.
	// If communications to the device failed, the boolean value should be false.
	// If error is not nil, the controller Run() function will terminate with this error.
	Access() (bool, error)

	// Disconnected will be called by the controller when it appears the device left the bus.
	Disconnected() error
}

FunctionalDevice represents code implementing the interface to a BattGO compatible device.

Directories

Path Synopsis
functions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳