common

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Index

Constants

View Source
const (
	DeviceStatusOK        = "ok"
	DeviceStatusOnline    = "online"
	DeviceStatusOffline   = "offline"
	DeviceStatusDisCONN   = "disconnected" /* Disconnected */
	DeviceStatusUnhealthy = "unhealthy"    /* Unhealthy status from device */
	DeviceStatusUnknown   = "unknown"
)

Device status definition.

View Source
const (
	PushMethodHTTP = "http"
	PushMethodMQTT = "mqtt"
	PushMethodOTEL = "otel"
)
View Source
const (
	DevInitModeRegister  = "register"
	DevInitModeConfigmap = "configmap"
)
View Source
const (
	SaveFrame = "saveFrame"
	SaveVideo = "saveVideo"
)
View Source
const (
	TopicTwinUpdateDelta = "$hw/events/device/%s/twin/update/delta"
	TopicTwinUpdate      = "$hw/events/device/%s/twin/update"
	TopicStateUpdate     = "$hw/events/device/%s/state/update"
	TopicDataUpdate      = "$ke/events/device/%s/data/update"
)

Joint the topic like topic := fmt.Sprintf(TopicTwinUpdateDelta, deviceID)

View Source
const DefaultCollectCycle = time.Second
View Source
const DefaultReportCycle = time.Second
View Source
const (
	ProtocolCustomized = "customized-protocol"
)

Variables

This section is empty.

Functions

func Convert

func Convert(valueType string, value string) (result interface{}, err error)

Convert string to other types

func ConvertToString

func ConvertToString(value interface{}) (string, error)

ConvertToString other types to string

func CreateMessageData

func CreateMessageData(name string, valueType string, value string) (msg []byte, err error)

CreateMessageData create data message.

func CreateMessageTwinUpdate

func CreateMessageTwinUpdate(name string, valueType string, value string, expectValue string) (msg []byte, err error)

CreateMessageTwinUpdate create twin update message.

func DecodeAnyValue

func DecodeAnyValue(value *anypb.Any) (interface{}, error)

DecodeAnyValue Any to interface

Types

type BaseMessage

type BaseMessage struct {
	EventID   string `json:"event_id"`
	Timestamp int64  `json:"timestamp"`
}

BaseMessage the base structure of event message.

type DBConfig

type DBConfig struct {
	Influxdb2ClientConfig json.RawMessage `json:"influxdb2ClientConfig"`
	Influxdb2DataConfig   json.RawMessage `json:"influxdb2DataConfig"`
	RedisClientConfig     json.RawMessage `json:"redisClientConfig"`
	TDEngineClientConfig  json.RawMessage `json:"TDEngineClientConfig"`
	MySQLClientConfig     json.RawMessage `json:"mysqlClientConfig"`
}

type DBMethodConfig

type DBMethodConfig struct {
	DBMethodName string   `json:"dbMethodName"`
	DBConfig     DBConfig `json:"dbConfig"`
}

DBMethodConfig is structure to store database config

type DataMetadata

type DataMetadata struct {
	Timestamp int64  `json:"timestamp"`
	Type      string `json:"type"`
}

DataMetadata data metadata.

type DataMethod added in v1.19.0

type DataMethod struct {
	Methods []Method
}

DataMethod defined standard model for deviceMethod

type DataModel

type DataModel struct {
	// TODO DataModel is standardized data, need add field
	DeviceName   string
	PropertyName string
	Namespace    string

	Value string
	Type  string

	TimeStamp int64
}

DataModel defined standard data model for transferring data between interfaces

func NewDataModel

func NewDataModel(deviceName string, propertyName string, namespace string, options ...Option) *DataModel

func (*DataModel) SetTimeStamp

func (dm *DataModel) SetTimeStamp()

func (*DataModel) SetType

func (dm *DataModel) SetType(dataType string)

func (*DataModel) SetValue

func (dm *DataModel) SetValue(data string)

type DataValue

type DataValue struct {
	Value    string       `json:"value"`
	Metadata DataMetadata `json:"metadata"`
}

DataValue data value.

type DeviceData

type DeviceData struct {
	BaseMessage
	Data map[string]*DataValue `json:"data"`
}

DeviceData device data structure.

type DeviceInstance

type DeviceInstance struct {
	ID           string `json:"id,omitempty"`
	Name         string `json:"name,omitempty"`
	Namespace    string `json:"namespace,omitempty"`
	ProtocolName string `json:"protocol,omitempty"`
	PProtocol    ProtocolConfig
	Model        string           `json:"model,omitempty"`
	Twins        []Twin           `json:"twins,omitempty"`
	Properties   []DeviceProperty `json:"properties,omitempty"`
	Methods      []DeviceMethod   `json:"methods,omitempty"`
	Status       DeviceStatus     `json:"status,omitempty"`
}

DeviceInstance is structure to store detailed information about the device in the mapper.

type DeviceMethod added in v1.19.0

type DeviceMethod struct {
	// Required: The device method name to be accessed. It must be unique.
	Name string `json:"name,omitempty"`
	// Define the description of device method.
	// +optional
	Description string `json:"description,omitempty"`
	// PropertyNames are list of device properties that device methods can control.
	// Required: A device method can control multiple device properties.
	PropertyNames []string `json:"propertyNames,omitempty"`
}

DeviceMethod is structure to store method in device.

type DeviceModel

type DeviceModel struct {
	ID          string          `json:"id,omitempty"`
	Name        string          `json:"name,omitempty"`
	Namespace   string          `json:"namespace,omitempty"`
	Description string          `json:"description,omitempty"`
	Properties  []ModelProperty `json:"properties,omitempty"`
}

DeviceModel is structure to store detailed information about the devicemodel in the mapper.

type DeviceProperty

type DeviceProperty struct {
	Name         string          `json:"name,omitempty"`
	PropertyName string          `json:"propertyName,omitempty"`
	ModelName    string          `json:"modelName,omitempty"`
	Protocol     string          `json:"protocol,omitempty"`
	Visitors     json.RawMessage `json:"visitorConfig"`
	// whether be reported to the cloud
	ReportToCloud bool             `json:"reportToCloud,omitempty"`
	CollectCycle  int64            `json:"collectCycle"`
	ReportCycle   int64            `json:"reportCycle,omitempty"`
	PushMethod    PushMethodConfig `json:"pushMethod,omitempty"`
	PProperty     ModelProperty
}

DeviceProperty is structure to store propertyVisitor in device.

type DeviceStatus added in v1.19.0

type DeviceStatus struct {
	// whether be reported to the cloud
	ReportToCloud bool  `json:"reportToCloud,omitempty"`
	ReportCycle   int64 `json:"reportCycle,omitempty"`
}

DeviceStatus is structure to store parameters for device status reporting.

type DeviceTwinDelta

type DeviceTwinDelta struct {
	BaseMessage
	Twin  map[string]*MsgTwin `json:"twin"`
	Delta map[string]string   `json:"delta"`
}

DeviceTwinDelta twin delta.

type DeviceTwinResult

type DeviceTwinResult struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinResult device get result.

type DeviceTwinUpdate

type DeviceTwinUpdate struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinUpdate the structure of device twin update.

type DeviceUpdate

type DeviceUpdate struct {
	BaseMessage
	State      string              `json:"state,omitempty"`
	Attributes map[string]*MsgAttr `json:"attributes"`
}

DeviceUpdate device update.

type Metadata

type Metadata struct {
	Timestamp string `json:"timestamp,omitempty"`
	Type      string `json:"type,omitempty"`
}

Metadata is the metadata for data.

type Method added in v1.19.0

type Method struct {
	Name       string
	Path       string
	Parameters []Parameter
}

type ModelProperty

type ModelProperty struct {
	Name        string `json:"name,omitempty"`
	DataType    string `json:"dataType,omitempty"`
	Description string `json:"description,omitempty"`
	AccessMode  string `json:"accessMode,omitempty"`
	Minimum     string `json:"minimum,omitempty"`
	Maximum     string `json:"maximum,omitempty"`
	Unit        string `json:"unit,omitempty"`
}

ModelProperty is structure to store deviceModel property.

type MsgAttr

type MsgAttr struct {
	Value    string        `json:"value"`
	Optional *bool         `json:"optional,omitempty"`
	Metadata *TypeMetadata `json:"metadata,omitempty"`
}

MsgAttr the struct of device attr

type MsgTwin

type MsgTwin struct {
	Expected        *TwinValue    `json:"expected,omitempty"`
	Actual          *TwinValue    `json:"actual,omitempty"`
	Optional        *bool         `json:"optional,omitempty"`
	Metadata        *TypeMetadata `json:"metadata,omitempty"`
	ExpectedVersion *TwinVersion  `json:"expected_version,omitempty"`
	ActualVersion   *TwinVersion  `json:"actual_version,omitempty"`
}

MsgTwin the structure of device twin.

type Option

type Option func(*DataModel)

func WithTimeStamp

func WithTimeStamp(timeStamp int64) Option

func WithType

func WithType(dataType string) Option

func WithValue

func WithValue(data string) Option

type Parameter added in v1.19.0

type Parameter struct {
	PropertyName string
	ValueType    string
}

type ProtocolConfig

type ProtocolConfig struct {
	// Unique protocol name
	// Required.
	ProtocolName string `json:"protocolName,omitempty"`
	// Any config data
	// +optional
	// +kubebuilder:validation:XPreserveUnknownFields
	ConfigData json.RawMessage `json:"configData,omitempty"`
}

ProtocolConfig is structure to store protocol information in device.

type PushMethodConfig

type PushMethodConfig struct {
	MethodName   string          `json:"MethodName"`
	MethodConfig json.RawMessage `json:"MethodConfig"`
	DBMethod     DBMethodConfig  `json:"dbMethod,omitempty"`
}

PushMethodConfig is structure to store push config

type Twin

type Twin struct {
	PropertyName    string `json:"propertyName,omitempty"`
	Property        *DeviceProperty
	ObservedDesired TwinProperty `json:"observedDesired,omitempty"`
	Reported        TwinProperty `json:"reported,omitempty"`
}

Twin is the set/get pair to one register.

type TwinProperty

type TwinProperty struct {
	// Required: The value for this property.
	Value string `json:"value,"`
	// Additional metadata like timestamp when the value was reported etc.
	// +optional
	Metadata Metadata `json:"metadata,omitempty"`
}

type TwinValue

type TwinValue struct {
	Value    *string       `json:"value,omitempty"`
	Metadata ValueMetadata `json:"metadata,omitempty"`
}

TwinValue the structure of twin value.

type TwinVersion

type TwinVersion struct {
	CloudVersion int64 `json:"cloud"`
	EdgeVersion  int64 `json:"edge"`
}

TwinVersion twin version.

type TypeMetadata

type TypeMetadata struct {
	Type string `json:"type,omitempty"`
}

TypeMetadata the meta of value type.

type ValueMetadata

type ValueMetadata struct {
	Timestamp string `json:"timestamp,omitempty"`
}

ValueMetadata the meta of value.

Jump to

Keyboard shortcuts

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