From abf4a98837e43e542701c60b7ec6a088cd5236da Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期一, 22 二月 2021 09:10:35 +0800 Subject: [PATCH] 20210222 --- HDL_ON/DAL/DriverLayer/Control.cs | 182 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 147 insertions(+), 35 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index d6da0f6..20d2fa3 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,27 @@ { if (_gatewayOnline != value) { - _gatewayOnline = value; - //淇敼涓婚〉杩炴帴鐘舵�� - UI.HomePage.LoadEvent_CheckLinkStatus(); - if (value) + if(value) { + if (IsRemote)//濡傛灉鏄繙绋� + { + if(DB_ResidenceData.Instance.HomeGateway == null) + { + return; + } + 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 +110,12 @@ FunctionList.List.ReadAllFunctionStatus(); }) { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start(); + } + else + { + _gatewayOnline = value; + //淇敼涓婚〉杩炴帴鐘舵�� + HomePage.LoadEvent_CheckLinkStatus(); } } } @@ -103,23 +125,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 +192,14 @@ /// </summary> public void SearchLoaclGateway() { - MainPage.Log($"鎼滅储鏈湴缃戝叧鍒楄〃锛岀綉鍏崇被鍨�:{DB_ResidenceData.Instance.GatewayType}"); + //2021-01-15 : 浣忓畢娌℃湁缁戝畾缃戝叧鐨勬椂鍊欎笉鐢ㄦ悳绱紝骞朵笖涓嶈兘閾炬帴mqtt + if(DB_ResidenceData.Instance.HomeGateway == null) + { + return; + } + 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; @@ -191,9 +207,9 @@ } else if (MainPage.InternetStatus == 1) { - if (!Ins.IsRemote) + //if (!Ins.IsRemote) { - Ins.IsRemote = true; + //Ins.IsRemote = true; DAL.Mqtt.MqttClient.InitState(); } } @@ -241,7 +257,11 @@ { if (Ins.IsRemote || DB_ResidenceData.Instance.GatewayType == 1) { - ControlAProtocolScene(scene); + new System.Threading.Thread(() => + { + ControlAProtocolScene(scene); + }) + { IsBackground = true }.Start(); } else { @@ -259,8 +279,9 @@ /// </summary> /// <param name="commandString"></param> /// <param name="function"></param> + /// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param> /// <returns></returns> - public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary) + public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false) { function.controlCounter++; function.refreshTime = DateTime.Now; @@ -287,8 +308,21 @@ } } + MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); + + ///绗笁鏂规秱楦﹁澶囩粺涓�浣跨敤杩滅▼鎺у埗 + switch(function.spk) + { + case SPK.ElectricTuyaAirCleaner: + case SPK.ElectricTuyaFan: + case SPK.ElectricTuyaWaterValve: + case SPK.ElectricTuyaWeepRobot: + useRemote = true; + break; + } + //杩滅▼閫氳 - if (Ins.IsRemote) + if (Ins.IsRemote || useRemote == true) { DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest(); //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋� @@ -296,7 +330,6 @@ var actionObjs = new List<ApiAlinkControlActionObj>(); actionObjs.Add(apiControlData); var pack = httpServer.ControlDevice(actionObjs); - //MainPage.Log($"{pack.Code}:{pack.Data}"); } //鏈湴閫氳 else @@ -320,15 +353,72 @@ var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id); - MainPage.Log($"鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}"); + 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) { var pm = new DAL.Server.HttpServerRequest(); var pack = pm.RefreshDeviceStatus(functionIds); + } + /// <summary> + /// 璇诲彇鍔熻兘璇︾粏鏁版嵁 + /// </summary> + /// <param name="functionIds"></param> + public void ReadFunctionsInfo(List<string> functionIds) + { + var pm = new DAL.Server.HttpServerRequest(); + var pack = pm.GetDeviceInfoList(functionIds); + if(pack!= null&& pack.Data!=null) + { + var ddd = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>>(pack.Data.ToString()); + if(ddd!= null) + { + foreach(var function in ddd) + { + var temp = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.deviceId == function.deviceId); + if(temp!= null) + { + temp = function; + if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(temp.spk)) + { + Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(temp.sid, temp.status); + } + } + } + } + } } /// <summary> @@ -372,7 +462,7 @@ }; var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); - MainPage.Log($"鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}"); + MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}"); new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); } } @@ -401,8 +491,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 { @@ -495,7 +593,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)) @@ -817,14 +915,28 @@ } break; case SPK.ElectricTV: + break; + case SPK.ElectricTuyaAirCleaner: + case SPK.ElectricTuyaFan: + case SPK.ElectricTuyaWeepRobot: + case SPK.ElectricTuyaWaterValve: + //璁惧鐘舵�佹帹閫� + var myDevice = Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid,updateTemp.status); + if (myDevice != null) + { + localObj = myDevice; + } break; default: break; } - HomePage.UpdataFunctionStates(localObj); - RoomPage.UpdataStates(localObj); - FunctionPage.UpdataStates(localObj); - ClassificationPage.UpdataInfo(localObj); + if (localObj != null) + { + HomePage.UpdataFunctionStates(localObj); + RoomPage.UpdataStates(localObj); + FunctionPage.UpdataStates(localObj); + ClassificationPage.UpdataInfo(localObj); + } } } catch (Exception ex) -- Gitblit v1.8.0