From 1d5e384497c7059e09760628dab3e83eb88f97ae Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 04 十二月 2020 17:48:34 +0800 Subject: [PATCH] 2020-12-04-4 --- HDL_ON/DAL/DriverLayer/Control.cs | 68 +++++++++++++++++++++++----------- 1 files changed, 46 insertions(+), 22 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index a2c52c7..22e42b4 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -53,7 +53,7 @@ public string Get_TimeStamp() { long t = DateTime.Now.Ticks / 10000; - return t.ToString(); + return t.ToString(); } bool _gatewayOnline = false; @@ -76,10 +76,28 @@ /// 缃戝叧閫氳ID /// </summary> public string GatewayId; + + bool _isRemote = false; /// <summary> /// 鏄惁涓鸿繙绋嬭繛鎺� /// </summary> - public bool IsRemote = false; + public bool IsRemote { + get + { + return _isRemote; + } + set + { + _isRemote = value; + if(value) + { + DAL.Mqtt.MqttClient.InitState(); + }else + { + DAL.Mqtt.MqttClient.DisConnectRemote(); + } + } + } /// <summary> /// 閫氳鍦板潃IP /// </summary> @@ -128,7 +146,7 @@ /// </summary> public void CloseUdp() { - if(myUdp!= null) + if (myUdp != null) { myUdp = null; } @@ -161,15 +179,24 @@ public void SearchLoaclGateway() { OpenUdp(DB_ResidenceData.residenceData.GatewayType == 0 ? 6000 : 8585); - - if (DB_ResidenceData.residenceData.GatewayType == 0) + new System.Threading.Thread(() => { - myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); - } - else if (DB_ResidenceData.residenceData.GatewayType == 1) - { - myUdp.SearchLocalGateway(); - } + for (int i = 0; i < 5; i++) + { + if (GatewayOnline) + break; + if (DB_ResidenceData.residenceData.GatewayType == 0) + { + myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); + } + else if (DB_ResidenceData.residenceData.GatewayType == 1) + { + myUdp.SearchLocalGateway(); + } + System.Threading.Thread.Sleep(500); + } + }) + { IsBackground = true }.Start(); } /// <summary> @@ -199,19 +226,15 @@ { function.usageCount++; function.refreshTime = DateTime.Now; + DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest(); //杩滅▼閫氳 if (Ins.IsRemote) { - //ALink鎺у埗 - if (DB_ResidenceData.residenceData.GatewayType == 0) - { - - } - //Bus鎺у埗 - else - { - - } + //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋� + var apiControlData = function.GetApiControlData(commandDictionary); + var actionObjs = new List<ApiAlinkControlActionObj>(); + actionObjs.Add(apiControlData); + httpServer.ControlDevice(actionObjs); } //鏈湴閫氳 else @@ -236,7 +259,7 @@ { if (myUdp != null) { - var functionControlDataObj = function.GetControlSendData(commandDictionary); + var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); myUdp.SendLocalHdlLinkData(sendBytes); @@ -357,6 +380,7 @@ Ins.GatewayOnline = true; Ins.GatewayId = device.gatewayId; reportIp = "239.0.168.188";// device.ip_address; + Ins.IsRemote = false; } break; } -- Gitblit v1.8.0