From acf384f3d6653f4696446b113177140f491c4e38 Mon Sep 17 00:00:00 2001
From: gongshangguo <gongshangguo@admin.com>
Date: 星期二, 12 四月 2022 09:58:10 +0800
Subject: [PATCH] 更新aiot

---
 client/client.go |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/client/client.go b/client/client.go
index e501367..d833044 100644
--- a/client/client.go
+++ b/client/client.go
@@ -210,7 +210,7 @@
 }
 
 // 鍙戦�佹秷鎭�
-func (c *Client) WriteMsg(senderId string, msgType aiot.MSG_TYPE, reqType aiot.REQ_TYPE, data []byte, msgProto *aiot.MsgIdProto) (*aiot.Protocol, error) {
+func (c *Client) writeMsg(senderId string, msgType aiot.MSG_TYPE, reqType aiot.REQ_TYPE, data []byte, msgProto *aiot.MsgIdProto) (*aiot.Protocol, error) {
 	// 鍏抽棴鐨勮繛鎺ヤ笉鑳藉啓鍏�
 	if c.IsClosed() {
 		c.Logger.Error("Can not write msg on the closed chan", zap.Any("msgType", msgType), zap.Any("reqType", reqType), zap.Any("data", string(data)))
@@ -219,6 +219,7 @@
 
 	// 鎷艰骞跺彂閫佹秷鎭�
 	body := &aiot.Protocol{
+		Receiver: aiot.RECEIVER_TO_SAAS,
 		SenderId: senderId,
 		MsgType: msgType,
 		ReqType: reqType,
@@ -238,18 +239,23 @@
 		}
 	}()
 
+	// 閫氶亾宸插叧闂紝涓嶈兘鍐欏叆
 	if c.IsClosed() {
 		errMsg := "Can not write msg into closed chain"
 		c.Logger.Warn(errMsg, zap.Any("msg",body))
 		return errors.New(errMsg)
 	}
-	body.Receiver = aiot.RECEIVER_TO_SAAS
+
+	// 娑堟伅ID榛樿澶勭悊
+	if body.MsgProto == nil {
+		body.MsgProto = GetMsgProto("")
+	}
 	msgData, err := json.Marshal(body)
 	if err != nil {
 		c.Logger.Error("Fail to Marshal send data", zap.Error(err))
 		return err
 	}
-	c.Logger.Debug("Write Body into writeChan...", zap.Any("msg", body), zap.Any("msg", body), zap.Any("reqType", body.ReqType), zap.Any("msgType", body.MsgType))
+	c.Logger.Debug("Write Body into writeChan...", zap.Any("msg", body), zap.Any("reqType", body.ReqType), zap.Any("msgType", body.MsgType))
 	c.writeChan <- msgData
 	return nil
 }
@@ -259,7 +265,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, 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 +289,7 @@
 				t.Stop()
 				return
 			}
-			go c.WriteMsg(c.deviceId, aiot.MSG_TYPE_HEART_BEAT, aiot.REQ_TYPE_REQUEST, pingData, GetMsgProto(""))
+			go c.writeMsg(c.deviceId, aiot.MSG_TYPE_HEART_BEAT, aiot.REQ_TYPE_REQUEST, pingData, GetMsgProto(""))
 		}
 	}
 }
@@ -302,7 +308,7 @@
 	body.MsgType = aiot.MSG_TYPE_BUSINESS
 	body.ReqType = aiot.REQ_TYPE_REQUEST
 	body.Data = data
-	c.Logger.Debug("Send msg...", zap.Any("msg", body), zap.Any("msg", body), zap.Any("reqType", body.ReqType), zap.Any("msgType", body.MsgType))
+	c.Logger.Debug("Send msg...", zap.Any("msg", body), zap.Any("reqType", body.ReqType), zap.Any("msgType", body.MsgType))
 	msgData, err := json.Marshal(body)
 	if err != nil {
 		c.Logger.Error("Fail to Marshal send data", zap.Error(err))

--
Gitblit v1.8.0