models

package
v2.0.1-dev.27 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: Apache-2.0 Imports: 6 Imported by: 12

Documentation

Overview

This package defines interfaces and structs used to build an EdgeX Foundry Device Service. The interfaces provide an asbstraction layer for the device or protocol specific logic of a Device Service, and the structs represents request and response data format used by the protocol driver.

Index

Constants

View Source
const (
	// Policy limits should be located in global config namespace
	// Currently assigning 16MB (binary), 16 * 2^20 bytes
	MaxBinaryBytes = 16777216
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncValues

type AsyncValues struct {
	DeviceName    string
	SourceName    string
	CommandValues []*CommandValue
}

AsyncValues is the struct for sending Device readings asynchronously via ProtocolDrivers

type AutoEventManager

type AutoEventManager interface {
	// StartAutoEvents starts all the AutoEvents of the device service
	StartAutoEvents()
	// RestartForDevice restarts all the AutoEvents of the specific device
	RestartForDevice(name string)
	// StopForDevice stops all the AutoEvents of the specific device
	StopForDevice(name string)
}

type CommandRequest

type CommandRequest struct {
	// DeviceResourceName is the name of Device Resource for this command
	DeviceResourceName string
	// Attributes is a key/value map to represent the attributes of the Device Resource
	Attributes map[string]interface{}
	// Type is the data type of the Device Resource
	Type string
}

CommandRequest is the struct for requesting a command to ProtocolDrivers

type CommandValue

type CommandValue struct {
	// DeviceResourceName is the name of Device Resource for this command
	DeviceResourceName string
	// Type indicates what type of value was returned from the ProtocolDriver instance in
	// response to HandleCommand being called to handle a single ResourceOperation.
	Type string
	// Value holds value returned by a ProtocolDriver instance.
	// The value can be converted to its native type by referring to ValueType.
	Value interface{}
	// Origin is an int64 value which indicates the time the reading
	// contained in the CommandValue was read by the ProtocolDriver
	// instance.
	Origin int64
	// Tags allows device service to add custom information to the Event in order to
	// help identify its origin or otherwise label it before it is send to north side.
	Tags map[string]string
}

CommandValue is the struct to represent the reading value of a Get command coming from ProtocolDrivers or the parameter of a Put command sending to ProtocolDrivers.

func NewCommandValue

func NewCommandValue(deviceResourceName string, valueType string, value interface{}) (*CommandValue, error)

NewCommandValue create a CommandValue according to the valueType supplied.

func NewCommandValueWithOrigin added in v2.1.0

func NewCommandValueWithOrigin(deviceResourceName string, valueType string, value interface{}, origin int64) (*CommandValue, error)

NewCommandValueWithOrigin wraps NewCommandValue, create a CommandValue and add the Origin field.

func (*CommandValue) BinaryValue

func (cv *CommandValue) BinaryValue() ([]byte, error)

BinaryValue returns the value in []byte data type, and returns error if the Type is not Binary.

func (*CommandValue) BoolArrayValue

func (cv *CommandValue) BoolArrayValue() ([]bool, error)

BoolArrayValue returns the value in an array of bool type, and returns error if the Type is not BoolArray.

func (*CommandValue) BoolValue

func (cv *CommandValue) BoolValue() (bool, error)

BoolValue returns the value in bool data type, and returns error if the Type is not Bool.

func (*CommandValue) Float32ArrayValue

func (cv *CommandValue) Float32ArrayValue() ([]float32, error)

Float32ArrayValue returns the value in an array of float32 type, and returns error if the Type is not Float32Array.

func (*CommandValue) Float32Value

func (cv *CommandValue) Float32Value() (float32, error)

Float32Value returns the value in float32 data type, and returns error if the Type is not Float32.

func (*CommandValue) Float64ArrayValue

func (cv *CommandValue) Float64ArrayValue() ([]float64, error)

Float64ArrayValue returns the value in an array of float64 type, and returns error if the Type is not Float64Array.

func (*CommandValue) Float64Value

func (cv *CommandValue) Float64Value() (float64, error)

Float64Value returns the value in float64 data type, and returns error if the Type is not Float64.

func (*CommandValue) Int16ArrayValue

func (cv *CommandValue) Int16ArrayValue() ([]int16, error)

Int16ArrayValue returns the value in an array of int16 type, and returns error if the Type is not Int16Array.

func (*CommandValue) Int16Value

func (cv *CommandValue) Int16Value() (int16, error)

Int16Value returns the value in int16 data type, and returns error if the Type is not Int16.

func (*CommandValue) Int32ArrayValue

func (cv *CommandValue) Int32ArrayValue() ([]int32, error)

Int32ArrayValue returns the value in an array of int32 type, and returns error if the Type is not Int32Array.

func (*CommandValue) Int32Value

func (cv *CommandValue) Int32Value() (int32, error)

Int32Value returns the value in int32 data type, and returns error if the Type is not Int32.

func (*CommandValue) Int64ArrayValue

func (cv *CommandValue) Int64ArrayValue() ([]int64, error)

Int64ArrayValue returns the value in an array of int64 type, and returns error if the Type is not Int64Array.

func (*CommandValue) Int64Value

func (cv *CommandValue) Int64Value() (int64, error)

Int64Value returns the value in int64 data type, and returns error if the Type is not Int64.

func (*CommandValue) Int8ArrayValue

func (cv *CommandValue) Int8ArrayValue() ([]int8, error)

Int8ArrayValue returns the value in an array of int8 type, and returns error if the Type is not Int8Array.

func (*CommandValue) Int8Value

func (cv *CommandValue) Int8Value() (int8, error)

Int8Value returns the value in int8 data type, and returns error if the Type is not Int8.

func (*CommandValue) ObjectValue added in v2.1.0

func (cv *CommandValue) ObjectValue() (interface{}, error)

ObjectValue returns the value in object data type, and returns error if the Type is not Object.

func (*CommandValue) String

func (cv *CommandValue) String() string

String returns a string representation of a CommandValue instance.

func (*CommandValue) StringValue

func (cv *CommandValue) StringValue() (string, error)

StringValue returns the value in string data type, and returns error if the Type is not String.

func (*CommandValue) Uint16ArrayValue

func (cv *CommandValue) Uint16ArrayValue() ([]uint16, error)

Uint16ArrayValue returns the value in an array of uint16 type, and returns error if the Type is not Uint16Array.

func (*CommandValue) Uint16Value

func (cv *CommandValue) Uint16Value() (uint16, error)

Uint16Value returns the value in uint16 data type, and returns error if the Type is not Uint16.

func (*CommandValue) Uint32ArrayValue

func (cv *CommandValue) Uint32ArrayValue() ([]uint32, error)

Uint32ArrayValue returns the value in an array of uint32 type, and returns error if the Type is not Uint32Array.

func (*CommandValue) Uint32Value

func (cv *CommandValue) Uint32Value() (uint32, error)

Uint32Value returns the value in uint32 data type, and returns error if the Type is not Uint32.

func (*CommandValue) Uint64ArrayValue

func (cv *CommandValue) Uint64ArrayValue() ([]uint64, error)

Uint64ArrayValue returns the value in an array of uint64 type, and returns error if the Type is not Uint64Array.

func (*CommandValue) Uint64Value

func (cv *CommandValue) Uint64Value() (uint64, error)

Uint64Value returns the value in uint64 data type, and returns error if the Type is not Uint64.

func (*CommandValue) Uint8ArrayValue

func (cv *CommandValue) Uint8ArrayValue() ([]uint8, error)

Uint8ArrayValue returns the value in an array of uint8 type, and returns error if the Type is not Uint8Array.

func (*CommandValue) Uint8Value

func (cv *CommandValue) Uint8Value() (uint8, error)

Uint8Value returns the value in uint8 data type, and returns error if the Type is not Uint8.

func (*CommandValue) ValueToString

func (cv *CommandValue) ValueToString() string

ValueToString returns the string format of the value.

type DiscoveredDevice

type DiscoveredDevice struct {
	Name        string
	Protocols   map[string]models.ProtocolProperties
	Description string
	Labels      []string
}

DiscoveredDevice defines the required information for a found device.

type ProtocolDiscovery

type ProtocolDiscovery interface {
	// Discover triggers protocol specific device discovery, asynchronously
	// writes the results to the channel which is passed to the implementation
	// via ProtocolDriver.Initialize(). The results may be added to the device service
	// based on a set of acceptance criteria (i.e. Provision Watchers).
	Discover()
}

ProtocolDiscovery is a low-level device-specific interface implemented by device services that support dynamic device discovery.

type ProtocolDriver

type ProtocolDriver interface {
	// Initialize performs protocol-specific initialization for the device service.
	// The given *AsyncValues channel can be used to push asynchronous events and
	// readings to Core Data. The given []DiscoveredDevice channel is used to send
	// discovered devices that will be filtered and added to Core Metadata asynchronously.
	Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues, deviceCh chan<- []DiscoveredDevice) error

	// HandleReadCommands passes a slice of CommandRequest struct each representing
	// a ResourceOperation for a specific device resource.
	HandleReadCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []CommandRequest) ([]*CommandValue, error)

	// HandleWriteCommands passes a slice of CommandRequest struct each representing
	// a ResourceOperation for a specific device resource.
	// Since the commands are actuation commands, params provide parameters for the individual
	// command.
	HandleWriteCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error

	// Stop instructs the protocol-specific DS code to shutdown gracefully, or
	// if the force parameter is 'true', immediately. The driver is responsible
	// for closing any in-use channels, including the channel used to send async
	// readings (if supported).
	Stop(force bool) error

	// AddDevice is a callback function that is invoked
	// when a new Device associated with this Device Service is added
	AddDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error

	// UpdateDevice is a callback function that is invoked
	// when a Device associated with this Device Service is updated
	UpdateDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error

	// RemoveDevice is a callback function that is invoked
	// when a Device associated with this Device Service is removed
	RemoveDevice(deviceName string, protocols map[string]models.ProtocolProperties) error
}

ProtocolDriver is a low-level device-specific interface used by by other components of an EdgeX Device Service to interact with a specific class of devices.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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