From 631f94758c3cb42abcdda8094e77895f376eff16 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期一, 11 一月 2021 14:53:43 +0800 Subject: [PATCH] 2021-1-12-3 --- HDL_ON/DAL/DriverLayer/Control.cs | 103 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 75 insertions(+), 28 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index 8e434c9..fe8179b 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -1,4 +1,4 @@ -using System; +锘縰sing System; using System.Collections.Generic; using System.Text; using HDL_ON.Entity; @@ -82,11 +82,23 @@ { if (_gatewayOnline != value) { - _gatewayOnline = value; - //淇敼涓婚〉杩炴帴鐘舵�� - UI.HomePage.LoadEvent_CheckLinkStatus(); - if (value) + if(value) { + if (IsRemote)//濡傛灉鏄繙绋� + { + if (!DB_ResidenceData.Instance.HomeGateway.gatewayStatus)//杩滅▼鎯呭喌涓嬶紝缃戝叧鏈摼鎺ユ湇鍔″櫒涓嶈兘淇敼涓婚〉缃戝叧鐘舵�� + { + new System.Threading.Thread(() => { + System.Threading.Thread.Sleep(3000); + var pm = new DAL.Server.HttpServerRequest(); + pm.GetGatewayInfo(); + }) { IsBackground = true }.Start(); + return; + } + } + _gatewayOnline = value; + //淇敼涓婚〉杩炴帴鐘舵�� + HomePage.LoadEvent_CheckLinkStatus(); MainPage.Log($"缃戝叧鍦ㄧ嚎锛屽埛鏂拌澶囩姸鎬�"); new System.Threading.Thread(() => { @@ -94,6 +106,12 @@ FunctionList.List.ReadAllFunctionStatus(); }) { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start(); + } + else + { + _gatewayOnline = value; + //淇敼涓婚〉杩炴帴鐘舵�� + HomePage.LoadEvent_CheckLinkStatus(); } } } @@ -103,23 +121,10 @@ /// </summary> public string GatewayId = ""; - bool _isRemote = false; /// <summary> /// 鏄惁涓鸿繙绋嬭繛鎺� /// </summary> - public bool IsRemote - { - get - { - return _isRemote; - } - set - { - _isRemote = value; - //淇敼涓婚〉杩炴帴鐘舵�� - HomePage.LoadEvent_CheckLinkStatus(); - } - } + public bool IsRemote = false; /// <summary> /// 閫氳鍦板潃IP /// </summary> @@ -183,7 +188,9 @@ /// </summary> public void SearchLoaclGateway() { - MainPage.Log($"鎼滅储鏈湴缃戝叧鍒楄〃锛岀綉鍏崇被鍨�:{DB_ResidenceData.Instance.GatewayType}"); + var ggg = DB_ResidenceData.Instance.GatewayType == 0 ? "涓�绔彛" : "A缃戝叧"; + var ggg1 = MainPage.InternetStatus == 1 ? "4G" : "wifi"; + MainPage.Log($"鎼滅储缃戝叧鍒楄〃锛岀綉鍏崇被鍨�:{ggg};缃戠粶绫诲瀷:{ggg1}"); if (MainPage.InternetStatus == 0) { Ins.GatewayOnline = false; @@ -225,8 +232,6 @@ //鏈湴鎼滅储涓嶅埌缃戝叧 if (!Ins.IsRemote) { - //杩炴帴mqtt鍓嶏紝鍏堟柇寮�--2020-12-21 - DAL.Mqtt.MqttClient.DisConnectRemote(); Ins.IsRemote = true; DAL.Mqtt.MqttClient.InitState(); } @@ -243,7 +248,11 @@ { if (Ins.IsRemote || DB_ResidenceData.Instance.GatewayType == 1) { - ControlAProtocolScene(scene); + new System.Threading.Thread(() => + { + ControlAProtocolScene(scene); + }) + { IsBackground = true }.Start(); } else { @@ -264,7 +273,7 @@ /// <returns></returns> public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary) { - function.usageCount++; + function.controlCounter++; function.refreshTime = DateTime.Now; //濡傛灉鏄帶鍒惰皟鍏夌殑寮�鏃讹紝浜害鍊间笉鑳戒负0 @@ -289,6 +298,8 @@ } } + MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); + //杩滅▼閫氳 if (Ins.IsRemote) { @@ -298,7 +309,6 @@ var actionObjs = new List<ApiAlinkControlActionObj>(); actionObjs.Add(apiControlData); var pack = httpServer.ControlDevice(actionObjs); - //MainPage.Log($"{pack.Code}:{pack.Data}"); } //鏈湴閫氳 else @@ -325,6 +335,35 @@ MainPage.Log($"鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}"); } } + } + /// <summary> + /// 鍏ㄥ紑鍏ㄥ叧鍔熻兘 + /// </summary> + public void SwtichFunctions(bool open,List<Function> functions) + { + 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) + { + logString += temp.spk + ":" + temp.sid + "\r\n"; + var apiControlData = temp.GetApiControlData(d); + actionObjs.Add(apiControlData); + count++; + if (count > 9) + { + var result = pm.ControlDevice(actionObjs); + actionObjs = new List<ApiAlinkControlActionObj>(); + count = 0; + MainPage.Log(logString); + logString = ""; + } + } + var pack = pm.ControlDevice(actionObjs); + MainPage.Log(logString); } public void SendApiReadCommand(List<string> functionIds) @@ -403,8 +442,16 @@ { if (Ins.IsRemote) { - var pm = new HDL_ON.DAL.Server.HttpServerRequest(); - pm.ExecuteScene(scene.userSceneId); + //浜戠鍋氬鐞嗗彂閫佷竴绔彛鍦烘櫙 + //if (DB_ResidenceData.Instance.GatewayType == 0) + //{ + // new Control_Udp().ControlBusScenes(scene); + //} + //else + { + var pm = new DAL.Server.HttpServerRequest(); + var result = pm.ExecuteScene(scene.userSceneId); + } } else { @@ -497,7 +544,7 @@ var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); if (device.device_mac == DB_ResidenceData.Instance.residenceGatewayMAC) { - //鏈湴鎼滅储缃戝叧鎴愬姛 + MainPage.Log("鏈湴鎼滅储缃戝叧鎴愬姛"); Control.Ins.IsSearchLocalGatewaySuccessful = true; Ins.GatewayOnline = true; if (!string.IsNullOrEmpty(device.gatewayId)) -- Gitblit v1.8.0