From 361a8bf001dd093f44f20d3abd9486e343cc2cfd Mon Sep 17 00:00:00 2001 From: xu Date: Sat, 29 Jun 2024 20:30:28 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E8=B0=83=E6=95=B4=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=87=BD=E6=95=B0=20=20=E4=B8=BA=E6=89=80?= =?UTF-8?q?=E6=9C=89=E9=9C=80=E8=A6=81=E5=B9=BF=E6=92=AD=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E6=96=B9=E8=B0=83=E7=94=A8=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- .../CommModuleGenerateMavLink.cs | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs b/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs index 063030c..22a845e 100644 --- a/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs +++ b/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs @@ -540,6 +540,9 @@ namespace Plane.CommunicationManagement byte[] data = packet1.Concat(packet2).Concat(packet3).ToArray(); await WriteCommPacketAsync(copterId, MavComm.COMM_DOWNLOAD_COMM, data, batchPacket).ConfigureAwait(false); + if (Recomisopen) + await BroadcastSendAsync(data); + } else { @@ -1213,11 +1216,16 @@ namespace Plane.CommunicationManagement byte rtcm_tmpser = 0; //用于通讯模块的 byte rtcm_Broadser = 0;//用于广播的 - - public async Task BroadcastbackupGpsDataAsync(byte[] packet) + /// + /// 发送到广播端口 + /// + /// 发送数据 + /// 发送失败是否要重新打开再发一次 + /// + public async Task BroadcastSendAsync(byte[] packet,bool reopensend = false) { - bool sendok=false; + bool sendok = false; try { //防止阻塞,异步发送 @@ -1229,7 +1237,8 @@ namespace Plane.CommunicationManagement { Windows.Messages.Message.Show("广播端口发送失败..."); } - if (!sendok) + + if (!sendok&& reopensend) { try { @@ -1240,9 +1249,27 @@ namespace Plane.CommunicationManagement { Windows.Messages.Message.Show("再次打开串口失败" + ex.Message); ReOpenRtcmserial(); - } + } + if (Recomisopen) + { + try + { + await RecomPort.BaseStream.WriteAsync(packet, 0, packet.Length); + //RecomPort.Write(packet, 0, packet.Length); + } + catch (Exception ex) + { + Windows.Messages.Message.Show("再次发送失败..."); + } + } + } } + + public async Task BroadcastbackupGpsDataAsync(byte[] packet) + { + await BroadcastSendAsync(packet,true); + } // get sum crc 计算数据校验和 public byte checkrtrcmsum(byte[] data, ushort length) @@ -1453,8 +1480,7 @@ namespace Plane.CommunicationManagement RecomPort.StopBits = StopBits.One; RecomPort.DataBits = 8; RecomPort.Handshake = Handshake.None; - //改为异步更好一些 - // RecomPort.WriteTimeout = 500; // 设置写入超时为500毫秒 + RecomPort.WriteTimeout = 500; // 设置写入超时为500毫秒,防止Close时候卡死 try