123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package klink
- import "github.com/gogf/gf/encoding/gjson"
- type PacketAction string
- const (
- DevSendAction PacketAction = "devSend" // 设备上报数据
- BatchDevSendAction PacketAction = "batchDevSend" // 网关批量上报设备数据
- CloudSendAction PacketAction = "cloudSend" // 云端给设备下发指令
- ReportFirmwareAction PacketAction = "reportFirmware" // 设备上报固件信息
- DevLoginAction PacketAction = "devLogin" // 子设备上线
- DevLogoutAction PacketAction = "devLogout" // 子设备下线
- DevNetConfigAction PacketAction = "devNetConfig" // 设备配网信息
- DevUpgradeAction PacketAction = "devUpgrade" // 设备升级
- )
- // DevLogin 子设备上线
- type DevLogin struct {
- Action string `json:"action"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- Pk string `json:"pk"`
- SubDeviceId string `json:"subDeviceId"`
- Timestamp int64 `json:"timestamp"`
- }
- func (d *DevLogin) Marshal() ([]byte, error) {
- return gjson.New(d).ToJson()
- }
- func (d *DevLogin) UnMarshal(bytes []byte) error {
- j, err := gjson.DecodeToJson(bytes)
- if err != nil {
- return err
- }
- return j.Struct(d)
- }
- // DevLogout 子设备下线
- type DevLogout struct {
- Action string `json:"action"`
- Pk string `json:"pk"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- SubDeviceId string `json:"subDeviceId"`
- Timestamp int64 `json:"timestamp"`
- }
- func (d *DevLogout) Marshal() ([]byte, error) {
- return gjson.New(d).ToJson()
- }
- func (d *DevLogout) UnMarshal(bytes []byte) error {
- j, err := gjson.DecodeToJson(bytes)
- if err != nil {
- return err
- }
- return j.Struct(d)
- }
- // DevSend 设备上报数据帧
- type DevSend struct {
- Action string `json:"action"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- SubDeviceId string `json:"subDeviceId"`
- Data *DevSendData `json:"data"`
- Timestamp int64 `json:"timestamp"`
- Version string `json:"version"`
- }
- func (d *DevSend) Marshal() ([]byte, error) {
- return gjson.New(d).ToJson()
- }
- func (d *DevSend) UnMarshal(bytes []byte) error {
- j, err := gjson.DecodeToJson(bytes)
- if err != nil {
- return err
- }
- return j.Struct(d)
- }
- type DevSendData struct {
- Cmd string `json:"cmd"`
- Params *gjson.Json `json:"params"`
- }
- type CloudSendData struct {
- Cmd string `json:"cmd"`
- Params map[string]interface{} `json:"params"`
- }
- type CloudSend struct {
- Action string `json:"action"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- Timestamp int64 `json:"timestamp"`
- Data *CloudSendData `json:"data"`
- SubDeviceId string `json:"subDeviceId"`
- }
- func (c *CloudSend) Marshal() ([]byte, error) {
- return gjson.New(c).ToJson()
- }
- func (c *CloudSend) UnMarshal(bytes []byte) error {
- j, err := gjson.DecodeToJson(bytes)
- if err != nil {
- return err
- }
- return j.Struct(c)
- }
- // DevUpgrade 设备升级
- type DevUpgrade struct {
- Action string `json:"action"`
- MsgId int `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- SubDeviceId string `json:"subDeviceId"`
- Timestamp int64 `json:"timestamp"`
- Url string `json:"url"`
- Md5 string `json:"md5"`
- Type string `json:"type"`
- Version string `json:"version"`
- }
- func (c *DevUpgrade) Marshal() ([]byte, error) {
- return gjson.New(c).ToJson()
- }
- func (c *DevUpgrade) UnMarshal(bytes []byte) error {
- j, err := gjson.DecodeToJson(bytes)
- if err != nil {
- return err
- }
- return j.Struct(c)
- }
|