models

package
v1.2.4-dev.25 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0 Imports: 10 Imported by: 4

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
	// DefaultFoloatEncoding indicates the representation of floating value of reading.
	// It would be configurable in system level in the future
	DefaultFloatEncoding = contract.Base64Encoding
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncValues

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

AsyncValues is the struct for sending Device readings asynchronously via ProtocolDrivers

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]string
	// Type is the data type of the Device Resource
	Type ValueType
}

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
	// Origin is an int64 value which indicates the time the reading
	// contained in the CommandValue was read by the ProtocolDriver
	// instance.
	Origin int64
	// Type is a ValueType value which indicates what type of
	// value was returned from the ProtocolDriver instance in
	// response to HandleCommand being called to handle a single
	// ResourceOperation.
	Type ValueType
	// NumericValue is a byte slice with a maximum capacity of
	// 64 bytes, used to hold a numeric value returned by a
	// ProtocolDriver instance. The value can be converted to
	// its native type by referring to the the value of ResType.
	NumericValue []byte

	// BinValue is a binary value with a maximum capacity of 16 MB,
	// used to hold binary values returned by a ProtocolDriver instance.
	BinValue []byte
	// contains filtered or unexported fields
}

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 NewBinaryValue

func NewBinaryValue(DeviceResourceName string, origin int64, value []byte) (cv *CommandValue, err error)

NewBinaryValue creates a CommandValue with binary payload and enforces the memory limit for event readings.

func NewBoolArrayValue added in v1.2.0

func NewBoolArrayValue(DeviceResourceName string, origin int64, value []bool) (cv *CommandValue, err error)

NewBoolArrayValue creates a CommandValue of Type BoolArray with the given value.

func NewBoolValue

func NewBoolValue(DeviceResourceName string, origin int64, value bool) (cv *CommandValue, err error)

NewBoolValue creates a CommandValue of Type Bool with the given value.

func NewCommandValue

func NewCommandValue(DeviceResourceName string, origin int64, value interface{}, t ValueType) (cv *CommandValue, err error)

NewCommandValue create a CommandValue according to the Type supplied.

func NewFloat32ArrayValue added in v1.2.0

func NewFloat32ArrayValue(DeviceResourceName string, origin int64, value []float32) (cv *CommandValue, err error)

NewFloat32ArrayValue creates a CommandValue of Type Float32Array with the given value.

func NewFloat32Value

func NewFloat32Value(DeviceResourceName string, origin int64, value float32) (cv *CommandValue, err error)

NewFloat32Value creates a CommandValue of Type Float32 with the given value.

func NewFloat64ArrayValue added in v1.2.0

func NewFloat64ArrayValue(DeviceResourceName string, origin int64, value []float64) (cv *CommandValue, err error)

NewFloat64ArrayValue creates a CommandValue of Type Float64Array with the given value.

func NewFloat64Value

func NewFloat64Value(DeviceResourceName string, origin int64, value float64) (cv *CommandValue, err error)

NewFloat64Value creates a CommandValue of Type Float64 with the given value.

func NewInt16ArrayValue added in v1.2.0

func NewInt16ArrayValue(DeviceResourceName string, origin int64, value []int16) (cv *CommandValue, err error)

NewInt16ArrayValue creates a CommandValue of Type Int16Array with the given value.

func NewInt16Value

func NewInt16Value(DeviceResourceName string, origin int64, value int16) (cv *CommandValue, err error)

NewInt16Value creates a CommandValue of Type Int16 with the given value.

func NewInt32ArrayValue added in v1.2.0

func NewInt32ArrayValue(DeviceResourceName string, origin int64, value []int32) (cv *CommandValue, err error)

NewInt32ArrayValue creates a CommandValue of Type Int32Array with the given value.

func NewInt32Value

func NewInt32Value(DeviceResourceName string, origin int64, value int32) (cv *CommandValue, err error)

NewInt32Value creates a CommandValue of Type Int32 with the given value.

func NewInt64ArrayValue added in v1.2.0

func NewInt64ArrayValue(DeviceResourceName string, origin int64, value []int64) (cv *CommandValue, err error)

NewInt64ArrayValue creates a CommandValue of Type Int64Array with the given value.

func NewInt64Value

func NewInt64Value(DeviceResourceName string, origin int64, value int64) (cv *CommandValue, err error)

NewInt64Value creates a CommandValue of Type Int64 with the given value.

func NewInt8ArrayValue added in v1.2.0

func NewInt8ArrayValue(DeviceResourceName string, origin int64, value []int8) (cv *CommandValue, err error)

NewInt8ArrayValue creates a CommandValue of Type Int8Array with the given value.

func NewInt8Value

func NewInt8Value(DeviceResourceName string, origin int64, value int8) (cv *CommandValue, err error)

NewInt8Value creates a CommandValue of Type Int8 with the given value.

func NewStringValue

func NewStringValue(DeviceResourceName string, origin int64, value string) (cv *CommandValue)

NewStringValue creates a CommandValue of Type string with the given value.

func NewUint16ArrayValue added in v1.2.0

func NewUint16ArrayValue(DeviceResourceName string, origin int64, value []uint16) (cv *CommandValue, err error)

NewUint16ArrayValue creates a CommandValue of Type Uint16Array with the given value.

func NewUint16Value

func NewUint16Value(DeviceResourceName string, origin int64, value uint16) (cv *CommandValue, err error)

NewUint16Value creates a CommandValue of Type Uint16 with the given value.

func NewUint32ArrayValue added in v1.2.0

func NewUint32ArrayValue(DeviceResourceName string, origin int64, value []uint32) (cv *CommandValue, err error)

NewUint32ArrayValue creates a CommandValue of Type Uint32Array with the given value.

func NewUint32Value

func NewUint32Value(DeviceResourceName string, origin int64, value uint32) (cv *CommandValue, err error)

NewUint32Value creates a CommandValue of Type Uint32 with the given value.

func NewUint64ArrayValue added in v1.2.0

func NewUint64ArrayValue(DeviceResourceName string, origin int64, value []uint64) (cv *CommandValue, err error)

NewUint64ArrayValue creates a CommandValue of Type Uint64Array with the given value.

func NewUint64Value

func NewUint64Value(DeviceResourceName string, origin int64, value uint64) (cv *CommandValue, err error)

NewUint64Value creates a CommandValue of Type Uint64 with the given value.

func NewUint8ArrayValue added in v1.2.0

func NewUint8ArrayValue(DeviceResourceName string, origin int64, value []uint8) (cv *CommandValue, err error)

NewUint8ArrayValue creates a CommandValue of Type Uint8Array with the given value.

func NewUint8Value

func NewUint8Value(DeviceResourceName string, origin int64, value uint8) (cv *CommandValue, err error)

NewUint8Value creates a CommandValue of Type Uint8 with the given value.

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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) String

func (cv *CommandValue) String() (str 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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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(encoding ...string) (str string)

ValueToString returns the string format of the value. In EdgeX, float value has two kinds of representation, Base64, and eNotation. Users can specify the floatEncoding in the properties value of the device profile, like floatEncoding: "Base64" or floatEncoding: "eNotation".

func (*CommandValue) ValueTypeToString added in v1.2.0

func (cv *CommandValue) ValueTypeToString() string

ValueTypeToString returns corresponding string representation of the ValueType.

type DiscoveredDevice added in v1.2.0

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

DiscoveredDevice defines the required information for a found device.

type Event

type Event struct {
	contract.Event
	EncodedEvent []byte
}

Event is a wrapper of contract.Event to provide more Binary related operation in Device Service.

func (Event) HasBinaryValue

func (e Event) HasBinaryValue() bool

HasBinaryValue confirms whether an event contains one or more readings populated with a BinaryValue payload.

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]contract.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]contract.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]contract.ProtocolProperties, adminState contract.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]contract.ProtocolProperties, adminState contract.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]contract.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.

type ValueType

type ValueType int

ValueType indicates the type of value being passed back from a ProtocolDriver instance.

const (
	// Bool indicates that the value is a bool,
	// stored in CommandValue's boolRes member.
	Bool ValueType = iota
	// BoolArray indicates that the value is array of bool,
	// store in CommandValue's stringValue member.
	BoolArray
	// String indicates that the value is a string,
	// stored in CommandValue's stringRes member.
	String
	// Uint8 indicates that the value is a uint8 that
	// is stored in CommandValue's NumericRes member.
	Uint8
	// Uint8Array indicates that the value is array of uint8,
	// store in CommandValue's stringValue member.
	Uint8Array
	// Uint16 indicates that the value is a uint16 that
	// is stored in CommandValue's NumericRes member.
	Uint16
	// Uint16Array indicates that the value is array of uint16,
	// store in CommandValue's stringValue member.
	Uint16Array
	// Uint32 indicates that the value is a uint32 that
	// is stored in CommandValue's NumericRes member.
	Uint32
	// Uint32Array indicates that the value is array of uint32,
	// store in CommandValue's stringValue member.
	Uint32Array
	// Uint64 indicates that the value is a uint64 that
	// is stored in CommandValue's NumericRes member.
	Uint64
	// Uint64Array indicates that the value is array of uint64,
	// store in CommandValue's stringValue member.
	Uint64Array
	// Int8 indicates that the value is a int8 that
	// is stored in CommandValue's NumericRes member.
	Int8
	// Int8Array indicates that the value is array of int8,
	// store in CommandValue's stringValue member.
	Int8Array
	// Int16 indicates that the value is a int16 that
	// is stored in CommandValue's NumericRes member.
	Int16
	// Int16Array indicates that the value is array of int16,
	// store in CommandValue's stringValue member.
	Int16Array
	// Int32 indicates that the value is a int32 that
	// is stored in CommandValue's NumericRes member.
	Int32
	// Int32Array indicates that the value is array of int32,
	// store in CommandValue's stringValue member.
	Int32Array
	// Int64 indicates that the value is a int64 that
	// is stored in CommandValue's NumericRes member.
	Int64
	// Int64Array indicates that the value is array of int64,
	// store in CommandValue's stringValue member.
	Int64Array
	// Float32 indicates that the value is a float32 that
	// is stored in CommandValue's NumericRes member.
	Float32
	// Float32Array indicates that the value is array of float32,
	// store in CommandValue's stringValue member.
	Float32Array
	// Float64 indicates that the value is a float64 that
	// is stored in CommandValue's NumericRes member.
	Float64
	// Float64Array indicates that the value is array of float64,
	// store in CommandValue's stringValue member.
	Float64Array
	// Binary indicates that the value is a binary payload that
	// is stored in CommandValue's ByteArrRes member.
	Binary
)

func ParseValueType

func ParseValueType(typeName string) ValueType

ParseValueType could get ValueType from type name in string format if the type name cannot be parsed correctly, return String ValueType

Jump to

Keyboard shortcuts

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