device

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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

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

Device defines driver for the IoT device itself.

func New

func New(modules ...Module) *Device

New constructs new IoT Device driver instance.

func (*Device) Battery

func (d *Device) Battery() models.DeviceBattery

Battery returns Device current battery stats.

func (*Device) Close

func (d *Device) Close() error

Close stops all working device.Module and frees allocated resources.

func (*Device) ExistsAssetInCache

func (c *Device) ExistsAssetInCache(id string) bool

ExistsAssetInCache determines whether the models.Asset record stored in cache by given `id`.

func (*Device) FlushAssetsCache

func (c *Device) FlushAssetsCache()

FlushAssetsCache resets models.Asset records cache.

func (*Device) FlushRequirementsCache

func (c *Device) FlushRequirementsCache()

FlushRequirementsCache resets models.Requirements records cache.

func (*Device) GetCachedAssets

func (c *Device) GetCachedAssets() []string

GetCachedAssets returns IDs of cached models.Asset records.

func (*Device) GetCachedRequirements

func (c *Device) GetCachedRequirements() []*model.SensorsReadingRequest

GetCachedRequirements returns data of cached models.Requirements records as model.SensorsReadingRequest.

func (*Device) GetCachedRequirementsFor

func (c *Device) GetCachedRequirementsFor(assetIDs ...string) []*model.SensorsReadingRequest

GetCachedRequirementsFor returns models.Requirements cached data for given `assetIDs` as model.SensorsReadingRequest.

func (*Device) GetRequirementsFromCache

func (c *Device) GetRequirementsFromCache(id string) (*model.SensorsReadingRequest, bool)

GetRequirementsFromCache tries to retrieve single models.Requirements from cache by given `id`, where it is stored as a model.SensorsReadingRequest record.

func (*Device) ID

func (d *Device) ID() string

ID returns Device unique identifier key in blockchain network.

func (*Device) IsLoggedToNetwork

func (d *Device) IsLoggedToNetwork() bool

IsLoggedToNetwork determines whether the Device is logged to network and thus is ready to operate.

func (*Device) Location

func (d *Device) Location() models.Location

Location returns Device current location.

func (*Device) Name

func (d *Device) Name() string

Name returns Device given name.

func (*Device) PutAssetsToCache

func (c *Device) PutAssetsToCache(assets ...*models.Asset)

PutAssetsToCache puts models.Asset records to local cache.

func (*Device) PutRequirementsToCache

func (c *Device) PutRequirementsToCache(reqs ...*models.Requirements) (requests []*model.SensorsReadingRequest)

PutRequirementsToCache puts models.Requirements records to local cache and return requests as they are stored.

func (*Device) RegisterSensors

func (d *Device) RegisterSensors(sensors ...sensor.Sensor)

RegisterSensors adds given `sensors` on the Device sensors pool.

func (*Device) RegisterStaticSensors

func (d *Device) RegisterStaticSensors(sensors ...sensor.Sensor) *Device

RegisterStaticSensors allows to registrant static (not auto-detectable) sensors.

func (*Device) RegisteredSensors

func (d *Device) RegisteredSensors() sensor.SensorsRegister

RegisteredSensors returns map with sensors registered on the Device.

func (*Device) RemoveAssetFromCache

func (c *Device) RemoveAssetFromCache(id string)

RemoveAssetFromCache removes models.Asset record to local cache by given `id`.

func (*Device) RemoveRequirementsFromCache

func (c *Device) RemoveRequirementsFromCache(id string)

RemoveRequirementsFromCache removes models.Requirements record to local cache by given `id`.

func (*Device) SetBattery

func (d *Device) SetBattery(battery models.DeviceBattery) error

SetBattery updates Device current battery stats in blockchain network.

func (*Device) SetLocation

func (d *Device) SetLocation(location models.Location) error

SetLocation updates Device current location in blockchain network.

func (*Device) SetSpecs

func (d *Device) SetSpecs(setter func(specs *model.DeviceSpecs)) error

SetSpecs updates Device current specification in blockchain network.

func (*Device) SetState

func (d *Device) SetState(state models.DeviceState) error

SetState updates Device current state in blockchain network.

func (*Device) Specs

func (d *Device) Specs() model.DeviceSpecs

Specs returns Device current specification.

func (*Device) Start

func (d *Device) Start()

Start performs startup of the Device and setting up all registered modules.

func (*Device) State

func (d *Device) State() models.DeviceState

State returns Device current state.

func (*Device) StaticSensors

func (d *Device) StaticSensors() sensor.SensorsRegister

StaticSensors returns map with sensors statically registered on the Device.

func (*Device) UnregisterSensor

func (d *Device) UnregisterSensor(id string)

UnregisterSensor removes sensor by given `id` from the Device sensors pool.

func (*Device) UpdateDeviceModel

func (d *Device) UpdateDeviceModel(model *models.Device)

UpdateDeviceModel updates Device data model (models.Device).

This method won't change state of the Device in blockchain ledger, it just updates device locally saved properties.

func (*Device) UpdateSensorsRegister

func (d *Device) UpdateSensorsRegister(added []sensor.Sensor, removed []string)

UpdateSensorsRegister applies changes in sensor.SensorsRegister of the Device.

type Module

type Module interface {
	// MID returns Module ID.
	MID() string
	// Setup registers logical Module onto the Device instance.
	Setup(device *Device) error
	// IsReady determines whether the logical Module's Setup is complete and it is ready to Start.
	IsReady() bool
	// Start starts Module operational routine.
	Start(ctx context.Context)
	// Close stops Module gracefully and clears allocated resources.
	Close() error
}

Module defines interface for Device extendable logical modules.

type ModulesRegistry

type ModulesRegistry []Module

ModulesRegistry defines pool of registered logical Module's extending the Device functionality.

func (ModulesRegistry) Close

func (r ModulesRegistry) Close()

func (ModulesRegistry) Setup

func (r ModulesRegistry) Setup(device *Device)

Setup registers all logical device.Module's presented in ModulesRegistry onto the device.Device instance.

func (ModulesRegistry) Start

func (r ModulesRegistry) Start(ctx context.Context)

Start starts all presented in ModulesRegistry logical device.Module's operational routine.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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