12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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" // 子设备下线
- )
- // DevLogin 子设备上线
- type DevLogin struct {
- Action string `json:"action"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- SubDeviceId string `json:"subDeviceId"`
- Timestamp int64 `json:"timestamp"`
- }
- // DevLogout 子设备下线
- type DevLogout struct {
- Action string `json:"action"`
- MsgId int64 `json:"msgId"`
- DeviceCode string `json:"deviceCode"`
- SubDeviceId string `json:"subDeviceId"`
- Timestamp int64 `json:"timestamp"`
- }
- // 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"`
- }
- 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 *gjson.Json `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)
- }
|