common

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEVSTOK        = "OK"
	DEVSTERR       = "ERROR"        /* Expected value is not equal as setting */
	DEVSTDISCONN   = "DISCONNECTED" /* Disconnected */
	DEVSTUNHEALTHY = "UNHEALTHY"    /* Unhealthy status from device */
	DEVSTUNKNOWN   = "UNKNOWN"
)

Device status definition.

View Source
const (
	PushMethodHTTP = "http"
	PushMethodMQTT = "mqtt"
)
View Source
const (
	DevInitModeRegister  = "register"
	DevInitModeConfigmap = "configmap"
)
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"`
}

type DBMethodConfig

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

type DataMetadata

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

DataMetadata data metadata.

type DataModel

type DataModel struct {
	// TODO DataModel is standardized data, need add field
	DeviceName   string
	PropertyName 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, 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"`
}

DeviceInstance is structure to store device in deviceProfile.json in configmap.

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 deviceModel in deviceProfile.json in configmap.

type DeviceProfile

type DeviceProfile struct {
	DeviceInstances []DeviceInstance `json:"deviceInstances,omitempty"`
	DeviceModels    []DeviceModel    `json:"deviceModels,omitempty"`
	Protocols       []ProtocolConfig `json:"protocols,omitempty"`
}

DeviceProfile is structure to store in configMap. It will be removed later

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 deviceProfile.json in configmap.

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 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 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"`
}

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