From 0e0584b87851c56745bf73b1a961b80613dd0721 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 19 五月 2020 16:35:16 +0800
Subject: [PATCH] 2020-05-19-4

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs |  126 +++++++++++++++++++++++++++++++++--------
 1 files changed, 101 insertions(+), 25 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
old mode 100644
new mode 100755
index 40ab0de..f64c0b6
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -425,24 +425,51 @@
                         //娓╁害
                         if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
                         {
-                            if (attData.AttriButeData == 0)
+                            decimal temperatrue = 0;
+                            string receiptData = string.Empty;
+                            //涓や釜涓や釜浣嶇疆鏇挎崲
+                            for (int i = attData.AttriButeDataHex.Length - 1; i >= 0; i = i - 2)
                             {
-                                ((TemperatureSensor)locadevice).Temperatrue = 0;
+                                receiptData += attData.AttriButeDataHex[i - 1].ToString() + attData.AttriButeDataHex[i].ToString();
                             }
-                            else if (attData.AttriButeData > 32767)
-                            {
-                                //璐熸暟(鐗规畩澶勭悊)
-                                string strValue = (attData.AttriButeData - 65536).ToString();
-                                //灏忔暟鐐归渶瑕佷竴浣�
-                                strValue = strValue.Substring(0, strValue.Length - 1);
-                                ((TemperatureSensor)locadevice).Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
-                            }
-                            else
+                            //鏈夌鍙�(浼氬嚭鐜拌礋鏁�)
+                            if (attData.AttriButeDataType == 40 || attData.AttriButeDataType == 41)
                             {
                                 //灏忔暟鐐归渶瑕佷竴浣�
-                                string strValue = attData.AttriButeData.ToString();
+                                string strValue = Convert.ToInt16(receiptData, 16).ToString();
                                 strValue = strValue.Substring(0, strValue.Length - 1);
-                                ((TemperatureSensor)locadevice).Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                                temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                            }
+                            //鏃犵鍙�(涓嶄細鍑虹幇璐熸暟)
+                            else if (attData.AttriButeDataType == 32 || attData.AttriButeDataType == 33)
+                            {
+                                ushort shortData = Convert.ToUInt16(receiptData, 16);
+                                if (shortData > 32767)
+                                {
+                                    //璐熸暟(鐗规畩澶勭悊)
+                                    string strValue = (shortData - 65536).ToString();
+                                    //灏忔暟鐐归渶瑕佷竴浣�
+                                    strValue = strValue.Substring(0, strValue.Length - 1);
+                                    temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                                }
+                                else
+                                {
+                                    //灏忔暟鐐归渶瑕佷竴浣�
+                                    string strValue = shortData.ToString();
+                                    strValue = strValue.Substring(0, strValue.Length - 1);
+                                    temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                                }
+                            }
+
+                            //娓╁害浼犳劅鍣�
+                            if (locadevice is TemperatureSensor)
+                            {
+                                ((TemperatureSensor)locadevice).Temperatrue = temperatrue;
+                            }
+                            //PM2.5浼犳劅鍣�
+                            else if (locadevice is PMSensor)
+                            {
+                                ((PMSensor)locadevice).currentTemperature = (int)temperatrue;
                             }
                             //宸茬粡鎺ユ敹鍒扮姸鎬�
                             locadevice.HadReadDeviceStatu = true;
@@ -460,22 +487,66 @@
                         //婀垮害
                         if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
                         {
-                            if (attData.AttriButeData == 0)
+                            decimal humidity = 0;
+                            string receiptData = string.Empty;
+                            //涓や釜涓や釜浣嶇疆鏇挎崲
+                            for (int i = attData.AttriButeDataHex.Length - 1; i >= 0; i = i - 2)
                             {
-                                ((TemperatureSensor)locadevice).Humidity = 0;
+                                receiptData += attData.AttriButeDataHex[i - 1].ToString() + attData.AttriButeDataHex[i].ToString();
                             }
-                            else
+                            //鏈夌鍙�(浼氬嚭鐜拌礋鏁�)
+                            if (attData.AttriButeDataType == 40 || attData.AttriButeDataType == 41)
                             {
-                                //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟)
-                                string strValue = attData.AttriButeData.ToString();
+                                //灏忔暟鐐归渶瑕佷竴浣�
+                                string strValue = Convert.ToInt16(receiptData, 16).ToString();
                                 strValue = strValue.Substring(0, strValue.Length - 1);
-                                ((TemperatureSensor)locadevice).Humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                                humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                            }
+                            //鏃犵鍙�(涓嶄細鍑虹幇璐熸暟)
+                            else if (attData.AttriButeDataType == 32 || attData.AttriButeDataType == 33)
+                            {
+                                //灏忔暟鐐归渶瑕佷竴浣� 婀垮害涓嶄細鍑虹幇璐熸暟
+                                string strValue = Convert.ToUInt16(receiptData, 16).ToString();
+                                strValue = strValue.Substring(0, strValue.Length - 1);
+                                humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+                            }
+                            //娓╁害浼犳劅鍣�
+                            if (locadevice is TemperatureSensor)
+                            {
+                                ((TemperatureSensor)locadevice).Humidity = humidity;
+                            }
+                            //PM2.5浼犳劅鍣�
+                            else if (locadevice is PMSensor)
+                            {
+                                ((PMSensor)locadevice).currentHumidity = (int)humidity;
                             }
                         }
                         //宸茬粡鎺ユ敹鍒扮姸鎬�
                         locadevice.HadReadDeviceStatu = true;
                     }
                 }
+                #endregion
+
+                #region 鈻� PM2.5鏁版嵁
+                //PM2.5鏁版嵁
+                else if (report.DeviceStatusReport.CluterID == 1066)
+                {
+                    foreach (var attData in report.DeviceStatusReport.AttriBute)
+                    {
+                        //PM2.5
+                        if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
+                        {
+
+                            if (attData.AttriButeDataType == 57)
+                            {
+                                ((PMSensor)locadevice).currentPmData = attData.AttriButeData;
+                            }
+                        }
+                        //宸茬粡鎺ユ敹鍒扮姸鎬�
+                        locadevice.HadReadDeviceStatu = true;
+                    }
+                }
+
                 #endregion
             }
 
@@ -548,7 +619,7 @@
                         {
                             //娓╁眳鍩庣殑瑕佺綉鍏充腑鏄惁鏈夐�昏緫瀛樺湪 
                             //鍙傛暟:2-甯稿紑鑷姩鍖�;3-澶辨晥鏃堕棿鑷姩鍖�
-                            var result = await Shared.Phone.Device.Logic.SkipView.Exist(2, (ZigBee.Device.DoorLock)device);
+                            var result = await Shared.Phone.Device.Logic.SkipView.Exist(3, (ZigBee.Device.DoorLock)device);
                             HdlThreadLogic.Current.RunMain(() =>
                             {
                                 //寮瑰嚭寰愭鐨勯偅涓獥鍙�
@@ -582,13 +653,18 @@
             tempDevice.IsOnline = Convert.ToInt32(receiveData["Data"]["IsOnline"].ToString());
 
             //澶勭悊缃戝叧涓婃姤鐨勬暟鎹�,鐒跺悗鍙樻洿鏈湴缂撳瓨
-            var locadevice = Common.LocalDevice.Current.GetDevice(tempDevice.DeviceAddr, tempDevice.DeviceEpoint);
-            if (locadevice != null)
+            var locadevice = Common.LocalDevice.Current.GetDevicesByMac(tempDevice.DeviceAddr);
+            for (int i = 0; i < locadevice.Count; i++)
             {
-                locadevice.IsOnline = tempDevice.IsOnline;
+                bool onlineChanged = locadevice[i].IsOnline != tempDevice.IsOnline;
+                locadevice[i].IsOnline = tempDevice.IsOnline;
                 //璁板綍鍥炲鏃堕棿
-                locadevice.LastDateTime = DateTime.Now;
-                locadevice.ReSave();
+                locadevice[i].LastDateTime = DateTime.Now;
+                if (onlineChanged == true)
+                {
+                    //鍦ㄧ嚎鐘舵�佸彉鏇翠簡,鎵嶄繚瀛�
+                    locadevice[i].ReSave();
+                }
             }
 
             this.DeviceReportPush(tempDevice, ReceiveComandDiv.A璁惧鍦ㄧ嚎涓婃姤);

--
Gitblit v1.8.0