From a9d1161b1df96e7ddad566335989a1444e433ef5 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 28 三月 2023 11:54:45 +0800
Subject: [PATCH] 2023年03月28日11:52:02

---
 HDL_ON/DAL/DriverLayer/Control.cs |  547 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 483 insertions(+), 64 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index cc8237a..652bc0d 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -1,31 +1,18 @@
 锘縰sing System;
 using System.Collections.Generic;
 using System.Text;
+using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
 using HDL_ON.UI;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using Shared;
 
 namespace HDL_ON.DriverLayer
 {
-    /// <summary>
-    /// 閫氳鏂瑰紡
-    /// </summary>
-    public enum CommunicationMode
-    {
-        none,
-        /// <summary>
-        /// 鏈湴udp
-        /// </summary>
-        local_BusUdp,
-        /// <summary>
-        /// 鏈湴tcp瀹㈡埛绔�
-        /// </summary>
-        tcp_local_client,
-    }
-
     public class Control
     {
-       
+
         static Control _control;
         public static Control Ins
         {
@@ -42,6 +29,27 @@
         /// 璁板綍鎺ユ敹鍒扮殑娑堟伅锛屾柟渚縵b鐨勫伐绋嬪笀璋冭瘯浠栦滑鐨勮澶�
         /// </summary>
         public List<string> MsgInfoList = new List<string>();
+        private bool _LocalTcpClientLogin = false;
+        /// <summary>
+        /// 鏈湴tcp瀹㈡埛绔繛鎺ユ槸鍚︽垚鍔�
+        /// 鏄惁鐧诲綍缃戝叧鎴愬姛
+        /// </summary>
+        public bool LocalTcpClientLogin
+        {
+            get
+            {
+                return _LocalTcpClientLogin;
+            }
+            set
+            {
+                _LocalTcpClientLogin = value;
+                if (!value)
+                {
+                    loginGatewayThread?.Abort();
+                    loginGatewayThread = null;
+                }
+            }
+        }
 
         int _msg_id = 1;
         /// <summary>
@@ -199,11 +207,6 @@
         public Control_Udp myUdp1 = null;
 
         /// <summary>
-        /// 閫氳鏂瑰紡
-        /// </summary>
-        public CommunicationMode communicationMode;
-
-        /// <summary>
         /// 鎵撳紑tcp鏈嶅姟绔�
         /// </summary>
         public void OpenTcpServer()
@@ -235,8 +238,9 @@
             if (myTcpClient == null)
             {
                 myTcpClient = new Control_TcpClient(reportIp);
-                myTcpClient.Connect();
             }
+            myTcpClient.Connect();
+
         }
 
         /// <summary>
@@ -279,7 +283,8 @@
                         }
                         if (DB_ResidenceData.Instance.GatewayType == 0)
                         {
-                            new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
+                            new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255,
+                                new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
                         }
                         else if (DB_ResidenceData.Instance.GatewayType == 1)
                         {
@@ -294,6 +299,57 @@
                 { IsBackground = true }.Start();
             }
         }
+
+
+        private System.Threading.Thread loginGatewayThread;
+
+        /// <summary>
+        /// 鐧诲綍缃戝叧
+        /// </summary>
+        public void LoginGateway()
+        {
+            if(loginGatewayThread== null)
+            {
+                loginGatewayThread = new System.Threading.Thread(() => {
+                    while (!Ins.myTcpClient.isConnected)
+                    {
+                        if (Ins.GatewayOnline_Local && myTcpClient.isConnected)
+                        {
+                            var sendData = new { clientType = "app", version = "1.0" };
+                            var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData };
+
+                            var bodyString = JsonConvert.SerializeObject(sendJob);
+
+                            var sendBytes = ConvertSendBodyData($"/user/{GatewayId}/custom/gateway/login", bodyString);
+
+                            Ins.myTcpClient.SendMessage(sendBytes);
+                        }
+                        System.Threading.Thread.Sleep(2000);
+                    }
+                    //loginGatewayThread?.Abort();
+                    //loginGatewayThread = null;
+
+                });
+                loginGatewayThread.Start();
+            }
+            else
+            {
+                try
+                {
+                    loginGatewayThread?.Abort();
+                }catch (Exception ex)
+                {
+                    MainPage.Log($"閲嶅惎鐧诲綍缃戝叧绾跨▼寮傚父:{ex.Message}");
+                }
+                finally
+                {
+                    loginGatewayThread = null;
+                    LoginGateway();
+                }
+            }
+            
+        }
+
 
         /// <summary>
         /// 鍦烘櫙鎺у埗鍏ュ彛
@@ -340,15 +396,6 @@
                 }
             }
         }
-        /// <summary>
-        /// 瀹夐槻鎺у埗
-        /// </summary>
-        public void ControlArm()
-        {
-            DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
-            //var pack = httpServer.GetSecurityAlarmLogList
-        }
-
 
         /// <summary>
         /// 鍙戦�佸懡浠�
@@ -359,10 +406,11 @@
         /// <param name="function"></param>
         /// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param>
         /// <returns></returns>
-        public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
+        public bool SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
         {
             function.controlCounter++;
             function.refreshTime = DateTime.Now;
+
 
             //濡傛灉鏄帶鍒惰皟鍏夌殑寮�鏃讹紝浜害鍊间笉鑳戒负0
             if (commandDictionary.Count > 2)
@@ -403,7 +451,7 @@
                 upDataObj.objects.Add(asd);
                 revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
                 UpdataFunctionStatus(revString, null, true);
-                return;
+                return true;
             }
 
 
@@ -492,6 +540,8 @@
                 }
 
             }
+
+            return true;
         }
         /// <summary>
         /// 鍏ㄥ紑鍏ㄥ叧鍔熻兘
@@ -503,11 +553,18 @@
             {
                 new System.Threading.Thread(() =>
                 {
-                    foreach (var temp in functions)
+                    foreach (var function in functions)
                     {
                         Dictionary<string, string> d1 = new Dictionary<string, string>();
                         d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
-                        SendWriteCommand(temp, d1);
+                         if (function.spk == SPK.PanelSocket)
+                        {
+                            if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null)
+                            {
+                                d1.Add("on_off_usb", function.trait_on_off.curValue.ToString());
+                            }
+                        }
+                        SendWriteCommand(function, d1);
                         System.Threading.Thread.Sleep(100);
                     }
                 })
@@ -644,6 +701,79 @@
         }
 
         /// <summary>
+        /// 鍙戦�佽鍙栧懡浠�
+        /// 鑷姩鍒ゆ柇鏄惁涓篈鍗忚璁惧
+        /// </summary>
+        public void SendReadCommand(List<Function> functions, bool forceRemote = false)
+        {
+            List<string> sids = new List<string>();
+            foreach (Function function in functions)
+            {
+                sids.Add(function.sid);
+                function.refreshTime = DateTime.Now;
+            }
+            if (forceRemote)
+            {
+
+                var pm = new DAL.Server.HttpServerRequest();
+                var pack = pm.RefreshDeviceStatus(sids);
+            }
+            else
+            {
+                if (Ins.GatewayOnline_Local)
+                {
+
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        try
+                        {
+                            var busClient = new Control_Udp();
+                            foreach (Function function in functions)
+                            {
+                                busClient.ReadBusData(function);
+                            }
+                            
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}");
+                        }
+                    }
+                    else
+                    {
+                        var objects = new List<Dictionary<string, string>>();
+
+
+                        foreach (Function function in functions)
+                        {
+                            var readKey = new Dictionary<string, string>();
+                            readKey.Add("sid", function.sid);
+                            objects.Add(readKey);
+                        }
+
+
+                        var readDataObj = new AlinkReadFunctionStatusObj()
+                        {
+                            id = Ins.msg_id.ToString(),
+                            objects = objects,
+                            time_stamp = Utlis.GetTimestamp()
+                        };
+                        var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
+                        MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                        new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+                    }
+                }
+                else
+                {
+                    var pm = new DAL.Server.HttpServerRequest();
+                    var pack = pm.RefreshDeviceStatus(sids);
+                }
+            }
+        }
+
+
+        /// <summary>
         /// 瀹夐槻鎺у埗
         /// </summary>
         public void ControlSecurity(SecurityAlarm securityAlarm,string state)
@@ -707,6 +837,33 @@
                 new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id,0);
             }
         }
+
+
+        /// <summary>
+        /// 鑾峰彇闊充箰鐩綍
+        /// </summary>
+        public void GetMusicDirectory(Function function)
+        {
+            if (Ins.GatewayOnline_Local)
+            {
+                var objects = new List<Dictionary<string, string>>();
+                var readKey = new Dictionary<string, string>();
+                readKey.Add("sid", function.sid);
+                objects.Add(readKey);
+                var readDataObj = new AlinkReadFunctionStatusObj()
+                {
+                    id = Ins.msg_id.ToString(),
+                    objects = objects,
+                    time_stamp = Utlis.GetTimestamp()
+                };
+                var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+                var sendBytes = Ins.ConvertSendBodyData($"/base/{DB_ResidenceData.Instance.HomeGateway.gatewayId}/thing/service/MusicPlayGroupListGet/down", functionControlDataJson);
+                MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+            }
+
+        }
+
         /// <summary>
         /// 缃戝叧杩涘叆閰嶇綉妯″紡
         /// </summary>
@@ -761,8 +918,8 @@
             topicAndLengthBytes.CopyTo(sendDataBytes, 0);
             bodyBytes.CopyTo(sendDataBytes, topicAndLengthBytes.Length);
 
-            //var sendDataString = Encoding.UTF8.GetString(sendDataBytes);
-            //MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
+            var sendDataString = Encoding.UTF8.GetString(sendDataBytes);
+            MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n");
             //***************************************************************
 
             return sendDataBytes;
@@ -786,7 +943,6 @@
         {
             LocalCommunicationData receiveObj = new LocalCommunicationData();
 
-            MainPage.Log($"灞�鍩熺綉淇℃伅: \r\n{receiveString}");
 
             var res = receiveString.Split("\r\n\r\n");
 
@@ -818,13 +974,19 @@
                 //}
                 receiveObj.BodyDataString = res[1];
 
+                if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
+                {
+                    Ins.myTcpClient.ClearHeartBeatLog();
+                    MainPage.Log("tcp蹇冭烦鍥炲");
+                    return null;
+                }
+
                 //2021-09-23 杩囨护涓嶉渶瑕佽В瀵嗙殑涓婚 鐩墠鎼滅储缃戝叧涓婚涓嶅姞瀵�
                 if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply)
                 {
                     //鍒ゆ柇褰撳墠缃戝叧鏄惁寮�鍚簡鏈湴鍔犲瘑
                     if (IsLocalEncryptAndGetAesKey)
                     {
-                        MainPage.Log($"灞�鍩熺綉淇℃伅 寮�濮嬭В瀵�");
                         if (originalReceiveBytes != null)
                         {
                             //鎷垮埌鍘熷Bytes鏁版嵁鍘昏В瀵�
@@ -832,13 +994,16 @@
                             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");
-                            //}
+                            if (receiveBytes != null)
+                            {
+                                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
                         {
@@ -853,12 +1018,31 @@
                         }
 
                     }
+                    else
+                    {
+                        MainPage.Log($"灞�鍩熺綉淇℃伅: 鏄庢枃锛�" + receiveObj.BodyDataString);
+                    }
                 }
 
+                try
+                {
+                    var idMsg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
+                    var hasProcess = hasItBeenProcessed(idMsg.id);
+                    if (hasProcess)
+                    {
+                        return null;
+                    }
+                    MainPage.Log($"澶勭悊灞�鍩熺綉鏁版嵁id:{idMsg.id}");
+
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log($"瑙f瀽灞�鍩熺綉鏁版嵁寮傚父{ex.Message}");
+                }
 
                 if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
                 {
-                   
+
                     var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
                     if (bodyJObj == null)
                     {
@@ -887,17 +1071,21 @@
                         //2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
                         Ins.IsLocalEncrypt = device.isLocalEncrypt;
                         //MainPage.Log("缃戝叧鏈湴鍔犲瘑鐘舵�侊細" + device.local_encrypt.ToString());
+                        //鐧诲綍缃戝叧Tcp
+                        OpenTcpClent();
+
+
                     }
                 }
                 else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
                     receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
                     receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
-                    receiveObj.Topic.Contains( CommunicationTopic.ct.GatewayUpSortTopic))
+                    receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
                 {
                     //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
                     UpdataFunctionStatus(receiveObj.BodyDataString, null);
                 }
-                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply"
+                else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply"
                     || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply"
                     || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp)
                 {
@@ -905,7 +1093,8 @@
                     {
                         MainPage.Log($"灞�鍩熺綉瀹夐槻淇℃伅: {receiveObj.Topic}  : 鍐呭: {res[1]}");
                         var tt = "";
-                        lock (tt) {
+                        lock (tt)
+                        {
                             var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString);
                             if (temp != null)
                             {
@@ -924,8 +1113,29 @@
                             }
                         }
                     }
-                    catch (Exception ex){
+                    catch (Exception ex)
+                    {
                         MainPage.Log($"瀹夐槻灞�鍩熺綉寮傚父锛歿ex.Message}");
+                    }
+                }
+                else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") {
+                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString);
+                    if (temp.GetValue("objects").ToString().Contains("success"))
+                    {
+                        LocalTcpClientLogin = true;
+                        try
+                        {
+                            loginGatewayThread?.Abort();
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"缁堟鐧诲綍缃戝叧tcp寮傚父锛歿ex.Message}");
+                        }
+                        finally
+                        {
+                            loginGatewayThread = null;
+                        }
+                        MainPage.Log("灞�鍩熺綉tcp杩炴帴鐧诲綍缃戝叧鎴愬姛");
                     }
                 }
                 else
@@ -937,6 +1147,29 @@
             return receiveObj;
         }
 
+
+        private List<string> processedDataList = new List<string>();
+        /// <summary>
+        /// 鏄惁宸茬粡澶勭悊杩囨暟鎹�
+        /// </summary>
+        /// <returns></returns>
+        private bool hasItBeenProcessed(string msgId)
+        {
+            if (processedDataList.Contains(msgId))
+            {
+                return true;
+            }
+            else
+            {
+                if(processedDataList.Count> 50)
+                {
+                    processedDataList.RemoveAt(0);
+                }
+                return false;
+            }
+
+        }
+
         /// <summary>
         /// 鏇存柊璁惧鐘舵��
         /// A鍗忚鏁版嵁
@@ -944,6 +1177,12 @@
         /// <param name="updateBytes"></param>
         public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false)
         {
+            ////test 浜戠杩炴帴鎴愬姛鏃讹紝涓嶉�傜敤鏈湴鏁版嵁鏇存柊
+            //if (Ins.GatewayOnline_Cloud && !isCloudData)
+            //{
+            //    return;
+            //}
+
             var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
             if (temp != null)
             {
@@ -956,25 +1195,27 @@
 
                         if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
                         {
-                            if (FunctionList.List.OtherBrandFunction.Count != 0)
+                            if (FunctionList.List.OtherBrandFunction.Count == 0)
+                            {
+                                MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�...");
+                                return;
+                            }
+                            else
                             {
                                 if (FunctionList.List.OtherBrandFunction.Find((obj) => obj.sid == updateTemp.sid) == null)
                                 {
-                                    //MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�...");
                                     return;
                                 }
                             }
                         }
 
-
-
-
                         var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid);
                         if (localFunction == null)
                         {
-                            Console.WriteLine("鎵句笉鍒伴煶涔愭挱鏀惧櫒娣�=======" + revString);
                             continue;
                         }
+                        MainPage.Log(localFunction.name);
+
                         if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
                         {
                             if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk) && !SPK.MusicSpkList().Contains( localFunction.spk))
@@ -994,7 +1235,7 @@
                         //        return;
                         //    }
                         //}
-                        //MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
+                        MainPage.Log($"闊充箰鏀跺埌鏁版嵁:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
@@ -1006,6 +1247,13 @@
                         //鏇存柊鐣岄潰鐘舵��
                         switch (localFunction.spk)
                         {
+                            case SPK.AcstParent:
+                                AcstParentPage.UpdateAcstParentInfo(localFunction);
+                                break;
+                            case SPK.AcstSub:
+                                AcstParentPage.UpdateAcstSubInfo(localFunction);
+                                AcstSubPage.UpdateStatus(localFunction);
+                                break;
                             case SPK.AirSwitch:
                                 AirSwitchPage.UpdataState(localFunction);
                                 if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//濡傛灉鏄甫鐢甸噺鐨勭┖寮�涔熻鏇存柊鑳芥簮鐣岄潰
@@ -1035,6 +1283,8 @@
                                 RGBPage.UpdataStates(localFunction);
                                 break;
                             case SPK.LightRGBW:
+                                localFunction.lastState = Language.StringByID(StringId.Brightness) + " : " + localFunction.GetAttrState(FunctionAttributeKey.Brightness) + "%";
+                                RGBWPage.UpdataStates(localFunction);
                                 break;
                             case SPK.LightCCT:
                                 localFunction.lastState = Language.StringByID(StringId.Brightness) + " : " + localFunction.GetAttrState(FunctionAttributeKey.Brightness) + "%";
@@ -1043,6 +1293,14 @@
                             case SPK.CurtainSwitch:
                                 localFunction.lastState = localFunction.trait_on_off.curValue.ToString() == "on" ? Language.StringByID(StringId.Open) : Language.StringByID(StringId.Close);
                                 CurtainModulePage.UpdataState(localFunction);
+                                break;
+                            case SPK.CurtainDream:
+                                if(localFunction.GetAttrState(FunctionAttributeKey.Percent) == "0")
+                                {
+                                    localFunction.SetAttrState(FunctionAttributeKey.OnOff, "off");
+                                }
+                                localFunction.lastState = localFunction.trait_on_off.curValue.ToString() == "on" ? Language.StringByID(StringId.Open) : Language.StringByID(StringId.Close);
+                                CurtainDreamPage.UpdataState(localFunction);
                                 break;
                             case SPK.CurtainTrietex:
                                 localFunction.lastState = Language.StringByID(StringId.Open) + localFunction.GetAttrState(FunctionAttributeKey.Percent) + "%";
@@ -1053,6 +1311,8 @@
                                 RollingShutterPage.UpdataState(localFunction);
                                 break;
                             case SPK.CurtainShades:
+                                localFunction.lastState = Language.StringByID(StringId.Open) + localFunction.GetAttrState(FunctionAttributeKey.Percent) + "%";
+                                VenetianBlindsPage.UpdataState(localFunction);
                                 break;
                             case SPK.AcStandard:
                             case SPK.HvacAC:
@@ -1139,7 +1399,7 @@
                                 EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
                                 //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction);
                                 break;
-                            case SPK.SensorEnvironment:
+                            case SPK.SensorEnvironment:case SPK.SensorEnvironmentHailin:
                             case SPK.SensorEnvironment2:
                             case SPK.SensorEnvironment3:
                                 if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature))
@@ -1156,6 +1416,7 @@
                             case SPK.ElectricSocket:
                             case SPK.PanelSocket:
                                 SocketPage.UpdataState(localFunction);
+                                SocketPage_InstantaneousValue.UpdataView(localFunction);
                                 break;
                             case SPK.ElectricTV:
                                 break;
@@ -1172,13 +1433,58 @@
                             case SPK.SensorSmoke:
                             case SPK.SensorWater:
                             case SPK.ClothesHanger:
-                            case SPK.SenesorMegahealth:
-                            case SPK.SenesorMegahealth2:
                             case SPK.AirFreshStandard:
                             case SPK.HvacAirFresh:
                             case SPK.SensorGas:
+                            case SPK.HvacCac:
+                            case SPK.SensorHelp:
+                            case SPK.MechanicalArm:
                                 //璁惧鐘舵�佹帹閫�
                                 //鐘舵�佹洿鏂�
+                                Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
+                                break;
+                            case SPK.SenesorMegahealth:
+                            case SPK.SenesorMegahealth2:
+                            case SPK.SensorMmvPose:
+
+                                var tempStatus = localFunction.attributes.Find((sta) => sta.key == FunctionAttributeKey.TargetStatus);
+                                if (tempStatus != null)
+                                {
+
+                                    switch (tempStatus.state)
+                                    {//0绌猴紝1璧帮紝2璺戯紝3鍧愶紝4璺屽�掞紝5绔�
+                                        case "0":
+                                            localFunction.lastState = Language.StringByID(StringId.SensorNormalState);
+                                            break;
+                                        case "1":
+                                            localFunction.lastState = Language.StringByID(StringId.SomeoneIn);
+                                            break;
+                                        case "2":
+                                            if (localFunction.extSet.labModel)
+                                            {
+                                                localFunction.lastState = Language.StringByID(StringId.SomeoneRunning);
+                                            }
+                                            break;
+                                        case "3":
+                                            if (localFunction.extSet.labModel)
+                                            {
+                                                localFunction.lastState = Language.StringByID(StringId.SomeoneSitting);
+                                            }
+                                            break;
+                                        case "4":
+                                            localFunction.lastState = Language.StringByID(StringId.SomeoneFell);
+                                            break;
+                                        case "5":
+                                            if (localFunction.extSet.labModel)
+                                            {
+                                                localFunction.lastState = Language.StringByID(StringId.SomeoneStanding);
+                                            }
+                                            break;
+                                        default:
+
+                                            break;
+                                    }
+                                }
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
                                 break;
                             case SPK.AvMusic:
@@ -1186,6 +1492,14 @@
                                 //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
                                 Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
                                 //wjc
+                                break;
+                            case SPK.Inverter:
+                            case SPK.InverterRst:
+                                var status = new Dictionary<string, object> { ["method"] = "status", ["data"] = temp.objects };
+                                Application.RunOnMainThread(() =>
+                                {
+                                    Inverter.Ins.H5Page.CallJS($"nativeToJs(\'{Newtonsoft.Json.JsonConvert.SerializeObject(status)}\')");
+                                });
                                 break;
                         }
 
@@ -1203,5 +1517,110 @@
             }
         }
 
+
+
+        #region 闂ㄩ攣
+
+        /// <summary>
+        /// //涓�閿紙杩滅▼锛夊紑閿�
+        /// </summary>
+        public void OneKeyUnlocking(Function doorlock,string extStr)
+        {
+            if (Ins.GatewayOnline_Local)
+            {
+                Dictionary<string, string> dic = new Dictionary<string, string>();
+                var functionControlDataObj = doorlock.GetGatewayAlinkDoorlockData(UserInfo.Current.ID,extStr);
+                var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
+                var sendBytes = Ins.ConvertSendBodyData($"/base/{Control.Ins.GatewayId}/thing/service/doorRemoteOpen/down", functionControlDataJson);
+                new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, 0);
+            }
+            else
+            {
+                ConfirmUnlocking(doorlock.deviceId, extStr);
+            }
+        }
+        /// <summary>
+        /// 纭寮�閿�
+        /// </summary>
+        /// <param name="functionId"></param>
+        /// <param name="pwd"></param>
+        public void ConfirmUnlocking(string functionId,string pwd)
+        {
+            Loading loading = new Loading();
+            MainPage.BaseView.AddChidren(loading);
+            loading.BackgroundColor = 0x88000000;
+            loading.LodingBackgroundColor = UI.CSS.CSS_Color.BackgroundColor;
+            loading.Start(Language.StringByID(StringId.PleaseWait));
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                    d.Add("deviceId", functionId);
+                    d.Add("pwd", pwd);
+                    var requestJson = HttpUtil.GetSignRequestJson(d);
+                    var pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/pwdConfirm", requestJson);
+                    if (pack.Code == StateCode.SUCCESS)
+                    {
+                        Newtonsoft.Json.Linq.JObject pairs = Newtonsoft.Json.Linq.JObject.Parse(pack.Data.ToString());
+                        var scrip = pairs.GetValue("scrip");
+
+                        d = new Dictionary<string, object>();
+                        d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                        d.Add("deviceId", functionId);
+                        d.Add("scrip", scrip);
+                        requestJson = HttpUtil.GetSignRequestJson(d);
+                        pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/remoteOpen", requestJson);
+                        //if(pack.Code == StateCode.SUCCESS)
+                        //{
+                        //    return true;
+                        //}
+                        //else
+                        //{
+                        //    return false;
+                        //}
+                        if (pack.Code != StateCode.SUCCESS) {
+                            Application.RunOnMainThread(() => {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                                UserInfo.Current.doorPasswordString = "";//
+                                UserInfo.Current.LastTimeOpenDoor = DateTime.MinValue;
+                            });
+                        }
+                    }
+                    if (pack.Code != StateCode.SUCCESS)
+                    {
+                        Application.RunOnMainThread(() => {
+                            if(string.IsNullOrEmpty(pack.message))
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip),
+                                    Language.StringByID(StringId.OperationFailed));
+                            }
+                            else
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                            }
+                        });
+                    }
+                }
+                catch (Exception ex)
+                {
+
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        loading.RemoveFromParent();
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
+        }
+        //瀵嗙爜鍐荤粨
+        //瀵嗙爜楠岃瘉
+
+        #endregion
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0