[feat] 调整广播发送函数

为所有需要广播的地方调用做准备

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
xu 2024-06-29 20:30:28 +08:00
parent 40bf208054
commit 361a8bf001

View File

@ -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)
/// <summary>
/// 发送到广播端口
/// </summary>
/// <param name="packet">发送数据</param>
/// <param name="reopensend">发送失败是否要重新打开再发一次</param>
/// <returns></returns>
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
{
@ -1241,7 +1250,25 @@ 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 计算数据校验和
@ -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