deviceMsg

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package device 设备发送来的消息解析

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonMsg

type CommonMsg struct {
	Method    string     `json:"method,omitempty"`    //操作方法
	MsgToken  string     `json:"msgToken,omitempty"`  //方便排查随机数
	Timestamp int64      `json:"timestamp,omitempty"` //毫秒时间戳
	Code      int64      `json:"code,omitempty"`      //状态码
	Msg       string     `json:"msg,omitempty"`       //返回信息
	Data      any        `json:"data,omitempty"`      //返回具体设备上报的最新数据内容
	Sys       *SysConfig `json:"sys,omitempty"`       //系统配置
}

func NewRespCommonMsg

func NewRespCommonMsg(ctx context.Context, method, MsgToken string) *CommonMsg

如果MsgToken为空,会使用uuid生成一个

func (*CommonMsg) AddStatus

func (c *CommonMsg) AddStatus(err error, needRet bool) *CommonMsg

func (*CommonMsg) Bytes

func (c *CommonMsg) Bytes() []byte

func (*CommonMsg) GetTimeStamp

func (c *CommonMsg) GetTimeStamp() time.Time

func (*CommonMsg) NeedRetMsg

func (c *CommonMsg) NeedRetMsg() bool

func (*CommonMsg) NoAsk

func (c *CommonMsg) NoAsk() bool

func (*CommonMsg) String

func (c *CommonMsg) String() string

type Method

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

	PackReport      Method = "packReport"      //表示设备属性上报
	PackReportReply Method = "packReportReply" // 表示云端接收设备上报后的响应报文

	/*
		需要主动请求设备上报的时候需要用以下方式上报 Topic:
		设备属性下行请求 Topic: $thing/up/property/{ProductID}/{DeviceNames}
		设备属性上行响应 Topic: $thing/down/property/{ProductID}/{DeviceNames}
	*/
	GetReport      Method = "getReport"      //表示云端请求设备获取上报消息
	GetReportReply Method = "getReportReply" // 表示设备属性上报

	/*
		使用数据模板协议的设备,当需要通过云端远程控制设备时,设备需订阅下发 Topic 接收云端指令:
		下发 Topic: $thing/down/property/{ProductID}/{DeviceNames}
		响应 Topic: $thing/up/property/{ProductID}/{DeviceNames}
	*/
	Control      Method = "control"      //表示云端向设备发起控制请求
	ControlReply Method = "controlReply" //表示设备向云端下发的控制指令的请求响应(设备回复的 云端下发控制指令 的处理结果)

	/*
		设备从云端接收最新消息使用的 Topic:
		请求 Topic: $thing/up/property/{ProductID}/{DeviceNames}
		响应 Topic: $thing/down/property/{ProductID}/{DeviceNames}
	*/
	GetStatus      Method = "getStatus"      //表示获取设备最新上报的信息(设备请求获取 云端记录的最新设备信息)
	GetStatusReply Method = "getStatusReply" //表示获取设备最新上报信息的 reply 消息

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

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

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

	/*
		拓扑关系管理
		网关类型的设备,可通过与云端的数据通信,对其下的子设备进行绑定与解绑操作。实现此类功能需利用如下两个 Topic:
		数据上行 Topic(用于发布):$gateway/topo/${productid}/${devicename}
		数据下行 Topic(用于订阅):$gateway/topo/${productid}/${devicename}
	*/
	Bind         Method = "bind"         //绑定设备
	Unbind       Method = "unbind"       //解绑设备
	GetTopo      Method = "getTopo"      //查询拓扑关系
	Change       Method = "change"       //拓扑关系变化
	Register     Method = "register"     //注册新设备
	GetFound     Method = "getFound"     //获取发现的子设备(可以用来绑定的设备列表)
	GetSchema    Method = "getSchema"    //获取子设备的物模型列表
	CreateSchema Method = "createSchema" //创建设备物模型,需要打开对应产品的设备模型创建
	DeleteSchema Method = "deleteSchema" //删除设备物模型,需要打开对应产品的设备模型创建
	Found        Method = "found"        //网关上报发现子设备
	NotifyBind   Method = "notifyBind"   //通知网关绑定子设备
	/*
		数据上行 Topic(用于发布):$gateway/status/${productid}/${devicename}
		数据下行 Topic(用于订阅):$gateway/status/${productid}/${devicename}
	*/
	Online  Method = "online"  //代理子设备上线
	Offline Method = "offline" //代理子设备下线

	/*
		数据上行 Topic(用于发布):$config/up/get/${productid}/${devicename}
		数据下行 Topic(用于订阅):$config/down/get/${productid}/${devicename}
	*/
	RemoteConfigReply Method = "reply" //表示设备请求配置

	/*
		ntp时间同步
		设备ntp上行请求 Topic(用于发布):$ext/up/ntp/${productid}/${devicename}
		设备ntp下行响应 Topic(用于订阅):$ext/down/ntp/${productid}/${devicename}
	*/
	GetNtp      Method = "getNtp"      //表示设备ntp请求
	GetNtpReply Method = "getNtpReply" //表示云端ntp返回

	AppBindToken Method = "appBindToken"
)

func GetRespMethod

func GetRespMethod(method Method) Method

type PublishMsg

type PublishMsg struct {
	Topic        string            `json:"topic"`  //只用于日志记录
	Handle       devices.MsgHandle `json:"handle"` //对应 mqtt topic的第一个 thing ota config 等等
	Type         string            `json:"type"`   //操作类型 从topic中提取 物模型下就是   property属性 event事件 action行为
	Payload      []byte            `json:"payload"`
	Timestamp    int64             `json:"timestamp"` //毫秒时间戳
	ProductID    string            `json:"productID"`
	DeviceName   string            `json:"deviceName"`
	Explain      string            `json:"explain"`      //内部使用的拓展字段
	ProtocolCode string            `json:"protocolCode"` //如果有该字段则回复的时候也会带上该字段
}

func GetDevPublish

func GetDevPublish(ctx context.Context, data []byte) (*PublishMsg, error)

func (*PublishMsg) GetPayload

func (p *PublishMsg) GetPayload() string

func (*PublishMsg) String

func (p *PublishMsg) String() string

type ReqType

type ReqType = string
const (
	ReqMsg  ReqType = "req"
	RespMsg ReqType = "resp"
)

type SysConfig

type SysConfig struct {
	NoAsk  bool `json:"noAsk"`  //云平台是否回复消息
	RetMsg bool `json:"retMsg"` //是否返回错误信息
}

type TimeParams

type TimeParams struct {
	Timestamp int64          `json:"timestamp,omitempty"` //毫秒时间戳
	EventID   string         `json:"eventID,omitempty"`   //事件的 Id,在数据模板事件中定义。
	Params    map[string]any `json:"params,omitempty"`    //参数列表
}

type TimeValue

type TimeValue struct {
	Timestamp int64 `json:"timestamp,omitempty"` //毫秒时间戳
	Value     any   `json:"value"`               //值
}

Directories

Path Synopsis
Package repo 本文件是提供设备模型数据存储的信息
Package repo 本文件是提供设备模型数据存储的信息

Jump to

Keyboard shortcuts

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