From 6d73bf6e816570291865674bef8bce8972e4de3f Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期三, 01 十二月 2021 16:32:57 +0800
Subject: [PATCH] 2021-12-01-01

---
 HDL_ON/DAL/DriverLayer/Control.cs |  418 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 364 insertions(+), 54 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 559605c..be5293d 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -26,7 +26,6 @@
     public class Control
     {
        
-
         static Control _control;
         public static Control Ins
         {
@@ -39,6 +38,11 @@
                 return _control;
             }
         }
+        /// <summary>
+        /// 璁板綍鎺ユ敹鍒扮殑娑堟伅锛屾柟渚縵b鐨勫伐绋嬪笀璋冭瘯浠栦滑鐨勮澶�
+        /// </summary>
+        public List<string> MsgInfoList = new List<string>();
+
         int _msg_id = 1;
         /// <summary>
         /// 閫氳ID
@@ -64,7 +68,19 @@
         /// 鏄惁鎼滅储鏈湴缃戝叧鎴愬姛
         /// </summary>
         public bool IsSearchLocalGatewaySuccessful = false;
-      
+        /// <summary>
+        /// 鏄惁鏈湴鍔犲瘑锛岀洰鍓嶅彧瀵笰缃戝叧鏈夌敤
+        /// </summary>
+        public bool IsLocalEncrypt;
+        /// <summary>
+        /// 鍒ゆ柇鏄惁鏈湴鍔犲瘑骞朵笖鍔犲瘑key涓嶄负绌�
+        /// </summary>
+        public bool IsLocalEncryptAndGetAesKey {
+            get {
+                return IsLocalEncrypt && (!string.IsNullOrEmpty(DB_ResidenceData.Instance.CurrentRegion.localSecret));
+            }
+        }
+
         bool _GatewayOnline_Local = false;
         /// <summary>
         /// 缃戝叧鍦ㄧ嚎-灞�鍩熺綉
@@ -268,6 +284,7 @@
                         else if (DB_ResidenceData.Instance.GatewayType == 1)
                         {
                             new Control_Udp().SearchLocalGateway();
+                            new Control_Udp().SearchLocalGateway(true);
                         }
                         System.Threading.Thread.Sleep(500);
                     }
@@ -283,6 +300,30 @@
         /// </summary>
         public void ControlScene(Scene scene)
         {
+            //浣撻獙妯″紡
+            if(MainPage.NoLoginMode)
+            {
+                foreach(var sceneFunction in scene.functions)
+                {
+                    var revString = "";
+                    var upDataObj = new AlinkFunctionStatusObj();
+                    upDataObj.id = "999";
+                    upDataObj.objects = new List<AlinkStatusData>();
+                    var asd = new AlinkStatusData() { deviceId = sceneFunction.localFunction.deviceId, sid = sceneFunction.sid };
+                    var status1 = new List<AttributesStatus>();
+                    foreach (var dic in sceneFunction.status)
+                    {
+                        status1.Add(new AttributesStatus() { key = dic.key, value = dic.value });
+                    }
+                    asd.status = status1;
+                    upDataObj.objects.Add(asd);
+                    revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
+                    UpdataFunctionStatus(revString, null, true);
+                }
+                return;
+            }
+
+            //杩滅▼鎴栬�呮帶鍒秎ink缃戝叧鍦烘櫙
             if (!Ins.GatewayOnline_Local || DB_ResidenceData.Instance.GatewayType == 1)
             {
                 new System.Threading.Thread(() =>
@@ -299,6 +340,15 @@
                 }
             }
         }
+        /// <summary>
+        /// 瀹夐槻鎺у埗
+        /// </summary>
+        public void ControlArm()
+        {
+            DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
+            //var pack = httpServer.GetSecurityAlarmLogList
+        }
+
 
         /// <summary>
         /// 鍙戦�佸懡浠�
@@ -309,7 +359,7 @@
         /// <param name="function"></param>
         /// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param>
         /// <returns></returns>
-        public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false)
+        public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
         {
             function.controlCounter++;
             function.refreshTime = DateTime.Now;
@@ -336,15 +386,39 @@
                 }
             }
 
+            ///dome鎺у埗
+            if (MainPage.NoLoginMode)
+            {
+                var revString = "";
+                var upDataObj = new AlinkFunctionStatusObj();
+                upDataObj.id = "999";
+                upDataObj.objects = new List<AlinkStatusData>();
+                var asd = new AlinkStatusData() { deviceId = function.deviceId, sid = function.sid };
+                var status1 = new List<AttributesStatus>();
+                foreach (var dic in commandDictionary)
+                {
+                    status1.Add(new AttributesStatus() { key = dic.Key, value = dic.Value });
+                }
+                asd.status = status1;
+                upDataObj.objects.Add(asd);
+                revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
+                UpdataFunctionStatus(revString, null, true);
+                return;
+            }
+
+
             //MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}");
 
             ///绗笁鏂规秱楦﹁澶囩粺涓�浣跨敤杩滅▼鎺у埗
-            switch(function.spk)
+            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;
             }
@@ -361,16 +435,6 @@
             }
             else
             {
-                ////杩滅▼閫氳
-                //if (Ins.GatewayOnline_Local == false && Ins.GatewayOnline_Cloud == true)
-                //{
-                //    DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
-                //    //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋�
-                //    var apiControlData = function.GetApiControlData(commandDictionary);
-                //    var actionObjs = new List<ApiAlinkControlActionObj>();
-                //    actionObjs.Add(apiControlData);
-                //    var pack = httpServer.ControlDevice(actionObjs);
-                //}
                 //鏈湴閫氳
                 if (Ins.GatewayOnline_Local)
                 {
@@ -392,19 +456,39 @@
                         var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary);
                         var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
                         var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
-                        new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id);
+                        new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend);
                         MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
                     }
                 }
                 //杩滅▼閫氳
                 else
                 {
+                    //Bug淇锛氫竴绔彛杩滅▼鎺у埗璋冨厜璁惧鐨勮皟鍏夊睘鎬ф椂锛屾棤娉曟帶鍒跺埌0锛屽弽澶嶆í璺炽��
+                    //鍥犱负On + 杩滅▼鎺у埗鍙戦�佺粰浜戠浣跨敤鐨勬槸link鍗忚鏁版嵁锛屾潹娑涗腑杞粰楂樿儨澶勭悊鏃跺�欓�昏緫涓婃湁鍐茬獊锛屽鑷存棤娉曞崟鐙帶鍒朵寒搴﹀�硷紝闇�瑕佸悓鏃跺彂閫佸紑鍏冲�间笌浜害鍊笺��
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        if (commandDictionary.Count == 1)
+                        {
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on");
+                            }
+                        }
+                        if(function.spk == SPK.LightCCT)
+                        {
+                            if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.CCT, function.GetAttrState(FunctionAttributeKey.CCT));
+                            }
+                        }
+                    }
                     DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
                     //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋�
                     var apiControlData = function.GetApiControlData(commandDictionary);
                     var actionObjs = new List<ApiAlinkControlActionObj>();
                     actionObjs.Add(apiControlData);
                     var pack = httpServer.ControlDevice(actionObjs);
+                    MainPage.Log($"杩滅▼鎺у埗鍙嶉:{pack.message}");
                 }
 
             }
@@ -414,29 +498,59 @@
         /// </summary>
         public void SwtichFunctions(bool open,List<Function> functions)
         {
+            //dome妯″紡鎺у埗
+            if(MainPage.NoLoginMode)
+            {
+                new System.Threading.Thread(() =>
+                {
+                    foreach (var temp in functions)
+                    {
+                        Dictionary<string, string> d1 = new Dictionary<string, string>();
+                        d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
+                        SendWriteCommand(temp, d1);
+                        System.Threading.Thread.Sleep(100);
+                    }
+                })
+                { IsBackground = true }.Start();
+                return;
+            }
+
             var count = 0;
-            var logString = open ? "鎵撳紑\r\n" : "鍏抽棴\r\n";
             List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>();
             Dictionary<string, string> d = new Dictionary<string, string>();
             d.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
             var pm = new DAL.Server.HttpServerRequest();
-            foreach (var temp in functions)
+            //涓�绔彛鍏ㄥ紑鍏ㄥ叧闇�瑕佸欢鏃跺彂閫�
+            if (DB_ResidenceData.Instance.GatewayType == 0)
             {
-                logString += temp.spk + ":" + temp.sid + "\r\n";
-                var apiControlData = temp.GetApiControlData(d);
-                actionObjs.Add(apiControlData);
-                count++;
-                if (count > 9)
+                new System.Threading.Thread(() =>
                 {
-                    var result = pm.ControlDevice(actionObjs);
-                    actionObjs = new List<ApiAlinkControlActionObj>();
-                    count = 0;
-                    MainPage.Log(logString);
-                    logString = "";
-                }
+                    foreach (var temp in functions)
+                    {
+                        var apiControlData = temp.GetApiControlData(d);
+                        var result = pm.ControlDevice(new List<ApiAlinkControlActionObj>() { apiControlData });
+                        System.Threading.Thread.Sleep(100);
+                    }
+                })
+                { IsBackground = true }.Start();
             }
-            var pack = pm.ControlDevice(actionObjs);
-            MainPage.Log(logString);
+            else
+            {
+                foreach (var temp in functions)
+                {
+                    var apiControlData = temp.GetApiControlData(d);
+                    actionObjs.Add(apiControlData);
+                    count++;
+                    if (count > 9)
+                    {
+                        var result = pm.ControlDevice(actionObjs);
+                        actionObjs = new List<ApiAlinkControlActionObj>();
+                        count = 0;
+                        System.Threading.Thread.Sleep(100);
+                    }
+                }
+                var pack = pm.ControlDevice(actionObjs);
+            }
         }
 
         public void SendApiReadCommand(List<string> functionIds)
@@ -510,9 +624,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);
@@ -526,6 +640,41 @@
                     var pm = new DAL.Server.HttpServerRequest();
                     var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
                 }
+            }
+        }
+
+        /// <summary>
+        /// 瀹夐槻鎺у埗
+        /// </summary>
+        public void ControlSecurity(SecurityAlarm securityAlarm,string state)
+        {
+            if (!Ins.GatewayOnline_Local)//缃戝叧鏈湴涓嶅湪绾�
+            {
+                var pm = new DAL.Server.HttpServerRequest();
+                var result = pm.SetSecurityStatus(new List<SecurityState>() { new SecurityState() {
+                 gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId,
+                  sid = securityAlarm.sid, status = state, userSecurityId = securityAlarm.userSecurityId
+                } });
+                MainPage.Log($"瀹夐槻鎺у埗缁撴灉:{result.Code}");
+            }
+            else
+            {
+                Dictionary<string, string> keys = new Dictionary<string, string>();
+                keys.Add("sid", securityAlarm.sid);
+                keys.Add("status", state);
+                keys.Add("alarm", securityAlarm.alarm.ToString());
+                var aLinkData = new AlinkReadFunctionStatusObj()
+                {
+                    id = Ins.msg_id.ToString(),
+                    objects = new List<Dictionary<string, string>>()
+                        {
+                            keys
+                        },
+                    time_stamp = Utlis.GetTimestamp()
+                };
+                var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
+                var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlSeurity, aLinkJson);
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id);
             }
         }
 
@@ -555,21 +704,66 @@
                 };
                 var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
                 var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson);
-                new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id);
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id,0);
             }
         }
         /// <summary>
-        /// 杞崲閫氳鏁版嵁
+        /// 缃戝叧杩涘叆閰嶇綉妯″紡
         /// </summary>
-        public byte[] ConvertSendBodyData(string topic, string bodyDataString)
+        public void AuthGateway()
         {
-            string topicString = "Topic:" + topic + "\r\n";
-            byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString);
-            string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
+            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() };
 
-            string sendDataString = topicString + lengthString + bodyDataString;
-            byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString);
-            MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
+            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>
+        /// <param name="bodyDataString">body鍐呭鏁版嵁</param>
+        /// <param name="isEncryption">鏄惁瑕佸body鍔犲瘑</param>
+        /// <returns></returns>
+        public byte[] ConvertSendBodyData(string topic, string bodyDataString, bool isEncryption = true)
+        {
+            //string topicString = "Topic:" + topic + "\r\n";
+            //byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString);
+            //string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
+
+            //string sendDataString = topicString + lengthString + bodyDataString;
+            //byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString);
+            //MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
+
+            //***************************************************************
+            //2021-09-23 澧炲姞鏈湴閫氫俊鍔犲瘑澶勭悊
+            //1.鎷兼帴澶�
+            string topicString = "Topic:" + topic + "\r\n";
+            //2.Body瀛楃涓茶浆涓篵yte鏁扮粍
+            byte[] bodyBytes = Encoding.UTF8.GetBytes(bodyDataString);
+            //鍒ゆ柇鏄惁闇�鍔犲瘑Body鏁版嵁
+            if (isEncryption && IsLocalEncryptAndGetAesKey)
+            {
+                bodyBytes = Securitys.EncryptionService.AesEncryptPayload(bodyBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret);
+                //bodyDataString = Encoding.UTF8.GetString(bodyBytes);
+                //MainPage.Log($"杞崲HDL-Link鏁版嵁 鍔犲瘑key锛�" + DB_ResidenceData.Instance.CurrentRegion.localSecret);
+            }
+            //3.鎷兼帴body鐨凩ength闀垮害鏁版嵁
+            string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
+            string topicAndLengthString = topicString + lengthString;
+            byte[] topicAndLengthBytes = Encoding.UTF8.GetBytes(topicAndLengthString);
+            //4.鎷兼帴鍚堝苟 Topic 鍜� body鐨刡yte鏁扮粍鏁版嵁
+            byte[] sendDataBytes = new byte[topicAndLengthBytes.Length + bodyBytes.Length];
+            topicAndLengthBytes.CopyTo(sendDataBytes, 0);
+            bodyBytes.CopyTo(sendDataBytes, topicAndLengthBytes.Length);
+
+            //var sendDataString = Encoding.UTF8.GetString(sendDataBytes);
+            //MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
+            //***************************************************************
 
             return sendDataBytes;
         }
@@ -577,18 +771,22 @@
         /// 杞崲鎺ユ敹鍒扮殑鏁版嵁
         /// </summary>
         /// <returns></returns>
-        public void ConvertReceiveData(byte[] receiveBytes)
+        public void ConvertReceiveData(byte[] receiveBytes,string ip)
         {
             var reString = Encoding.UTF8.GetString(receiveBytes);
-            AnalysisReceiveData(reString);
+            AnalysisReceiveData(reString, receiveBytes,ip);
         }
         /// <summary>
         /// 杞崲鎺ユ敹鍒扮殑鏁版嵁
         /// </summary>
+        /// <param name="receiveString">杞琒tring鍚庣殑鏁版嵁</param>
+        /// <param name="originalReceiveBytes"鍘熷Bytes鏁版嵁</param>
         /// <returns></returns>
-        public LocalCommunicationData AnalysisReceiveData(string receiveString)
+        public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null)
         {
             LocalCommunicationData receiveObj = new LocalCommunicationData();
+
+            MainPage.Log($"灞�鍩熺綉淇℃伅: \r\n{receiveString}");
 
             var res = receiveString.Split("\r\n\r\n");
 
@@ -610,8 +808,7 @@
                     }
                 }
 
-                MainPage.Log($"灞�鍩熺綉淇℃伅: {receiveObj.Topic}  : 鍐呭: {res[1]}");
-
+                //MainPage.Log($"灞�鍩熺綉淇℃伅: {receiveObj.Topic}  : 鍐呭: {res[1]}");
 
                 //楠岃瘉鏈夋晥鏁版嵁闀垮害
                 //if (res[1].Length != receiveObj.Length)
@@ -621,8 +818,47 @@
                 //}
                 receiveObj.BodyDataString = res[1];
 
-                if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply)
+                //2021-09-23 杩囨护涓嶉渶瑕佽В瀵嗙殑涓婚 鐩墠鎼滅储缃戝叧涓婚涓嶅姞瀵�
+                if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply)
                 {
+                    //鍒ゆ柇褰撳墠缃戝叧鏄惁寮�鍚簡鏈湴鍔犲瘑
+                    if (IsLocalEncryptAndGetAesKey)
+                    {
+                        MainPage.Log($"灞�鍩熺綉淇℃伅 寮�濮嬭В瀵�");
+                        if (originalReceiveBytes != null)
+                        {
+                            //鎷垮埌鍘熷Bytes鏁版嵁鍘昏В瀵�
+                            byte[] topicBytes = Encoding.UTF8.GetBytes(res[0]);
+                            byte[] bodyBytes = new byte[receiveObj.Length];
+                            Array.Copy(originalReceiveBytes, topicBytes.Length + 4, bodyBytes, 0, receiveObj.Length);
+                            byte[] receiveBytes = Securitys.EncryptionService.AesDecryptPayload(bodyBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret);
+                            var revString = Encoding.UTF8.GetString(receiveBytes);
+                            receiveObj.BodyDataString = revString;
+                            MainPage.Log($"灞�鍩熺綉淇℃伅: 瑙e瘑鍚庯細" + receiveObj.BodyDataString);
+                            if(receiveObj.Topic.EndsWith("/thing/property/up"))
+                            {
+                                MsgInfoList.Add(revString + "\r\n");
+                            }
+                        }
+                        else
+                        {
+                            //鐩墠涓嶆嬁鍘熷Bytes鏁版嵁 瑙e瘑涓嶄簡
+                            //byte[] receiveBytes = Encoding.UTF8.GetBytes(res[1]);
+                            //MainPage.Log($"灞�鍩熺綉淇℃伅 receiveBytes {receiveBytes.Length}");
+                            //receiveBytes = Securitys.EncryptionService.AesDecryptPayload(receiveBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret);
+                            //MainPage.Log($"灞�鍩熺綉淇℃伅 瑙e瘑鍚庯細receiveBytes {receiveBytes.Length}");
+                            //var revString = Encoding.UTF8.GetString(receiveBytes);
+                            //receiveObj.BodyDataString = revString;
+                            //MainPage.Log($"灞�鍩熺綉淇℃伅: 瑙e瘑鍚庯細" + receiveObj.BodyDataString);
+                        }
+
+                    }
+                }
+
+
+                if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
+                {
+                   
                     var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
                     if (bodyJObj == null)
                     {
@@ -643,15 +879,54 @@
                         {
                             Ins.GatewayId = device.device_mac;
                         }
-                        reportIp = "239.0.168.188";// device.ip_address;//涓绘挱鍦板潃涔熻兘鎺у埗璁惧
+                        if (!string.IsNullOrEmpty(sIp))
+                        {
+                            device.ip_address = sIp;
+                        }
+                        reportIp = device.ip_address;//涓绘挱鍦板潃涔熻兘鎺у埗璁惧//"239.0.168.188";//
+                        //2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
+                        Ins.IsLocalEncrypt = device.isLocalEncrypt;
+                        //MainPage.Log("缃戝叧鏈湴鍔犲瘑鐘舵�侊細" + device.local_encrypt.ToString());
                     }
                 }
                 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);
+                }
+                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply"
+                    || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply"
+                    || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp)
+                {
+                    try
+                    {
+                        MainPage.Log($"灞�鍩熺綉瀹夐槻淇℃伅: {receiveObj.Topic}  : 鍐呭: {res[1]}");
+                        var tt = "";
+                        lock (tt) {
+                            var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString);
+                            if (temp != null)
+                            {
+                                Control_Udp.ReceiveRepeatManager(temp.id, null);
+                                foreach (var updataSecurity in temp.objects)
+                                {
+                                    var updataLocalSecurity = FunctionList.List.securities.Find((obj) => obj.sid == updataSecurity.sid);
+                                    if (updataLocalSecurity != null)
+                                    {
+                                        updataLocalSecurity.status = updataSecurity.status;
+                                        updataLocalSecurity.alarm = updataSecurity.alarm;
+                                        ArmCenterPage.LoadEvent_RefreshSecurityStatus(updataLocalSecurity);
+                                    }
+                                }
+                                HomePage.LoadEvent_RefreshSecurityStatus();
+                            }
+                        }
+                    }
+                    catch (Exception ex){
+                        MainPage.Log($"瀹夐槻灞�鍩熺綉寮傚父锛歿ex.Message}");
+                    }
                 }
                 else
                 {
@@ -707,7 +982,7 @@
                                 return;
                             }
                         }
-                        MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
+                        //MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
@@ -715,9 +990,15 @@
                         }
 
                         //鏇存柊鐣岄潰鐘舵��
-                        Function localObj = null;
                         switch (localFunction.spk)
                         {
+                            case SPK.AirSwitch:
+                                AirSwitchPage.UpdataState(localFunction);
+                                if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//濡傛灉鏄甫鐢甸噺鐨勭┖寮�涔熻鏇存柊鑳芥簮鐣岄潰
+                                {
+                                    EnergyMainPage.UpdataStatus(localFunction);
+                                }
+                                break;
                             case SPK.ElectricEnergy:
                                 EnergyMainPage.UpdataStatus(localFunction);
                                 break;
@@ -730,6 +1011,7 @@
                                 DimmerPage.UpdataStates(localFunction);
                                 break;
                             case SPK.ElectricFan:
+                            case SPK.HvacFan:
                                 localFunction.lastState = Language.StringByID(StringId.Level) + " : " +
                                    localFunction.GetAttrState(FunctionAttributeKey.OpenLevel);
                                 FanPage.UpdataState(localFunction);
@@ -759,6 +1041,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)
                                 {
@@ -797,10 +1081,12 @@
                                             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))
                                 {
                                     case "normal":
@@ -827,6 +1113,7 @@
                             case SPK.SensorTVOC:
                             case SPK.SensorTemperature:
                             case SPK.SensorHumidity:
+                            case SPK.SensorHcho:
                                 if(localFunction.spk == SPK.SensorTemperature)
                                 {
                                     HomePage.LoadEvent_RefreshEnvirIndoorTemp();
@@ -836,23 +1123,46 @@
                                     HomePage.LoadEvent_RefreshEnvirIndoorHumi();
                                 }
                                 EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
+                                //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction);
+                                break;
+                            case SPK.SensorEnvironment:
+                            case SPK.SensorEnvironment2:
+                            case SPK.SensorEnvironment3:
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorTemp();
+                                }
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Humidity))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorHumi();
+                                }
+                                EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
+                                //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