sensor

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context
	SensorID string
	Pipe     ReadingsPipe
}

Context defines structure for the sensor.Sensor reading context.

func NewReaderContext

func NewReaderContext(parent context.Context, sensor Sensor) *Context

NewReaderContext constructs new Context instance based on given `parent` context for the given sensor.Sensor.

func (*Context) Error

func (c *Context) Error(err error)

Error wraps `err` logging with sensor.Sensor metadata.

func (*Context) Info

func (c *Context) Info(info string)

Info wraps `info` logging with sensor.Sensor metadata.

func (*Context) Warning

func (c *Context) Warning(msg string)

Warning wraps `msg` logging with sensor.Sensor metadata.

func (*Context) WriterFor

func (c *Context) WriterFor(metric models.Metric) *MetricWriter

WriterFor returns MetricWriter for a given models.Metric.

type Factory

type Factory interface {
	Build(bus int) Sensor
}

Factory defines interface for building sensor.Sensor.

func I2CFactory

func I2CFactory(factory func(addr uint16, bus int) Sensor, addr uint16) Factory

I2CFactory provides new factory for building I2C-based sensor.Sensor.

type FactoryFunc

type FactoryFunc func(int) Sensor

FactoryFunc builds sensor.Sensor.

func (FactoryFunc) Build

func (f FactoryFunc) Build(bus int) Sensor

Build calls FactoryFunc to build sensor.Sensor on specified peripheral bus.

type MetricWriter

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

MetricWriter defines object capable of dumping reading results from sensor.Sensor to a specific ReadingsPipe for models.Metric data.

func (*MetricWriter) Write

func (w *MetricWriter) Write(v interface{})

Write writes reading results from sensor.Sensor with required type conversation.

func (*MetricWriter) WriteWithError

func (w *MetricWriter) WriteWithError(value interface{}, err error)

WriteWithError allows to Write reading results and logged potential error at the same time.

type ReadingResult

type ReadingResult struct {
	Source string
	Value  float64
}

ReadingResult defines structure for storing readings result from a single sensor.Sensor device.

type ReadingsPipe

type ReadingsPipe map[models.Metric]chan ReadingResult

ReadingsPipe maps where to dump sensor.Sensor ReadingResult for concrete models.Metric.

type Sensor

type Sensor interface {
	// ID returns unique Sensor identifier key.
	ID() string
	// Init performers initialization sequence of the Sensor device.
	Init() error
	// Harvest collects all available models.Metric from Sensor device and dumps them into the context.
	Harvest(ctx *Context)
	// Metrics return all available models.Metric to reads from Sensor device.
	Metrics() []models.Metric
	// Verify checks whether the driver is compatible with Sensor device.
	Verify() bool
	// Active checks whether the Sensor device is connected and active.
	Active() bool
	// Close closes connection to Sensor device and clears allocated resources.
	Close() error
}

Sensor defines base methods for controlling sensor device.

type SensorsRegister

type SensorsRegister map[string]Sensor

SensorsRegister represents pool of the multiply sensor.Sensor devices.

func (SensorsRegister) Exists

func (sr SensorsRegister) Exists(id string) bool

Exists determines whether the sensor.Sensor exists in SensorsRegister by given `id`.

func (SensorsRegister) NotEmpty

func (sr SensorsRegister) NotEmpty() bool

NotEmpty determines whether SensorsRegister contains at least one sensor.Sensor.

func (SensorsRegister) SupportedMetrics

func (sr SensorsRegister) SupportedMetrics() models.Metrics

SupportedMetrics aggregates all supported by sensors models.Metric devices.

func (SensorsRegister) ToList

func (sr SensorsRegister) ToList() []Sensor

ToList returns slice of all sensor.Sensor devices presented in SensorsRegister.

func (SensorsRegister) Union

Union produces new SensorsRegister combining sensors from original and `sr2`.

Jump to

Keyboard shortcuts

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