From 270b3d8539f6b4a991a9ebf3b3a9eceb436d61d5 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 28 十月 2021 17:08:02 +0800
Subject: [PATCH] 自动化地址问题修复

---
 HDL_ON/DAL/DriverLayer/Control.cs |   62 +++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 04eb714..686064e 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -279,6 +279,7 @@
                         else if (DB_ResidenceData.Instance.GatewayType == 1)
                         {
                             new Control_Udp().SearchLocalGateway();
+                            new Control_Udp().SearchLocalGateway(true);
                         }
                         System.Threading.Thread.Sleep(500);
                     }
@@ -407,9 +408,12 @@
             switch (function.spk)
             {
                 case SPK.ElectricTuyaAirCleaner:
+                case SPK.ElectricTuyaAirCleaner2:
                 case SPK.ElectricTuyaFan:
+                case SPK.ElectricTuyaFan2:
                 case SPK.ElectricTuyaWaterValve:
                 case SPK.ElectricTuyaWeepRobot:
+                case SPK.ElectricTuyaWeepRobot2:
                     useRemote = true;
                     break;
             }
@@ -615,9 +619,9 @@
                         {
                             id = Ins.msg_id.ToString(),
                             objects = new List<Dictionary<string, string>>()
-                        {
-                            readKey
-                        },
+                                        {
+                                            readKey
+                                        },
                             time_stamp = Utlis.GetTimestamp()
                         };
                         var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
@@ -699,6 +703,21 @@
             }
         }
         /// <summary>
+        /// 缃戝叧杩涘叆閰嶇綉妯″紡
+        /// </summary>
+        public void AuthGateway()
+        {
+            var objects1 = new { spk = "", time = "180" };
+            //{"objects":[{"spk":"","time":"180"}],"id":"8","time_stamp":"1635241216669"}
+            var sendId = Ins.msg_id.ToString();
+            var sendObj = new { objects = objects1, id = sendId, time_stamp = Utlis.GetTimestamp() };
+
+            var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(sendObj);
+            var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.AuthGateway, aLinkJson);
+            new Control_Udp().SendLocalHdlLinkData(sendBytes, Ins.msg_id.ToString());
+        }
+
+        /// <summary>
         /// 杞崲鍙戦�佹暟鎹�
         /// </summary>
         /// <param name="topic">涓婚</param>
@@ -720,7 +739,7 @@
             //1.鎷兼帴澶�
             string topicString = "Topic:" + topic + "\r\n";
             //2.Body瀛楃涓茶浆涓篵yte鏁扮粍
-            byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString);
+            byte[] bodyBytes = Encoding.UTF8.GetBytes(bodyDataString);
             //鍒ゆ柇鏄惁闇�鍔犲瘑Body鏁版嵁
             if (isEncryption && IsLocalEncryptAndGetAesKey)
             {
@@ -731,7 +750,7 @@
             //3.鎷兼帴body鐨凩ength闀垮害鏁版嵁
             string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
             string topicAndLengthString = topicString + lengthString;
-            byte[] topicAndLengthBytes = Encoding.ASCII.GetBytes(topicAndLengthString);
+            byte[] topicAndLengthBytes = Encoding.UTF8.GetBytes(topicAndLengthString);
             //4.鎷兼帴鍚堝苟 Topic 鍜� body鐨刡yte鏁扮粍鏁版嵁
             byte[] sendDataBytes = new byte[topicAndLengthBytes.Length + bodyBytes.Length];
             topicAndLengthBytes.CopyTo(sendDataBytes, 0);
@@ -747,10 +766,10 @@
         /// 杞崲鎺ユ敹鍒扮殑鏁版嵁
         /// </summary>
         /// <returns></returns>
-        public void ConvertReceiveData(byte[] receiveBytes)
+        public void ConvertReceiveData(byte[] receiveBytes,string ip)
         {
             var reString = Encoding.UTF8.GetString(receiveBytes);
-            AnalysisReceiveData(reString, receiveBytes);
+            AnalysisReceiveData(reString, receiveBytes,ip);
         }
         /// <summary>
         /// 杞崲鎺ユ敹鍒扮殑鏁版嵁
@@ -758,7 +777,7 @@
         /// <param name="receiveString">杞琒tring鍚庣殑鏁版嵁</param>
         /// <param name="originalReceiveBytes"鍘熷Bytes鏁版嵁</param>
         /// <returns></returns>
-        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes)
+        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null)
         {
             LocalCommunicationData receiveObj = new LocalCommunicationData();
 
@@ -851,6 +870,10 @@
                         {
                             Ins.GatewayId = device.device_mac;
                         }
+                        if (!string.IsNullOrEmpty(sIp))
+                        {
+                            device.ip_address = sIp;
+                        }
                         reportIp = device.ip_address;//涓绘挱鍦板潃涔熻兘鎺у埗璁惧//"239.0.168.188";//
                         //2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
                         Ins.IsLocalEncrypt = device.isLocalEncrypt;
@@ -859,7 +882,8 @@
                 }
                 else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
                     receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
-                    receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus)
+                    receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
+                    receiveObj.Topic.Contains( CommunicationTopic.ct.GatewayUpSortTopic))
                 {
                     //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
                     UpdataFunctionStatus(receiveObj.BodyDataString, null);
@@ -961,6 +985,10 @@
                         {
                             case SPK.AirSwitch:
                                 AirSwitchPage.UpdataState(localFunction);
+                                if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//濡傛灉鏄甫鐢甸噺鐨勭┖寮�涔熻鏇存柊鑳芥簮鐣岄潰
+                                {
+                                    EnergyMainPage.UpdataStatus(localFunction);
+                                }
                                 break;
                             case SPK.ElectricEnergy:
                                 EnergyMainPage.UpdataStatus(localFunction);
@@ -974,6 +1002,7 @@
                                 DimmerPage.UpdataStates(localFunction);
                                 break;
                             case SPK.ElectricFan:
+                            case SPK.HvacFan:
                                 localFunction.lastState = Language.StringByID(StringId.Level) + " : " +
                                    localFunction.GetAttrState(FunctionAttributeKey.OpenLevel);
                                 FanPage.UpdataState(localFunction);
@@ -1003,6 +1032,8 @@
                             case SPK.CurtainShades:
                                 break;
                             case SPK.AcStandard:
+                            case SPK.HvacAC:
+                            case SPK.AcIr:
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
                                 if (localFunction != null)
                                 {
@@ -1041,9 +1072,10 @@
                                             break;
                                     }
                                     localFunction.lastState += " " + localFunction.GetAttrState(FunctionAttributeKey.SetTemp) + new AC().GetTempUnitString(localFunction);
-                                    ACPage.UpdataStates(localFunction);
+
                                 }
                                 break;
+                            case SPK.HvacFloorHeat:
                             case SPK.FloorHeatStandard:
                                 localFunction.lastState = "";
                                 switch (localFunction.GetAttrState(FunctionAttributeKey.Mode))
@@ -1072,6 +1104,7 @@
                             case SPK.SensorTVOC:
                             case SPK.SensorTemperature:
                             case SPK.SensorHumidity:
+                            case SPK.SensorHcho:
                                 if(localFunction.spk == SPK.SensorTemperature)
                                 {
                                     HomePage.LoadEvent_RefreshEnvirIndoorTemp();
@@ -1098,22 +1131,29 @@
                                 //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction);
                                 break;
                             case SPK.ElectricSocket:
+                            case SPK.PanelSocket:
                                 SocketPage.UpdataState(localFunction);
                                 break;
                             case SPK.ElectricTV:
                                 break;
                             case SPK.ElectricTuyaAirCleaner:
+                            case SPK.ElectricTuyaAirCleaner2:
                             case SPK.ElectricTuyaFan:
+                            case SPK.ElectricTuyaFan2:
                             case SPK.ElectricTuyaWeepRobot:
+                            case SPK.ElectricTuyaWeepRobot2:
                             case SPK.ElectricTuyaWaterValve:
+                            case SPK.ElectricTuyaWaterValve2:
                             case SPK.SensorPir:
                             case SPK.SensorDoorWindow:
                             case SPK.SensorSmoke:
                             case SPK.SensorWater:
                             case SPK.ClothesHanger:
-                            case SPK.AcIr:
                             case SPK.SenesorMegahealth:
+                            case SPK.SenesorMegahealth2:
                             case SPK.AirFreshStandard:
+                            case SPK.HvacAirFresh:
+                            case SPK.SensorGas:
                                 //璁惧鐘舵�佹帹閫�
                                 //鐘舵�佹洿鏂�
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);

--
Gitblit v1.8.0