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 | 45 ++++++++++++++++----------------------------- 1 files changed, 16 insertions(+), 29 deletions(-) diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs index 4c86695..13996e8 100644 --- a/HDL_ON/DAL/DriverLayer/Control.cs +++ b/HDL_ON/DAL/DriverLayer/Control.cs @@ -123,7 +123,7 @@ /// <summary> /// 鏈湴udp /// </summary> - public Control_Udp myUdp = null; + public Control_Udp myUdp1 = null; /// <summary> /// 閫氳鏂瑰紡 @@ -144,11 +144,6 @@ /// </summary> public void OpenUdp(int port) { - if (myUdp == null) - { - myUdp = new Control_Udp(); - } - UdpSocket._BusSocket.Start(port); } /// <summary> @@ -156,10 +151,6 @@ /// </summary> public void CloseUdp() { - if (myUdp != null) - { - myUdp = null; - } UdpSocket._BusSocket.Stop(); } @@ -197,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); } @@ -227,7 +218,7 @@ { if (DB_ResidenceData.Instance.GatewayType == 0) { - myUdp.ControlBusScenes(scene); + new Control_Udp().ControlBusScenes(scene); } } } @@ -263,10 +254,7 @@ { try { - if (myUdp != null) - { - myUdp.WriteBusData(function, commandDictionary); - } + new Control_Udp().WriteBusData(function, commandDictionary); } catch (Exception ex) { @@ -276,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); } } } @@ -311,7 +296,7 @@ { try { - Ins.myUdp.ReadBusData(function); + new Control_Udp().ReadBusData(function); } catch (Exception ex) { @@ -334,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); } } } @@ -380,7 +365,7 @@ }; var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson); - Ins.myUdp.SendLocalHdlLinkData(sendBytes); + new Control_Udp().SendLocalHdlLinkData(sendBytes,aLinkData.id); } } /// <summary> @@ -468,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; @@ -479,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