From de53d12e223eb8c9a562aeefdcfa9b4039b3d0b0 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期三, 16 六月 2021 10:24:18 +0800 Subject: [PATCH] dome - 1 --- HDL_ON/DAL/DriverLayer/Control.cs | 165 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 87 insertions(+), 78 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index 335e8db..e4f1c1a 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -229,7 +229,7 @@ public void SearchLoaclGateway() { //2021-01-15 : 浣忓畢娌℃湁缁戝畾缃戝叧鐨勬椂鍊欎笉鐢ㄦ悳绱紝骞朵笖涓嶈兘閾炬帴mqtt - if(DB_ResidenceData.Instance.HomeGateway == null) + if(DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId)) { return; } @@ -283,6 +283,7 @@ /// </summary> public void ControlScene(Scene scene) { + //杩滅▼鎴栬�呮帶鍒秎ink缃戝叧鍦烘櫙 if (!Ins.GatewayOnline_Local || DB_ResidenceData.Instance.GatewayType == 1) { new System.Threading.Thread(() => @@ -336,7 +337,7 @@ } } - MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); + //MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); ///绗笁鏂规秱楦﹁澶囩粺涓�浣跨敤杩滅▼鎺у埗 switch(function.spk) @@ -477,47 +478,55 @@ /// 鍙戦�佽鍙栧懡浠� /// 鑷姩鍒ゆ柇鏄惁涓篈鍗忚璁惧 /// </summary> - public void SendReadCommand(Function function) + public void SendReadCommand(Function function ,bool forceRemote = false) { function.refreshTime = DateTime.Now; - if (Ins.GatewayOnline_Local) + if (forceRemote) { - - if (DB_ResidenceData.Instance.GatewayType == 0) + var pm = new DAL.Server.HttpServerRequest(); + var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); + } + else + { + if (Ins.GatewayOnline_Local) { - try + + if (DB_ResidenceData.Instance.GatewayType == 0) { - new Control_Udp().ReadBusData(function); + try + { + new Control_Udp().ReadBusData(function); + } + catch (Exception ex) + { + MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}"); + } } - catch (Exception ex) + else { - MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}"); + var readKey = new Dictionary<string, string>(); + readKey.Add("sid", function.sid); + + var readDataObj = new AlinkReadFunctionStatusObj() + { + id = Ins.msg_id.ToString(), + objects = new List<Dictionary<string, string>>() + { + readKey + }, + 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 readKey = new Dictionary<string, string>(); - readKey.Add("sid", function.sid); - - var readDataObj = new AlinkReadFunctionStatusObj() - { - id = Ins.msg_id.ToString(), - objects = new List<Dictionary<string, string>>() - { - readKey - }, - 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); + var pm = new DAL.Server.HttpServerRequest(); + var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); } - } - else - { - var pm = new DAL.Server.HttpServerRequest(); - var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); } } @@ -561,7 +570,7 @@ string sendDataString = topicString + lengthString + bodyDataString; byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString); - //MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n"); + MainPage.Log($"杞崲HDL-Link鏁版嵁\r\n{sendDataString}\r\n"); return sendDataBytes; } @@ -602,7 +611,7 @@ } } - //MainPage.Log($"灞�鍩熺綉淇℃伅: {receiveObj.Topic}"); + MainPage.Log($"灞�鍩熺綉淇℃伅: {receiveObj.Topic} : 鍐呭: {res[1]}"); //楠岃瘉鏈夋晥鏁版嵁闀垮害 @@ -613,17 +622,18 @@ //} receiveObj.BodyDataString = res[1]; - var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); - if (bodyJObj == null) - { - return receiveObj; - } if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply) { - var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); - if (device.device_mac == DB_ResidenceData.Instance.residenceGatewayMAC) + var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); + if (bodyJObj == null) { - //MainPage.Log("鏈湴鎼滅储缃戝叧鎴愬姛"); + return receiveObj; + } + + var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); + if (device.device_mac.ToUpper() == DB_ResidenceData.Instance.HomeGateway.mac.ToUpper()) + { + MainPage.Log("鏈湴鎼滅储缃戝叧鎴愬姛"); Ins.IsSearchLocalGatewaySuccessful = true; Ins.GatewayOnline_Local = true; if (!string.IsNullOrEmpty(device.gatewayId)) @@ -634,7 +644,7 @@ { Ins.GatewayId = device.device_mac; } - reportIp = "239.0.168.188";// device.ip_address; + reportIp = "239.0.168.188";// device.ip_address;//涓绘挱鍦板潃涔熻兘鎺у埗璁惧 } } else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || @@ -643,6 +653,11 @@ { //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮� UpdataFunctionStatus(receiveObj.BodyDataString, null); + } + else + { + //涓�浜涚壒娈婄殑涓婚澶勭悊(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�) + Stan.HdlCloudReceiveLogic.Current.CloudOverallMsgReceiveEx(receiveObj.Topic, receiveObj.BodyDataString); } } return receiveObj; @@ -655,15 +670,6 @@ /// <param name="updateBytes"></param> public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false) { - - if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞� - { - if (FunctionList.List.GetDeviceFunctionList(SPK.BrandType.Tuya).Count == 0) - { - //MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�..."); - return; - } - } var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString); if (temp != null) { @@ -673,6 +679,22 @@ { try { + + if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞� + { + if (FunctionList.List.OtherBrandFunction.Count != 0) + { + 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) { @@ -697,6 +719,9 @@ Function localObj = null; switch (localFunction.spk) { + case SPK.ElectricEnergy: + EnergyMainPage.UpdataStatus(localFunction); + break; case SPK.LightSwitch: RelayPage.UpdataState(localFunction); break; @@ -803,36 +828,18 @@ case SPK.SensorTVOC: case SPK.SensorTemperature: case SPK.SensorHumidity: - var sensor = FunctionList.List.GetEnvirSensorsList().Find((obj) => obj.sid == updateTemp.sid); - if (sensor != null) + if(localFunction.spk == SPK.SensorTemperature) { - localObj = sensor; - foreach (var attr in updateTemp.status) - { - var localAttr = sensor.attributes.Find((obj) => obj.key == attr.key); - if (localAttr != null) - { - localAttr.curValue = attr.value; - } - } - EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor); + HomePage.LoadEvent_RefreshEnvirIndoorTemp(); } + else if (localFunction.spk == SPK.SensorHumidity) + { + HomePage.LoadEvent_RefreshEnvirIndoorHumi(); + } + EnvironmentalPage.LoadEvent_UpdataStatus(localFunction); break; case SPK.ElectricSocket: - var es = FunctionList.List.GetElectricSocketList().Find((obj) => obj.sid == updateTemp.sid); - if (es != null) - { - localObj = es; - foreach (var attr in updateTemp.status) - { - var localAttr = es.attributes.Find((obj) => obj.key == attr.key); - if (localAttr != null) - { - localAttr.curValue = attr.value; - } - } - SocketPage.UpdataState(es); - } + SocketPage.UpdataState(localFunction); break; case SPK.ElectricTV: break; @@ -845,8 +852,10 @@ case SPK.SensorSmoke: case SPK.SensorWater: case SPK.ClothesHanger: - case SPK.IrAC: + case SPK.AcIr: + case SPK.SenesorMegahealth: //璁惧鐘舵�佹帹閫� + //鐘舵�佹洿鏂� Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status); break; } -- Gitblit v1.8.0