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 |  127 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 113 insertions(+), 14 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index ab30fc6..652bc0d 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -29,11 +29,27 @@
         /// 璁板綍鎺ユ敹鍒扮殑娑堟伅锛屾柟渚縵b鐨勫伐绋嬪笀璋冭瘯浠栦滑鐨勮澶�
         /// </summary>
         public List<string> MsgInfoList = new List<string>();
+        private bool _LocalTcpClientLogin = false;
         /// <summary>
         /// 鏈湴tcp瀹㈡埛绔繛鎺ユ槸鍚︽垚鍔�
         /// 鏄惁鐧诲綍缃戝叧鎴愬姛
         /// </summary>
-        public bool LocalTcpClientLogin = false;
+        public bool LocalTcpClientLogin
+        {
+            get
+            {
+                return _LocalTcpClientLogin;
+            }
+            set
+            {
+                _LocalTcpClientLogin = value;
+                if (!value)
+                {
+                    loginGatewayThread?.Abort();
+                    loginGatewayThread = null;
+                }
+            }
+        }
 
         int _msg_id = 1;
         /// <summary>
@@ -222,8 +238,9 @@
             if (myTcpClient == null)
             {
                 myTcpClient = new Control_TcpClient(reportIp);
-                myTcpClient.Connect();
             }
+            myTcpClient.Connect();
+
         }
 
         /// <summary>
@@ -294,9 +311,9 @@
             if(loginGatewayThread== null)
             {
                 loginGatewayThread = new System.Threading.Thread(() => {
-                    while (true)
+                    while (!Ins.myTcpClient.isConnected)
                     {
-                        if (Ins.GatewayOnline_Local && myTcpClient.isConnected && LocalTcpClientLogin)
+                        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 };
@@ -309,9 +326,28 @@
                         }
                         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();
+                }
+            }
+            
         }
 
 
@@ -801,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>
@@ -880,7 +943,6 @@
         {
             LocalCommunicationData receiveObj = new LocalCommunicationData();
 
-            MainPage.Log($"灞�鍩熺綉淇℃伅: \r\n{receiveString}");
 
             var res = receiveString.Split("\r\n\r\n");
 
@@ -912,9 +974,10 @@
                 //}
                 receiveObj.BodyDataString = res[1];
 
-                if(receiveObj.Topic == CommunicationTopic.ct.HeartBeat)
+                if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
                 {
-
+                    Ins.myTcpClient.ClearHeartBeatLog();
+                    MainPage.Log("tcp蹇冭烦鍥炲");
                     return null;
                 }
 
@@ -924,7 +987,6 @@
                     //鍒ゆ柇褰撳墠缃戝叧鏄惁寮�鍚簡鏈湴鍔犲瘑
                     if (IsLocalEncryptAndGetAesKey)
                     {
-                        MainPage.Log($"灞�鍩熺綉淇℃伅 寮�濮嬭В瀵�");
                         if (originalReceiveBytes != null)
                         {
                             //鎷垮埌鍘熷Bytes鏁版嵁鍘昏В瀵�
@@ -955,6 +1017,10 @@
                             //MainPage.Log($"灞�鍩熺綉淇℃伅: 瑙e瘑鍚庯細" + receiveObj.BodyDataString);
                         }
 
+                    }
+                    else
+                    {
+                        MainPage.Log($"灞�鍩熺綉淇℃伅: 鏄庢枃锛�" + receiveObj.BodyDataString);
                     }
                 }
 
@@ -1005,10 +1071,9 @@
                         //2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
                         Ins.IsLocalEncrypt = device.isLocalEncrypt;
                         //MainPage.Log("缃戝叧鏈湴鍔犲瘑鐘舵�侊細" + device.local_encrypt.ToString());
-
+                        //鐧诲綍缃戝叧Tcp
                         OpenTcpClent();
 
-                        LoginGateway();
 
                     }
                 }
@@ -1058,6 +1123,19 @@
                     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
@@ -1157,18 +1235,25 @@
                         //        return;
                         //    }
                         //}
-                        //MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
+                        MainPage.Log($"闊充箰鏀跺埌鏁版嵁:{revString}");
                         foreach (var attr in updateTemp.status)
                         {
                             localFunction.time_stamp = temp.time_stamp;
                             localFunction.SetAttrState(attr.key, attr.value);
-                            //Console.WriteLine("闊充箰鎾斁鍣ㄦ坊鍔犵紦瀛樻暟鎹�=======" + revString);
+                            Console.WriteLine("闊充箰鎾斁鍣ㄦ坊鍔犵紦瀛樻暟鎹�=======" + revString);
 
                         }
 
                         //鏇存柊鐣岄潰鐘舵��
                         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)//濡傛灉鏄甫鐢甸噺鐨勭┖寮�涔熻鏇存柊鑳芥簮鐣岄潰
@@ -1198,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) + "%";
@@ -1224,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:
@@ -1310,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))
@@ -1349,12 +1438,14 @@
                             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)
@@ -1399,9 +1490,17 @@
                             case SPK.AvMusic:
                             case SPK.MusicStandard:
                                 //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
-                                //Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
+                                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;
                         }
 
                         HomePage.UpdataFunctionStates(localFunction);

--
Gitblit v1.8.0