thingmodel

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const Version = "1.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type ACK

type ACK struct {
	// 默认情况下设备属性上报后云端不会返回应答消息,
	// 但可以通过ack参数改变这一默认行为:
	// 0:不做应答(默认)
	// :处理之后返回应答消息
	Ack int8 `json:"ack"`
}

type Action

type Action struct {
	AbilityId    string
	ProductId    string
	Code         string
	Name         string
	Description  string
	InputParams  []InputOutput
	OutputParams []InputOutput
	Attributes   map[string]string // 自定义
}

Action 物模型动作定义

type ActionDataIn

type ActionDataIn struct {
	ActionCode  string                 `json:"actionCode"`
	InputParams map[string]interface{} `json:"inputParams"`
}

云端-->TEdge-->驱动:设备执行动作入参

type ActionDataOut

type ActionDataOut struct {
	ActionCode   string                 `json:"actionCode"`
	OutputParams map[string]interface{} `json:"outputParams"`
}

驱动-->云端-->TEdge:设备执行动作结果出参

type ActionExecuteRequest

type ActionExecuteRequest struct {
	CommonRequest `json:",inline"`
	Data          ActionDataIn `json:"data"`
	Spec          Action       `json:"-"`
}

ActionExecuteRequest 执行设备动作请求

type ActionExecuteResponse

type ActionExecuteResponse struct {
	CommonResponse `json:",inline"`
	Data           ActionDataOut `json:"data"`
}

ActionExecuteResponse 执行设备动作响应

func NewActionExecuteResponse

func NewActionExecuteResponse(statusCode int64, msgId string, data ActionDataOut) ActionExecuteResponse

statusCode: 响应状态码,0代表成功,非0代表失败,默认0

type AddProductReq

type AddProductReq struct {
	Id          string
	Name        string
	Model       string
	Description string
}

AddProductReq 添加产品

type BatchData

type BatchData struct {
	Properties map[string]BatchProperty `json:"properties"`
	Events     map[string]BatchEvent    `json:"events"`
}

BatchReport 设备批量上报

type BatchEvent

type BatchEvent struct {
	EventTime    int64                  `json:"eventTime"`
	OutputParams map[string]interface{} `json:"outputParams"`
}

BatchReport 设备批量上报

type BatchProperty

type BatchProperty struct {
	Value interface{} `json:"value"` // 上报的属性值
	Time  int64       `json:"time"`  // 属性变更时间戳
}

BatchReport 设备批量上报

type BatchReport

type BatchReport struct {
	CommonRequest `json:",inline"`
	Data          BatchData `json:"data"`
}

BatchReport 设备批量上报

func NewBatchReport

func NewBatchReport(needACK bool, data BatchData) BatchReport

type CommonRequest

type CommonRequest struct {
	Version string `json:"version"` // 默认仅有1.0
	MsgId   string `json:"msgId"`   // 长度不超过32位
	Time    int64  `json:"time"`    // 消息发送时的unix时间戳(10位秒级或13位毫秒级)
	Sys     ACK    `json:"sys"`     // 控制消息的系统行为
}

type CommonResponse

type CommonResponse struct {
	Version string `json:"version"`
	MsgId   string `json:"msgId"`
	Time    int64  `json:"time"`
	Code    int64  `json:"code"` // 0代表成功,非0代表失败,默认0
}

CommonResponse 云端一般响应

func NewCommonResponse

func NewCommonResponse(t, code int64, msgId string) CommonResponse

type Event

type Event struct {
	AbilityId    string
	ProductId    string
	Code         string
	Name         string
	Description  string
	OutputParams []InputOutput
	Attributes   map[string]string // 自定义
}

Event 物模型事件定义

type EventData

type EventData struct {
	EventCode    string                 `json:"eventCode"`
	EventTime    int64                  `json:"eventTime"`
	OutputParams map[string]interface{} `json:"outputParams"`
}

func NewEventData

func NewEventData(ec string, t int64, data map[string]interface{}) EventData

type EventReport

type EventReport struct {
	CommonRequest `json:",inline"`
	Data          EventData `json:"data"`
}

驱动-->云端-->TEdge:设备向云端上报事件

func NewEventReport

func NewEventReport(needACK bool, data EventData) EventReport

type HttpRequestParam

type HttpRequestParam struct {
	Url     string `json:"url"`
	Api     string `json:"api"`
	Version string `json:"version"`
}

type InputOutput

type InputOutput struct {
	Code     string
	Name     string
	TypeSpec TypeSpec
}

type Property

type Property struct {
	Value interface{} `json:"value"` // 上报的属性值
	Time  int64       `json:"time"`  // 属性变更时间戳
}

func NewProperty

func NewProperty(value interface{}) Property

type PropertyData

type PropertyData struct {
	Properties []string `json:"properties"`
}

type PropertyDesiredDelete

type PropertyDesiredDelete struct {
	CommonRequest `json:",inline"`
	Data          map[string]PropertyDesiredDeleteValue `json:"data"`
}

PropertyDesiredDelete 设备清除属性期望值

type PropertyDesiredDeleteResponse

type PropertyDesiredDeleteResponse struct {
	CommonResponse `json:",inline"`
	Data           map[string]PropertyDesiredGetValue `json:"data"`
}

PropertyDesiredDeleteResponse 设备清除属性期望值响应

type PropertyDesiredDeleteValue

type PropertyDesiredDeleteValue struct {
	Version int64 `json:"version"`
}

type PropertyDesiredGet

type PropertyDesiredGet struct {
	CommonRequest `json:",inline"`
	//Data          []string `json:"data"`
	PropertyData `json:"data"`
}

PropertyDesiredGet 设备拉取属性期望值

func NewPropertyDesiredGet

func NewPropertyDesiredGet(data []string) PropertyDesiredGet

type PropertyDesiredGetResponse

type PropertyDesiredGetResponse struct {
	CommonResponse `json:",inline"`
	Data           map[string]PropertyDesiredGetValue `json:"data"`
}

PropertyDesiredGetResponse 设备拉取属性期望值响应

type PropertyDesiredGetValue

type PropertyDesiredGetValue struct {
	Value   interface{} `json:"value"`
	Version int64       `json:"version"`
}

type PropertyGet

type PropertyGet struct {
	CommonRequest `json:",inline"`
	Data          []string                `json:"data"`
	Spec          map[string]PropertySpec `json:"-"`
}

PropertyGet 属性查询,查询的属性code列表,如果为空代表查询所有属性

type PropertyGetResponse

type PropertyGetResponse struct {
	CommonResponse `json:",inline"`
	Data           map[string]Property `json:"data"`
}

PropertyGetResponse 属性查询设备响应

func NewPropertyGetResponse

func NewPropertyGetResponse(statusCode int64, msgId string, data map[string]Property) PropertyGetResponse

statusCode: 响应状态码,0 代表成功,非 0 代表失败,默认 0

type PropertyReport

type PropertyReport struct {
	CommonRequest `json:",inline"`
	Data          map[string]Property `json:"data"`
}

PropertyReport 属性上报 属性查询响应

func NewPropertyReport

func NewPropertyReport(needACK bool, data map[string]Property) PropertyReport

type PropertySet

type PropertySet struct {
	CommonRequest `json:",inline"`
	Data          map[string]interface{}  `json:"data"`
	Spec          map[string]PropertySpec `json:"-"`
}

云端-->TEdge-->驱动:设备属性下发

type PropertySpec

type PropertySpec struct {
	AbilityId  string
	ProductId  string
	Code       string
	Name       string
	AccessMode string
	TypeSpec   TypeSpec
	Attributes map[string]string // 自定义
}

PropertySpec 物模型属性定义

type ThingModelDriver

type ThingModelDriver interface {
	// DeviceNotify 设备增删改通知,删除设备时device参数为空
	DeviceNotify(ctx context.Context, t commons.DeviceNotifyType, cid string, device commons.TMDeviceInfo) error

	// ProductNotify 产品增删改通知,删除产品时product参数为空
	ProductNotify(ctx context.Context, t commons.ProductNotifyType, pid string, product ThingModelProduct) error

	// HandlePropertySet set device property, from cloud or web
	HandlePropertySet(ctx context.Context, cid string, data PropertySet, protocols map[string]commons.ProtocolProperties) error
	// HandlePropertyGet get device property, from cloud
	HandlePropertyGet(ctx context.Context, cid string, data PropertyGet, protocols map[string]commons.ProtocolProperties) error
	// HandleActionExecute device command, from cloud or web
	HandleActionExecute(ctx context.Context, cid string, data ActionExecuteRequest, protocols map[string]commons.ProtocolProperties) error

	Stop(ctx context.Context) error
}

type ThingModelProduct

type ThingModelProduct struct {
	Id              string
	Name            string
	Description     string
	Model           string
	Action          []Action
	Event           []Event
	Property        []PropertySpec
	DeviceLibraryId string
}

ThingModelProduct 物模型产品定义

type TypeSpec

type TypeSpec struct {
	Properties      map[string]PropertySpec
	ElementTypeSpec *TypeSpec
	Type            commons.DataType
	Min             int64
	Max             int64
	Step            int64
	Unit            string
	Scale           int64
	MaxLen          int64
	Range           []string
	Label           []string
	DefaultValue    string
}

Jump to

Keyboard shortcuts

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