From f759dc1e6f49c53733eafda82207c85af18f9931 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期四, 28 五月 2020 15:46:54 +0800
Subject: [PATCH] 2020-05-28-1

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs |  211 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 163 insertions(+), 48 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
index 79f5634..f64c0b6 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -274,7 +274,7 @@
                 }
                 #endregion
 
-                #region 鈻� 绌鸿皟鏁版嵁
+                #region 鈻� 绌鸿皟鍜屾柊椋庢暟鎹�
                 //绌鸿皟鏁版嵁
                 else if (report.DeviceStatusReport.CluterID == 513)
                 {
@@ -343,29 +343,59 @@
                     locadevice.DeviceStatusReport = report.DeviceStatusReport;
                     foreach (var attData in report.DeviceStatusReport.AttriBute)
                     {
-                        if (attData.AttributeId == 0)
+                        //鍖哄垎鏄┖璋冭繕鏄柊椋�
+                        var device = Shared.Common.LocalDevice.Current.GetDevice(report.DeviceAddr, report.DeviceEpoint);
+
+                        if (device.Type == DeviceType.FreshAir)
                         {
-                            //椋庢墖妯″紡
-                            ((AC)locadevice).currentFanMode = attData.AttriButeData;
-                            //宸茬粡鎺ユ敹鍒扮姸鎬�
-                            locadevice.HadReadDeviceStatu = true;
+                            if (attData.AttributeId == 0)
+                            {
+                                switch (attData.AttriButeData)
+                                {
+                                    case 0:
+                                    case 4:
+                                        ((FreshAir)locadevice).currentFanStatus = attData.AttriButeData;
+                                        break;
+                                    case 1:
+                                    case 2:
+                                    case 3:
+                                        ((FreshAir)locadevice).currentFanSpeed = attData.AttriButeData;
+                                        break;
+                                    case 5:
+                                    case 15:
+                                        ((FreshAir)locadevice).currentFanMode = attData.AttriButeData;
+                                        break;
+                                }
+                                //宸茬粡鎺ユ敹鍒扮姸鎬�
+                                locadevice.HadReadDeviceStatu = true;
+                            }
                         }
-                        else if (attData.AttributeId == 4096)
+                        else
                         {
-                            //椋庢墖鎵
-                            ((AC)locadevice).currentFanSwingMode = attData.AttriButeData;
-                            //宸茬粡鎺ユ敹鍒扮姸鎬�
-                            locadevice.HadReadDeviceStatu = true;
-                        }
-                        else if (attData.AttributeId == 4097)
-                        {
-                            //杞崲涓轰簩杩涘埗
-                            var value = Convert.ToString(attData.AttriButeData, 2).PadLeft(16, '0');
-                            //杩欎釜璁剧疆鏄斁鍦ㄥ悗闈㈢殑
-                            value = value.Substring(value.Length - 1, 1);
-                            //鍚敤鎽嗛鍔熻兘
-                            ((AC)locadevice).UseSwingFunction = value == "1";
-                            locadevice.ReSave();
+                            if (attData.AttributeId == 0)
+                            {
+                                //椋庢墖妯″紡
+                                ((AC)locadevice).currentFanMode = attData.AttriButeData;
+                                //宸茬粡鎺ユ敹鍒扮姸鎬�
+                                locadevice.HadReadDeviceStatu = true;
+                            }
+                            else if (attData.AttributeId == 4096)
+                            {
+                                //椋庢墖鎵
+                                ((AC)locadevice).currentFanSwingMode = attData.AttriButeData;
+                                //宸茬粡鎺ユ敹鍒扮姸鎬�
+                                locadevice.HadReadDeviceStatu = true;
+                            }
+                            else if (attData.AttributeId == 4097)
+                            {
+                                //杞崲涓轰簩杩涘埗
+                                var value = Convert.ToString(attData.AttriButeData, 2).PadLeft(16, '0');
+                                //杩欎釜璁剧疆鏄斁鍦ㄥ悗闈㈢殑
+                                value = value.Substring(value.Length - 1, 1);
+                                //鍚敤鎽嗛鍔熻兘
+                                ((AC)locadevice).UseSwingFunction = value == "1";
+                                locadevice.ReSave();
+                            }
                         }
                     }
                 }
@@ -395,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;
@@ -430,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
             }
 
@@ -477,6 +578,8 @@
             if (locadevice != null)
             {
                 ((IASZone)locadevice).iASInfo = ias.iASInfo;
+                //濡傛灉鎺ユ敹鍒颁笂鎶�,鍗宠鏄庤繖涓紶鎰熷櫒鏄湪绾跨殑
+                locadevice.IsOnline = 1;
                 //璁板綍鍥炲鏃堕棿
                 locadevice.LastDateTime = DateTime.Now;
             }
@@ -512,10 +615,17 @@
                     //甯稿紑妯″紡鍏抽棴
                     if (info.AlarmCode == 217 || info.AlarmCode == 219)
                     {
-                        HdlThreadLogic.Current.RunMain(() =>
+                        HdlThreadLogic.Current.RunThread(async () =>
                         {
-                            //寮瑰嚭寰愭鐨勯偅涓獥鍙�
-                            DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush, null);
+                            //娓╁眳鍩庣殑瑕佺綉鍏充腑鏄惁鏈夐�昏緫瀛樺湪 
+                            //鍙傛暟:2-甯稿紑鑷姩鍖�;3-澶辨晥鏃堕棿鑷姩鍖�
+                            var result = await Shared.Phone.Device.Logic.SkipView.Exist(3, (ZigBee.Device.DoorLock)device);
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                //寮瑰嚭寰愭鐨勯偅涓獥鍙�
+                                DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush,
+                                    result != 0 ? true : false, null);
+                            });
                         });
                     }
                 }
@@ -543,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