From 5eeafe3af80bfd88306bd8ad9e76c8f4b51ca35f Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 17 十二月 2020 14:16:20 +0800 Subject: [PATCH] 增加本地发送的重发机制 --- HDL_ON/DAL/DriverLayer/Control.cs | 89 +++++++++++++++++++++++++------------------- 1 files changed, 51 insertions(+), 38 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index 9d0256a..13996e8 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -77,7 +77,12 @@ if (value) { MainPage.Log($"缃戝叧鍦ㄧ嚎锛屽埛鏂拌澶囩姸鎬�"); - FunctionList.List.ReadAllFunctionStatus(); + new System.Threading.Thread(() => + { + System.Threading.Thread.Sleep(1000); + FunctionList.List.ReadAllFunctionStatus(); + }) + { IsBackground = true, Priority = System.Threading.ThreadPriority.AboveNormal }.Start(); } } } @@ -118,7 +123,7 @@ /// <summary> /// 鏈湴udp /// </summary> - public Control_Udp myUdp = null; + public Control_Udp myUdp1 = null; /// <summary> /// 閫氳鏂瑰紡 @@ -139,11 +144,6 @@ /// </summary> public void OpenUdp(int port) { - if (myUdp == null) - { - myUdp = new Control_Udp(); - } - UdpSocket._BusSocket.Start(port); } /// <summary> @@ -151,10 +151,6 @@ /// </summary> public void CloseUdp() { - if (myUdp != null) - { - myUdp = null; - } UdpSocket._BusSocket.Stop(); } @@ -192,11 +188,11 @@ break; if (DB_ResidenceData.Instance.GatewayType == 0) { - myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); + new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); } else if (DB_ResidenceData.Instance.GatewayType == 1) { - myUdp.SearchLocalGateway(); + new Control_Udp().SearchLocalGateway(); } System.Threading.Thread.Sleep(500); } @@ -214,13 +210,16 @@ /// </summary> public void ControlScene(Scene scene) { - if(myUdp!=null) - { - myUdp.ControlBusScenes(scene); - } - if(myTcpClient!= null) + if (Ins.IsRemote || DB_ResidenceData.Instance.GatewayType == 1) { ControlAProtocolScene(scene); + } + else + { + if (DB_ResidenceData.Instance.GatewayType == 0) + { + new Control_Udp().ControlBusScenes(scene); + } } } @@ -255,10 +254,7 @@ { try { - if (myUdp != null) - { - myUdp.WriteBusData(function, commandDictionary); - } + new Control_Udp().WriteBusData(function, commandDictionary); } catch (Exception ex) { @@ -268,13 +264,10 @@ //ALink鎺у埗 else { - if (myUdp != null) - { - var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); - var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); - var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); - Ins.myUdp.SendLocalHdlLinkData(sendBytes); - } + var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); + var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); + var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); + new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id); } } } @@ -303,7 +296,7 @@ { try { - Ins.myUdp.ReadBusData(function); + new Control_Udp().ReadBusData(function); } catch (Exception ex) { @@ -326,7 +319,7 @@ }; var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); - Ins.myUdp.SendLocalHdlLinkData(sendBytes); + new Control_Udp().SendLocalHdlLinkData(sendBytes,readDataObj.id); } } } @@ -347,15 +340,33 @@ //} /// <summary> - /// 鎺у埗a鍗忚鍦烘櫙 + /// a鍗忚鎺у埗鍦烘櫙 /// </summary> /// <param name="scene"></param> static void ControlAProtocolScene(Scene scene) { - var sendSidObj = new AProtocolSendingObject(); - sendSidObj.time_stamp = ""; - sendSidObj.type = "device_sid"; - sendSidObj.command = "get_list_response"; + if (Ins.IsRemote) + { + var pm = new HDL_ON.DAL.Server.HttpServerRequest(); + pm.ExecuteScene(scene.userSceneId); + } + else + { + Dictionary<string, string> keys = new Dictionary<string, string>(); + keys.Add("sid", scene.sid); + var aLinkData = new AlinkReadFunctionStatusObj() + { + id = Ins.msg_id.ToString(), + objects = new List<Dictionary<string, string>>() + { + keys + }, + time_stamp = Utlis.GetTimestamp() + }; + var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); + var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson); + new Control_Udp().SendLocalHdlLinkData(sendBytes,aLinkData.id); + } } /// <summary> /// 杞崲閫氳鏁版嵁 @@ -442,7 +453,8 @@ else if(receiveObj.Topic == CommunicationTopic.ct.ReadStatus+"_reply" || receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus) { - UpdataFunctionStatus(receiveObj.BodyDataString); + //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮� + UpdataFunctionStatus(receiveObj.BodyDataString,null); } } return receiveObj; @@ -453,12 +465,13 @@ /// A鍗忚鏁版嵁 /// </summary> /// <param name="updateBytes"></param> - public void UpdataFunctionStatus(string revString) + public void UpdataFunctionStatus(string revString,byte []usefulBytes) { MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}"); var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString); if (temp != null) { + Control_Udp.ReceiveRepeatManager(temp.id,usefulBytes); var allLocalFuntion = FunctionList.List.GetDeviceFunctionList(); foreach (var updateTemp in temp.objects) { -- Gitblit v1.8.0