1修复开网络RTK后,界面卡顿bug,rtkloop增加关键延迟

2将now改为utcnow,减少系统占用
This commit is contained in:
pxzleo 2024-01-10 16:15:33 +08:00
parent 9cfd7db051
commit 17e4c8bd97
2 changed files with 1133 additions and 1131 deletions

View File

@ -319,11 +319,11 @@ namespace Plane.FormationCreator.Formation
//得到千寻账号
_copterManager.GetRTKURL();
//等到返回5秒
DateTime Tthen = DateTime.Now;
DateTime Tthen = DateTime.UtcNow;
do
{
Application.DoEvents();
} while ((_copterManager.RTK_URL == "") || (Tthen.AddSeconds(2) > DateTime.Now));
} while ((_copterManager.RTK_URL == "") || (Tthen.AddSeconds(2) > DateTime.UtcNow));
}
if (_copterManager.RTK_URL != "")
{
@ -401,6 +401,7 @@ namespace Plane.FormationCreator.Formation
{
int reconnecttimeout = 10;
DateTime lastrecv = DateTime.MinValue;
DateTime unow = DateTime.UtcNow;
long last_send_pos = CurrentTimeMillis()- 5000;//5秒发一次就可以了
bool Ensend = false;
//新版本打包发送模式
@ -413,7 +414,8 @@ namespace Plane.FormationCreator.Formation
{
try
{
if ((DateTime.Now - lastrecv).TotalSeconds > reconnecttimeout || !comPort.IsOpen)
unow=DateTime.UtcNow;
if ((unow - lastrecv).TotalSeconds > reconnecttimeout || !comPort.IsOpen)
{
if (comPort is CommsNTRIP)
{
@ -424,7 +426,7 @@ namespace Plane.FormationCreator.Formation
comPort.Open();
}
// reset timer
lastrecv = DateTime.Now;
lastrecv = unow;
}
}
catch { }
@ -440,9 +442,9 @@ namespace Plane.FormationCreator.Formation
while (comPort.BytesToRead > 0)
{
int read = comPort.Read(buffer, 0, Math.Min(buffer.Length, comPort.BytesToRead));
Console.WriteLine(string.Format("{0:T} - read:{1:D}", DateTime.Now, read));
//Console.WriteLine(string.Format("{0:T} - read:{1:D}", DateTime.UtcNow, read));
if (read > 0)
lastrecv = DateTime.Now;
lastrecv = DateTime.UtcNow;
bps += read; //接收速率bps,byte需要*8到bit
// check for valid rtcm/sbp/ubx packets
for (int a = 0; a < read; a++)
@ -458,7 +460,7 @@ namespace Plane.FormationCreator.Formation
//广播数据直接发送不受小带宽数据选项影响
if (_enrecom)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--广播Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
// Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss") + "--广播Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
_commModuleManager.BroadcastGpsDataAsync(rtcm.packet, (ushort)rtcm.length);
}
@ -466,7 +468,7 @@ namespace Plane.FormationCreator.Formation
if (!SmallRtcmData)
{
//发送到飞机
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--通讯模块发送Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
// Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss") + "--通讯模块发送Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length);
//累加消息数量,用于界面显示
bpsusefull += rtcm.length;
@ -518,7 +520,7 @@ namespace Plane.FormationCreator.Formation
}
if (Ensend)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--通讯模块发送Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
//Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss") + "--通讯模块发送Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");
await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length);
//累加消息数量,用于界面显示
bpsusefull += rtcm.length;
@ -541,7 +543,7 @@ namespace Plane.FormationCreator.Formation
// ubx
if ((seenmsg = ubx_m8p.Read(buffer[a])) > 0)
{
Console.WriteLine(string.Format("{0:T}----------------------------ubx_m8p ", DateTime.Now));
//Console.WriteLine(string.Format("{0:T}----------------------------ubx_m8p ", DateTime.UtcNow));
rtcm.resetParser();
nmea.resetParser();
/*
@ -555,7 +557,7 @@ namespace Plane.FormationCreator.Formation
// nmea
if ((seenmsg = nmea.Read(buffer[a])) > 0)
{
Console.WriteLine(string.Format("{0:T}----------------------------nmea ", DateTime.Now));
//Console.WriteLine(string.Format("{0:T}----------------------------nmea ", DateTime.UtcNow));
rtcm.resetParser();
ubx_m8p.resetParser();
/*
@ -569,8 +571,9 @@ namespace Plane.FormationCreator.Formation
}
////////////////////////////解析/发送RTCM结束
await Task.Delay(10);
await Task.Delay(20);
}
await Task.Delay(20); //新增加关键延迟,要不然界面会出现卡死现象
}
catch (Exception ex)
{

View File

@ -188,22 +188,21 @@ namespace Plane.Util
{
if (lat != 0 || lng != 0)
{
if (_lastnmea.AddSeconds(30) < DateTime.Now)
DateTime currentUtcTime = DateTime.UtcNow;
if (_lastnmea.AddSeconds(30) < currentUtcTime)
{
double latdms = (int)lat + ((lat - (int)lat) * .6f);
double lngdms = (int)lng + ((lng - (int)lng) * .6f);
var line = string.Format(System.Globalization.CultureInfo.InvariantCulture,
"$GP{0},{1:HHmmss.ff},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", "GGA",
DateTime.Now.ToUniversalTime(), Math.Abs(latdms * 100).ToString("0000.00"), lat < 0 ? "S" : "N",
currentUtcTime, Math.Abs(latdms * 100).ToString("0000.00"), lat < 0 ? "S" : "N",
Math.Abs(lngdms * 100).ToString("00000.00"), lng < 0 ? "W" : "E", 1, 10,
1, alt.ToString("0.00"), "M", 0, "M", "0.0", "0");
string checksum = GetChecksum(line);
WriteLine(line + "*" + checksum);
_lastnmea = DateTime.Now;
_lastnmea = currentUtcTime;
}
}