driver

package
v0.0.0-...-fd6ac98 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryFunc

func RetryFunc(numTimes uint, waitTime time.Duration, theFunc func() error) ([]error, error)

RetryFunc will simply run the provided function in a loop checking if the function returns an error and retrying it if it does if the function fails after numTimes tries, all of the errors are returned in the first result and the second result is non-nil if the function eventually succeeds before running out of tries, the second result will be nil and the first result will contain the previous errors Note: if the number of times is specified as 0, this function will loop forever

Types

type Thingy52Driver

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

Thingy52Driver is a driver for a thingy52

func NewThingy52Driver

func NewThingy52Driver(errChan chan error) *Thingy52Driver

NewThingy52Driver creates a new ProtocolDriver with the associated error channel

func (*Thingy52Driver) FinishedRegisteringDevices

func (d *Thingy52Driver) FinishedRegisteringDevices(ctx context.Context) error

FinishedRegisteringDevices will send a signal that devices are done being registered with the driver and Initialize can finish

func (*Thingy52Driver) HandleReadCommands

func (d *Thingy52Driver) HandleReadCommands(
	deviceName string,
	protocols map[string]contract.ProtocolProperties,
	reqs []dsModels.CommandRequest,
) (res []*dsModels.CommandValue, err error)

HandleReadCommands handles read commands from the device SDK Currently only supports a single request at a time

func (*Thingy52Driver) HandleWriteCommands

func (d *Thingy52Driver) HandleWriteCommands(
	deviceName string,
	protocols map[string]contract.ProtocolProperties,
	reqs []dsModels.CommandRequest,
	params []*dsModels.CommandValue,
) error

HandleWriteCommands does nothing because there are no write commands for this device-service

func (*Thingy52Driver) Initialize

func (d *Thingy52Driver) Initialize(
	lc logger.LoggingClient,
	asyncCh chan<- *dsModels.AsyncValues,
) error

Initialize currently saves the logging client and notifies the driver that the initialization sequence has begun, then waits to finish initialization until the driver is notified that all devices have been registered must be run in different goroutine than FinishedRegisteringDevices and a different goroutine than WaitForInitStarted (though those two functions can themselves be run in the sam goroutine as each other)

func (*Thingy52Driver) RegisterBLEDevice

func (d *Thingy52Driver) RegisterBLEDevice(
	devName string,
	dev *api.Device,
) error

RegisterBLEDevice adds a device to the Thingy52Driver and starts running a background goroutine which gathers the data and pushes the data onto a queue which is then read from in the HandleReadCommands RegisterBLEDevice expects the device to already have been connected and ready to be read from must be called after Initialize has been started, but before FinishedRegisteringDevices is called

func (*Thingy52Driver) Stop

func (d *Thingy52Driver) Stop(force bool) (err error)

Stop will kill the background process reading from the program

func (*Thingy52Driver) WaitForInitStarted

func (d *Thingy52Driver) WaitForInitStarted(ctx context.Context) error

WaitForInitStarted will block until d.Initialize() is called

Jump to

Keyboard shortcuts

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