contracts

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryKey   = "category"
	DefaultModule = "default"
	Separator     = ":"
)

Variables

This section is empty.

Functions

func ConcatResourceName

func ConcatResourceName(module string, resource string) string

ConcatResourceName will concat the module and resource defined in vei console to edgex resource name.

func IsEvent

func IsEvent(req models.CommandRequest) bool

IsEvent checks whether the device resource is an event.

func IsProperty

func IsProperty(req models.CommandRequest) bool

IsProperty checks whether the device resource is a property.

func IsService

func IsService(req models.CommandRequest) bool

IsService checks whether the device resource is a service.

func SetResourceCategory

func SetResourceCategory(attributes map[string]interface{}, category ResourceCategory) map[string]interface{}

SetResourceCategory set the resource category into attributes.

func SplitResourceName

func SplitResourceName(full string) (module string, resource string)

SplitResourceName will split the edgex resource name to the module and resource defined in vei console.

Types

type AsyncValues

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

AsyncValues is the struct for sending Device readings asynchronously via ProtocolDrivers

func (*AsyncValues) Transform

func (v *AsyncValues) Transform() *models.AsyncValues

type BaseRequest

type BaseRequest interface {
	// Native returns the native command request.
	Native() *models.CommandRequest
	// Module returns the thingmodel module where the resource belongs to.
	Module() string
	// Resource returns the identifier of the thingmodel resource.
	Resource() string
	// ValueType returns the value type of the thingmodel resource.
	ValueType() ValueType
	// Attributes returns the attributes defined for the thingmodel resource.
	Attributes() map[string]interface{}
	// SetResult set the handle result of the request.
	SetResult(result Result)
	// Result get the handle result of the request.
	Result() Result
	// Failed set the error encountered when handling the request.
	Failed(error error)
	// Error returns the error encountered when handling the request.
	Error() error
	// Skip will skip the request.
	Skip()
	// Skipped indicates whether the request is skipped or not.
	Skipped() bool
}

type CallRequest

type CallRequest interface {
	BaseRequest
	// Payload returns the payload of the call request.
	Payload() []byte
}

func NewCallRequest

func NewCallRequest(req models.CommandRequest) (CallRequest, error)

type Device

type Device struct {
	Name           string                               `json:"name"`
	Protocols      map[string]models.ProtocolProperties `json:"protocols"`
	OperatingState OperatingState                       `json:"operating_state,omitempty"`
	Message        string                               `json:"message,omitempty"`
}

Device contains the necessary information of a device.

func WrapDevice

func WrapDevice(name string, protocols map[string]models.ProtocolProperties) *Device

func (*Device) GetProtocolByName

func (d *Device) GetProtocolByName(name string) (models.ProtocolProperties, bool)

GetProtocolByName returns the protocol specified by name.

func (*Device) SetOperatingState

func (d *Device) SetOperatingState(state OperatingState, message string)

SetOperatingState supports to set the device state customarily.

func (*Device) SetStateDown

func (d *Device) SetStateDown()

SetStateDown set the device state to DOWN.

func (*Device) SetStateUp

func (d *Device) SetStateUp()

SetStateUp set the device state to UP.

func (*Device) UpdateStateByError added in v1.1.2

func (d *Device) UpdateStateByError(raw error)

type Error added in v1.1.2

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

func NewError added in v1.1.2

func NewError(kind ErrorKind, err error) *Error

func NewErrorWithReason added in v1.1.2

func NewErrorWithReason(kind ErrorKind, reason string) *Error

func (*Error) Error added in v1.1.2

func (e *Error) Error() string

type ErrorKind added in v1.1.2

type ErrorKind string
const (
	DeviceNotFound          ErrorKind = "设备未找到"
	DeviceLoadFailed        ErrorKind = "设备加载失败"
	ProtocolMissing         ErrorKind = "协议缺失"
	ProtocolParseFailed     ErrorKind = "协议解析失败"
	ProtocolUnsupported     ErrorKind = "协议暂不支持"
	AuthFailed              ErrorKind = "鉴权失败"
	LoginFailed             ErrorKind = "登录失败"
	WrongPassword           ErrorKind = "用户名密码错误"
	ConnectionFailed        ErrorKind = "无法建立连接"
	ConnectionTimeout       ErrorKind = "连接超时"
	NetworkUnreachable      ErrorKind = "网络不可达"
	ResourceNotFound        ErrorKind = "资源未找到"
	ResourceTypeUnsupported ErrorKind = "资源类型暂不支持"
	AttributeParseFailed    ErrorKind = "点表解析失败"
	ParameterParseFailed    ErrorKind = "参数解析失败"
	DataParseError          ErrorKind = "数据解析错误"
	ReadError               ErrorKind = "数据读取错误"
	ReadTimeout             ErrorKind = "数据读取超时"
	WriteError              ErrorKind = "数据写入错误"
	WriteTimeout            ErrorKind = "数据写入超时"
)

type NativeResult

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

func NewNativeResult

func NewNativeResult(native *models.CommandValue) *NativeResult

func (*NativeResult) CommandValue

func (r *NativeResult) CommandValue(_ string, _ string) (*models.CommandValue, error)

func (*NativeResult) Tags

func (r *NativeResult) Tags() map[string]string

func (*NativeResult) UnixNano

func (r *NativeResult) UnixNano() int64

func (*NativeResult) Value

func (r *NativeResult) Value() interface{}

type OperatingState

type OperatingState string

OperatingState is an indication of the operations of the device.

const (
	UP          OperatingState = "Up"
	DOWN        OperatingState = "Down"
	UNKNOWN     OperatingState = "Unknown"
	REACHABLE   OperatingState = "Reachable"
	UNREACHABLE OperatingState = "Unreachable"
)

func (OperatingState) String

func (s OperatingState) String() string

type ReadRequest

type ReadRequest interface {
	BaseRequest
}

func NewReadRequest

func NewReadRequest(req models.CommandRequest) ReadRequest

type ResourceCategory

type ResourceCategory string

ResourceCategory indicates the category of device resource

const (
	Property ResourceCategory = "property"
	Service  ResourceCategory = "service"
	Event    ResourceCategory = "event"
)

func GetResourceCategory

func GetResourceCategory(req models.CommandRequest) ResourceCategory

GetResourceCategory get the category of resource from the request. Property is returned by default for the compatibility.

func (ResourceCategory) String

func (c ResourceCategory) String() string

type Result

type Result interface {
	// Value returns the value read by driver instance.
	Value() interface{}
	// UnixNano returns the unix nano timestamp of the result read by driver instance.
	UnixNano() int64
	// Tags returns the custom information of the result.
	Tags() map[string]string
	// CommandValue constructs EdgeX CommandValue based on the content of the result.
	CommandValue(resourceName string, valueType string) (*models.CommandValue, error)
}

Result defines the interface for a result of the Request.

type SimpleResult

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

func NewSimpleResult

func NewSimpleResult(value interface{}) *SimpleResult

func (*SimpleResult) CommandValue

func (r *SimpleResult) CommandValue(resourceName string, valueType string) (*models.CommandValue, error)

func (*SimpleResult) Tags

func (r *SimpleResult) Tags() map[string]string

func (*SimpleResult) UnixNano

func (r *SimpleResult) UnixNano() int64

func (*SimpleResult) Value

func (r *SimpleResult) Value() interface{}

func (*SimpleResult) WithCast added in v1.1.1

func (r *SimpleResult) WithCast(cast bool) *SimpleResult

func (*SimpleResult) WithTags

func (r *SimpleResult) WithTags(tags map[string]string) *SimpleResult

func (*SimpleResult) WithTime

func (r *SimpleResult) WithTime(origin time.Time) *SimpleResult

type ValueType

type ValueType string

ValueType indicates the type of reading value

const (
	Bool         ValueType = "Bool"
	String       ValueType = "String"
	Uint8        ValueType = "Uint8"
	Uint16       ValueType = "Uint16"
	Uint32       ValueType = "Uint32"
	Uint64       ValueType = "Uint64"
	Int8         ValueType = "Int8"
	Int16        ValueType = "Int16"
	Int32        ValueType = "Int32"
	Int64        ValueType = "Int64"
	Float32      ValueType = "Float32"
	Float64      ValueType = "Float64"
	Binary       ValueType = "Binary"
	BoolArray    ValueType = "BoolArray"
	StringArray  ValueType = "StringArray"
	Uint8Array   ValueType = "Uint8Array"
	Uint16Array  ValueType = "Uint16Array"
	Uint32Array  ValueType = "Uint32Array"
	Uint64Array  ValueType = "Uint64Array"
	Int8Array    ValueType = "Int8Array"
	Int16Array   ValueType = "Int16Array"
	Int32Array   ValueType = "Int32Array"
	Int64Array   ValueType = "Int64Array"
	Float32Array ValueType = "Float32Array"
	Float64Array ValueType = "Float64Array"
	Object       ValueType = "Object"
)

func (ValueType) String

func (t ValueType) String() string

type WriteRequest

type WriteRequest interface {
	BaseRequest
	// Param returns the input parameter of the write request.
	Param() *models.CommandValue
}

func NewWriteRequest

func NewWriteRequest(req models.CommandRequest, param *models.CommandValue) WriteRequest

Jump to

Keyboard shortcuts

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