saas-smartAi通信协议标准库
gongshangguo
2022-03-03 d3d05d0eecdd76e86eeb3d28dcd765db042dce17
修改获取消息ID方法
2个文件已修改
10 ■■■■ 已修改文件
client/client.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/clienter.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/client.go
@@ -259,7 +259,7 @@
    c.Logger.Debug("registering...")
    data := c.deviceRegister
    msgData, _ := json.Marshal(data)
    _, err := c.WriteMsg(c.deviceId, aiot.MSG_TYPE_REGISTER, aiot.REQ_TYPE_REQUEST, msgData, c.GetMsgProto(""))
    _, err := c.WriteMsg(c.deviceId, aiot.MSG_TYPE_REGISTER, aiot.REQ_TYPE_REQUEST, msgData, GetMsgProto(""))
    if err != nil {
        c.Logger.Error("Fail to send device register", zap.Any("msg", msgData))
    }
@@ -283,7 +283,7 @@
                t.Stop()
                return
            }
            go c.WriteMsg(c.deviceId, aiot.MSG_TYPE_HEART_BEAT, aiot.REQ_TYPE_REQUEST, pingData, c.GetMsgProto(""))
            go c.WriteMsg(c.deviceId, aiot.MSG_TYPE_HEART_BEAT, aiot.REQ_TYPE_REQUEST, pingData, GetMsgProto(""))
        }
    }
}
@@ -415,7 +415,7 @@
}
// 拼装消息ID
func (c *Client) GetMsgProto(msgId string) *aiot.MsgIdProto {
func GetMsgProto(msgId string) *aiot.MsgIdProto {
    // 新消息
    if msgId == "" {
        return &aiot.MsgIdProto{
server/clienter.go
@@ -28,7 +28,7 @@
    msg.SenderId = Srv.serverId
    msg.Receiver = aiot.RECEIVER_TO_MASTER
    msg.ReqType = aiot.REQ_TYPE_RESPONSE
    msg.MsgProto = cli.GetMsgProto(msg.MsgProto.MsgId)
    msg.MsgProto = client.GetMsgProto(msg.MsgProto.MsgId)
    _ = cli.WriteBody(msg)
    // 上报到服务端
    go Srv.serverCallBack.OnHeartBeat(cli, msg)
@@ -45,7 +45,7 @@
        DeviceProto: msg.DeviceProto,
        MsgType: aiot.MSG_TYPE_REGISTER,
        ReqType: aiot.REQ_TYPE_RESPONSE,
        MsgProto: cli.GetMsgProto(msg.MsgProto.MsgId),
        MsgProto: client.GetMsgProto(msg.MsgProto.MsgId),
        Data: msg.Data,
    }
    _ = cli.WriteBody(msgFeedBack)