device

package
v0.0.0-...-592b0ac Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BOOL      = "bool"
	INT       = "int"
	STRING    = "string"
	STRUCT    = "struct"
	FLOAT     = "float"
	TIMESTAMP = "timestamp"
	ARRAY     = "array"
	ENUM      = "enum"
)

数据类型

Variables

This section is empty.

Functions

func ToVal

func ToVal(tp map[string]TempParam) map[string]interface{}

Types

type Action

type Action struct {
	ID       string            `json:"id"`       //标识符
	Name     string            `json:"name"`     //功能名称
	Desc     string            `json:"desc"`     //描述
	Input    []Param           `json:"input"`    //调用参数
	Output   []Param           `json:"output"`   //返回参数
	Required bool              `json:"required"` //是否必须
	In       map[string]*Param `json:"-"`        //内部使用,使用map加速匹配,key为id
	Out      map[string]*Param `json:"-"`        //内部使用,使用map加速匹配,key为id
}

行为

type Define

type Define struct {
	Type      string            `json:"type"`                //参数类型:bool int string struct float timestamp array enum
	Maping    map[string]string `json:"mapping,omitempty"`   //枚举及bool类型:bool enum
	Min       string            `json:"min,omitempty"`       //数值最小值:int string float
	Max       string            `json:"max,omitempty"`       //数值最大值:int string float
	Start     string            `json:"start,omitempty"`     //初始值:int float
	Step      string            `json:"step,omitempty"`      //步长:int float
	Unit      string            `json:"unit,omitempty"`      //单位:int float
	Specs     []Spec            `json:"specs,omitempty"`     //结构体:struct
	ArrayInfo *Define           `json:"arrayInfo,omitempty"` //数组:array
	Spec      map[string]*Spec  //内部使用,使用map加速匹配,key为id
}

数据类型定义

func (*Define) GetVal

func (d *Define) GetVal(val interface{}) (interface{}, error)

type DeviceData

type DeviceData struct {
	Property map[string]interface{} `json:"property"` //属性
	Event    struct {
		ID     string                 `json:"id"`     //事件id
		Type   string                 `json:"type"`   //事件类型: 信息:info  告警alert  故障:fault
		Params map[string]interface{} `json:"params"` //事件参数
	} `json:"event"` //事件
	TimeStamp time.Time `json:"timeStamp"` //时间戳
}

type DeviceReq

type DeviceReq struct {
	Method      string                 `json:"method"`             //操作方法
	ClientToken string                 `json:"clientToken"`        //方便排查随机数
	Params      map[string]interface{} `json:"params,omitempty"`   //参数列表
	Version     string                 `json:"version,omitempty"`  //协议版本,默认为1.0。
	EventID     string                 `json:"eventId,omitempty"`  //事件的 Id,在数据模板事件中定义。
	ActionID    string                 `json:"actionId,omitempty"` //数据模板中的行为标识符,由开发者自行根据设备的应用场景定义
	Timestamp   int64                  `json:"timestamp,omitempty"`
	Showmeta    int64                  `json:"showmeta,omitempty"` //标识回复消息是否带 metadata,缺省为0表示不返回 metadata
	Type        string                 `json:"type,omitempty"`     //	表示获取什么类型的信息。report:表示设备上报的信息 info:信息 alert:告警 fault:故障
	Code        int64                  `json:"code,omitempty"`     //状态码
	Status      string                 `json:"status,omitempty"`   //返回信息
}

func (DeviceReq) AddStatus

func (d DeviceReq) AddStatus(err error) DeviceReq

type DeviceResp

type DeviceResp struct {
	Method      string                 `json:"method"`             //操作方法
	ClientToken string                 `json:"clientToken"`        //方便排查随机数
	Version     string                 `json:"version,omitempty"`  //协议版本,默认为1.0。
	Code        int64                  `json:"code"`               //状态码
	Status      string                 `json:"status,omitempty"`   //返回信息
	Type        string                 `json:"type,omitempty"`     //	表示什么类型的信息。report:表示设备上报的信息
	Data        map[string]interface{} `json:"data,omitempty"`     //返回具体设备上报的最新数据内容
	Response    map[string]interface{} `json:"response,omitempty"` //设备行为中定义的返回参数,设备行为执行成功后,向云端返回执行结果
}

func (DeviceResp) AddStatus

func (d DeviceResp) AddStatus(err error) DeviceResp

type Event

type Event struct {
	ID       string            `json:"id"`       //标识符
	Name     string            `json:"name"`     //功能名称
	Desc     string            `json:"desc"`     //描述
	Type     string            `json:"type"`     //事件类型: 信息:info  告警alert  故障:fault
	Params   []Param           `json:"params"`   //事件参数
	Required bool              `json:"required"` //是否必须
	Param    map[string]*Param `json:"-"`        //内部使用,使用map加速匹配,key为id
}

事件

type METHOD

type METHOD = string
const (
	/*
		当设备需要向云端上报设备运行状态的变化时,以通知应用端小程序、App 实时展示或云端业务系统接收设备上报属性数据,物联网开发平台为设备设定了默认的 Topic:
		设备属性上行请求 Topic: $thing/up/property/{ProductID}/{DeviceName}
		设备属性上行响应 Topic: $thing/down/property/{ProductID}/{DeviceName}
	*/
	REPORT       METHOD = "report"       //表示设备属性上报
	REPORT_REPLY METHOD = "report_reply" // 表示云端接收设备上报后的响应报文

	/*
		使用数据模板协议的设备,当需要通过云端远程控制设备时,设备需订阅下发 Topic 接收云端指令:
		下发 Topic: $thing/down/property/{ProductID}/{DeviceName}
		响应 Topic: $thing/up/property/{ProductID}/{DeviceName}
	*/
	CONTROL       METHOD = "control"       //表示云端向设备发起控制请求
	CONTROL_REPLY METHOD = "control_reply" //表示设备向云端下发的控制指令的请求响应

	/*
		设备从云端接收最新消息使用的 Topic:
		请求 Topic: $thing/up/property/{ProductID}/{DeviceName}
		响应 Topic: $thing/down/property/{ProductID}/{DeviceName}
	*/
	GET_STATUS       METHOD = "get_status"       //表示获取设备最新上报的信息
	GET_STATUS_REPLY METHOD = "get_status_reply" //表示获取设备最新上报信息的 reply 消息

	/*
		当设备需要向云端上报事件时,如上报设备的故障、告警数据,开发平台为设备设定了默认的 Topic:
		设备事件上行请求 Topic: $thing/up/event/{ProductID}/{DeviceName}
		设备事件上行响应 Topic: $thing/down/event/{ProductID}/{DeviceName}
	*/
	EVENT_POST  METHOD = "event_post"  //表示事件上报
	EVENT_REPLY METHOD = "event_reply" //表示是云端返回设备端的响应

	/*
		当应用通过云端向设备发起某个行为调用时,开发平台为设备行为的处理设定了默认的 Topic:
		应用调用设备行为 Topic: $thing/down/action/{ProductID}/{DeviceName}
		设备响应行为执行结果 Topic: $thing/up/action/{ProductID}/{DeviceName}
	*/
	ACTION       METHOD = "action"       //表示是调用设备的某个行为
	ACTION_REPLY METHOD = "action_reply" //表示是设备端执行完指定的行为向云端回复的响应

	/*
		小程序或 App 展示设备详细信息时,一般会展示设备的 MAC 地址、IMEI 号、时区等基础信息。设备信息上报使用的 Topic:
		上行请求 Topic: $thing/up/property/{ProductID}/{DeviceName}
		下行响应 Topic: $thing/down/property/{ProductID}/{DeviceName}
	*/
	REPORT_INFO       METHOD = "report_info"       //表示设备基础信息上报
	REPORT_INFO_REPLY METHOD = "report_info_reply" //表示云端接收设备上报后的响应报文

	/*
		当用户在小程序或App中删除已绑定成功的设备,平台会下发用户删除设备的通知到设备,设备接收后可根据业务需求自行处理。如网关类设备接收到子设备被删除。
		下发用户删除设备 Topic: $thing/down/service/{ProductID}/{DeviceName}
	*/
	UNBIND_DEVICE METHOD = "unbind_device" // 表示是用户在小程序或 App 中删除或解绑某个设备

)

func GetMethod

func GetMethod(method METHOD) METHOD

type Param

type Param struct {
	ID     string `json:"id"`               //参数标识符
	Name   string `json:"name"`             //参数名称
	Define Define `json:"define,omitempty"` //参数定义
}

参数

type Profile

type Profile struct {
	ProductID  string `json:"ProductId"`  //产品ID
	CategoryID string `json:"CategoryId"` //产品种类ID
}

type Property

type Property struct {
	ID       string `json:"id"`       //标识符
	Name     string `json:"name"`     //功能名称
	Desc     string `json:"gesc"`     //描述
	Mode     string `json:"mode"`     //读写乐行:rw(可读可写) r(只读)
	Define   Define `json:"define"`   //数据定义
	Required bool   `json:"required"` //是否必须
}

属性

type Spec

type Spec struct {
	ID       string `json:"id"`       //参数标识符
	Name     string `json:"name"`     //参数名称
	DataType Define `json:"dataType"` //参数定义
}

结构体说明

type TEMP_TYPE

type TEMP_TYPE int64
const (
	PROPERTY TEMP_TYPE = iota
	ACTION_INPUT
	ACTION_OUTPUT
	EVENT
)

type TempParam

type TempParam struct {
	ID       string `json:"id"`       //标识符
	Name     string `json:"name"`     //功能名称
	Desc     string `json:"gesc"`     //描述
	Mode     string `json:"mode"`     //读写乐行:rw(可读可写) r(只读)
	Required bool   `json:"required"` //是否必须
	Type     string `json:"type"`     //事件类型: 信息:info  告警alert  故障:fault
	Value    struct {
		Type   string            `json:"type"`              //参数类型:bool int string struct float timestamp array enum
		Maping map[string]string `json:"mapping,omitempty"` //枚举及bool类型:bool enum
		Min    string            `json:"min,omitempty"`     //数值最小值:int string float
		Max    string            `json:"max,omitempty"`     //数值最大值:int string float
		Start  string            `json:"start,omitempty"`   //初始值:int float
		Step   string            `json:"step,omitempty"`    //步长:int float
		Unit   string            `json:"unit,omitempty"`    //单位:int float
		Value  interface{}       `json:"Value"`
	} `json:"Value"` //数据定义
}

func (*TempParam) AddDefine

func (t *TempParam) AddDefine(d *Define, val interface{}) (err error)

func (*TempParam) ToVal

func (t *TempParam) ToVal() interface{}

type Template

type Template struct {
	Version    string               `json:"version"`    //版本号
	Properties []Property           `json:"properties"` //属性
	Events     []Event              `json:"events"`     //事件
	Actions    []Action             `json:"actions"`    //行为
	Profile    Profile              `json:"profile"`    //配置信息
	Property   map[string]*Property `json:"-"`          //内部使用,使用map加速匹配,key为id
	Event      map[string]*Event    `json:"-"`          //内部使用,使用map加速匹配,key为id
	Action     map[string]*Action   `json:"-"`          //内部使用,使用map加速匹配,key为id
}

数据模板定义

func NewTemplate

func NewTemplate(templateStr []byte) (*Template, error)

func (*Template) VerifyReqParam

func (t *Template) VerifyReqParam(dq DeviceReq, tt TEMP_TYPE) (map[string]TempParam, error)

func (*Template) VerifyRespParam

func (t *Template) VerifyRespParam(dr DeviceResp, id string, tt TEMP_TYPE) (map[string]TempParam, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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