黄学彪
2020-11-19 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCommonLogic.cs
@@ -67,6 +67,8 @@
        {
            var reResult = new ReceiptGatewayResult();
            reResult.listReceiptData = new string[listReceiptTopic.Count];
            reResult.JsonData = new string[listReceiptTopic.Count];
            var myGateway = device.Gateway;
            if (myGateway == null)
            {
@@ -76,7 +78,7 @@
                return reResult;
            }
            //网关ID
            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
            string gatewayID = device.Gateway.GwId;
            //错误主题
            string errorTopic = gatewayID + "/" + "Error_Respon";
            //检测对象的主题
@@ -85,8 +87,8 @@
                listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
            }
            //接收数
            int receiptCount = 0;
            //蓝才刚整了个同一个主题可能会推送多个过来的机能
            var listCheckTopic = new HashSet<string>();
            Action<string, string> receiptAction = (topic, message) =>
            {
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
@@ -102,6 +104,11 @@
                {
                    if (topic == listReceiptTopic[i])
                    {
                        if (listCheckTopic.Contains(topic) == true)
                        {
                            //这里写这个东西是有点用处的
                            continue;
                        }
                        string deviceMac = jobject["DeviceAddr"].ToString();
                        int deviceEpoint = 200;
                        if (jobject.Property("Epoint") != null)
@@ -120,7 +127,17 @@
                            return;
                        }
                        reResult.listReceiptData[i] = jobject["Data"].ToString();
                        receiptCount++;
                        if (jobject.Property("Time") != null)
                        {
                            //需要移除time这个字段
                            jobject.Remove("Time");
                        }
                        reResult.JsonData[i] = jobject.ToString();
                        if (listCheckTopic.Contains(topic) == false)
                        {
                            //加到检测主题对象中
                            listCheckTopic.Add(topic);
                        }
                    }
                }
@@ -132,7 +149,7 @@
            //超时时间
            int TimeOut = 0;
            waitTime = 20 * waitTime;
            while (receiptCount != listReceiptTopic.Count && TimeOut < waitTime)
            while (listCheckTopic.Count != listReceiptTopic.Count && TimeOut < waitTime)
            {
                //全部接收才退出
                System.Threading.Thread.Sleep(50);
@@ -140,7 +157,7 @@
            }
            myGateway.Actions -= receiptAction;
            receiptAction = null;
            if (receiptCount != listReceiptTopic.Count)
            if (listCheckTopic.Count != listReceiptTopic.Count)
            {
                reResult.ErrorMsgDiv = 0;
            }
@@ -151,7 +168,6 @@
                {
                    //如果只有一个主题,则替换变量
                    reResult.ReceiptData = reResult.listReceiptData[0];
                    reResult.listReceiptData = null;
                }
            }
@@ -166,8 +182,10 @@
        /// <param name="receiptCommand">指定接收命令符</param>
        /// <param name="receiptDataLength">指定接收数据的长度</param>
        /// <param name="waitTime">超时时间(秒)</param>
        /// <param name="listReceiptLength">附加检测数据接收长度,当接收的长度在这列表里面时,代表接收成功(旨在对应新旧设备,透传回复的长度可能不同)</param>
        /// <returns>网关返回的数据</returns>
        public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength, int waitTime = 5)
        public ReceiptGatewayResult SendJobjectDataToGateway2(CommonDevice device, string sendData, string receiptCommand, int receiptDataLength,
            int waitTime = 5, List<int> listReceiptLength = null)
        {
            var reResult = new ReceiptGatewayResult();
            var myGateway = device.Gateway;
@@ -179,7 +197,7 @@
                return reResult;
            }
            //网关ID
            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
            string gatewayID = device.Gateway.GwId;
            //错误主题
            string errorTopic = gatewayID + "/" + "Error_Respon";
            //检测对象的主题
@@ -217,18 +235,36 @@
                    }
                    var responseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                    //长度一致
                    if (responseData.PassData.Length == receiptDataLength)
                    //长度不一致
                    if (responseData.PassData.Length != receiptDataLength)
                    {
                        var command = responseData.PassData[4].ToString()
                        + responseData.PassData[5].ToString()
                        + responseData.PassData[2].ToString()
                        + responseData.PassData[3].ToString();
                        //并且是这个命令
                        if (command == receiptCommand)
                        if (listReceiptLength == null)
                        {
                            reResult.ReceiptData = responseData.PassData;
                            //如果没有附加检测长度,则直接返回
                            return;
                        }
                        if (listReceiptLength.Contains(responseData.PassData.Length) == false)
                        {
                            //如果附加的检测长度里面,还不存在的话,直接返回
                            return;
                        }
                    }
                    var command = responseData.PassData[4].ToString()
                        + responseData.PassData[5].ToString()
                        + responseData.PassData[2].ToString()
                        + responseData.PassData[3].ToString();
                    //并且是这个命令
                    if (command == receiptCommand)
                    {
                        reResult.ReceiptData = responseData.PassData;
                        reResult.JsonData = new string[1];
                        if (jobject.Property("Time") != null)
                        {
                            //需要移除time这个字段
                            jobject.Remove("Time");
                        }
                        reResult.JsonData[0] = jobject.ToString();
                    }
                }
            };