【FormationCreator.sln】加入性能检查

[App.xaml.cs]停用tcp连接和编队控制器formationController
[Copter.cs]关闭心跳包发送,减小数据发送量
[Plane.FormationCreator.csproj]加入ParamFile.cs修改参数
[ControlPanelViewModel.cs]
1加入读参数文件,可批量设置参数
2修改ReadRTKPacketAsync的bug,导致发送数据量太大>1000/s
3航线暂时改为停2秒
[CopterListViewModel.cs]加入数据收发量统计
This commit is contained in:
panxu 2018-05-12 23:16:13 +08:00
parent 031ba6a647
commit 71f2870968
8 changed files with 145 additions and 24 deletions

View File

@ -24,6 +24,9 @@ EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "PlaneGcsSdk.Contract_Shared", "..\Plane.Sdk3\PlaneGcsSdk.Contract_Shared\PlaneGcsSdk.Contract_Shared.shproj", "{695733D7-99FF-4707-8C89-474E949CADCB}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\Plane.Sdk3\PlaneGcsSdk_Shared\PlaneGcsSdk_Shared.projitems*{0111eb6e-72e3-499c-a3ba-022f5bbc4caf}*SharedItemsImports = 4
..\Plane.Sdk3\PlaneGcsSdk_Shared\PlaneGcsSdk_Shared.projitems*{2be393dc-21a4-48b3-83fd-f21cbe8b038b}*SharedItemsImports = 13

View File

@ -45,10 +45,10 @@ namespace Plane.FormationCreator
}
return LoadAssembly(simpleName);
};
this.DispatcherUnhandledException += async (s, e) =>
this.DispatcherUnhandledException += (s, e) =>
{
_logger.Log(e.Exception);
await _formationController.AllStop();
// await _formationController.AllStop();
TcpServerConnectionManager.Instance.StopListening();
UdpServerConnectionManager.Instance.StopReceiving();
};
@ -56,7 +56,7 @@ namespace Plane.FormationCreator
{
try
{
TcpServerConnectionManager.Instance.StopListening();
// TcpServerConnectionManager.Instance.StopListening();
UdpServerConnectionManager.Instance.StopReceiving();
}
catch (Exception ex)
@ -115,19 +115,24 @@ namespace Plane.FormationCreator
MainWindow.Show();
try
{
/* by panxu tcp 使 --使TCP监听在自动获取IP的情况下
TcpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
if (!TcpServerConnectionManager.Instance.StartListening())
{
Alert.Show("网络连接不正常,无法连接飞机。");
return;
}
*/
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
{
_logger.Log(e1.Exception);
};
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
UdpServerConnectionManager.Instance.StartReceiving();
}
catch (Exception ex)
{

View File

@ -12,7 +12,7 @@ namespace Plane.FormationCreator.Formation
{
class Copter : PLCopter
{
public Copter(IConnection Connection, SynchronizationContext uiThreadContext) : base(Connection, uiThreadContext)
public Copter(IConnection Connection, SynchronizationContext uiThreadContext) : base(Connection, uiThreadContext,false)
{
Brush = _brushes[NextBrushIndex()];
}

View File

@ -145,6 +145,7 @@
<Compile Include="ServiceLocatorConfigurer.cs" />
<Compile Include="Test.cs" />
<Compile Include="CalculationLogLatDistance.cs" />
<Compile Include="Util\ParamFile.cs" />
<Compile Include="ViewModels\ConnectViewModel.cs" />
<Compile Include="ViewModels\ControlPanelViewModel.cs" />
<Compile Include="ViewModels\CopterListViewModel.cs" />

View File

@ -15,6 +15,8 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Plane.Communication;
using Microsoft.Win32;
using Plane.Util;
namespace Plane.FormationCreator.ViewModels
{
@ -178,6 +180,55 @@ namespace Plane.FormationCreator.ViewModels
}));
}
}
private ICommand _LoadParamfile;
public ICommand LoadParamfile
{
get
{
return _LoadParamfile ?? (_LoadParamfile = new RelayCommand(async () =>
{
var dialog = new OpenFileDialog
{
DefaultExt = "param",
Filter = "飞行参数 (*.param)|*.param"
};
if (dialog.ShowDialog() == true)
{
bool ifallok = true;
var paramlist = ParamFile.loadParamFile(dialog.FileName);
foreach (string name in paramlist.Keys)
{
float value = float.Parse( paramlist[name].ToString());
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
(copter => copter.SetParamAsync(name, value)));
await Task.WhenAll(
_copterManager.AcceptingControlCopters.Select(async copter =>
{
float getvaule = await copter.GetParamAsync(name);
if (getvaule != value)
{
ifallok = false;
Alert.Show(copter.Id +"参数["+ name+ "]设置失败,读取的值是[" + getvaule+"]", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
));
}
if (ifallok)
Alert.Show("所有已选的飞机参数设置完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
else
Alert.Show("有部分飞机参数设置失败,请检查并再次设置", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}));
}
}
private ICommand _ParamModify;
@ -247,20 +298,25 @@ namespace Plane.FormationCreator.ViewModels
}
// limit to 110 byte packets
byte[] buffer = new byte[180];
byte[] buffer;
int length = 0;
try
{
if (Rtkport.BytesToRead() > 0)//while (Rtkport.BytesToRead() > 0)
length = Math.Min(180, Rtkport.BytesToRead());
if (length > 0)//while (Rtkport.BytesToRead() > 0)
{
int read = await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, Rtkport.BytesToRead()));
// sendData(buffer, (byte)read);
buffer = new byte[length];
int read = await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, length));
// sendData(buffer, (byte)read);
}
else
return null;
/*
if (await Rtkport.ReadAsync(buffer, 0, 1) == 0)
@ -273,7 +329,7 @@ namespace Plane.FormationCreator.ViewModels
}
*/
}
catch (Exception ex)
{
@ -324,13 +380,19 @@ namespace Plane.FormationCreator.ViewModels
{
//读入RTK数据
var packet = await ReadRTKPacketAsync().ConfigureAwait(false);
//分发到每个飞机
foreach (var copter in _copterManager.Copters)
if (packet != null)
{
// int iid = Convert.ToInt32(copter.Name);
//临时用来区分RTK发送数据
//if (iid<50)
Console.WriteLine("rev:" + (ushort)packet.Length);
//分发到每个飞机
foreach (var copter in _copterManager.Copters)
{
// int iid = Convert.ToInt32(copter.Name);
//临时用来区分RTK发送数据
//if (iid<50)
await copter.InjectGpsDataAsync(packet, (ushort)packet.Length);
}
}
@ -544,13 +606,14 @@ namespace Plane.FormationCreator.ViewModels
var _flightTaskManager = _taskmodimodel.FlightTaskManager;
int coptercount = _copterManager.Copters.Count;
int taskcount = _flightTaskManager.Tasks.Count;
bool havewritefault = true;
if (taskcount < 2) return;
for (int i = 0; i < coptercount; i++)
{
///写航线开始
var missions = new IMission[taskcount + 1]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分
var missions = new IMission[taskcount]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分
int missindex = 0;
for (int j = 0; j < _flightTaskManager.Tasks.Count; j++)
@ -560,14 +623,14 @@ namespace Plane.FormationCreator.ViewModels
{
case FlightTaskType.TakeOff:
missions[missindex++] = Mission.CreateTakeoffMission(10,10,_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng, 3);
missions[missindex++] = Mission.CreateTakeoffMission(2,5,_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j+1].SingleCopterInfos[i].TargetAlt);
//要起飞任务
break;
case FlightTaskType.FlyTo:
missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, 3);
missions[missindex++] = Mission.CreateWaypointMission(5,15,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
break;
case FlightTaskType.Loiter:
// missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
@ -588,8 +651,15 @@ namespace Plane.FormationCreator.ViewModels
}
var result = await _copterManager.Copters[i].WriteMissionListAsync(missions);
//MessageBox.Show($"The result of WriteMissions: {result}");
if (!result)
{
Alert.Show($"飞机:{_copterManager.Copters[i].Name} 任务写入失败!");
return;
}
}
Alert.Show($"所有任务写入成功!");
// var firstCopter = _copterManager.Copters.First();

View File

@ -25,6 +25,37 @@ namespace Plane.FormationCreator.ViewModels
_copterManager = copterManager;
_mapManager = mapManager;
_flightTaskManager = flightTaskManager;
System.Timers.Timer t = new System.Timers.Timer(5000); //实例化Timer类设置间隔时间为1秒
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件;
t.AutoReset = true; //设置是执行一次false还是一直执行(true)
t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
int allrec = 0;
int allsend = 0;
int copterrec = 0;
int coptersend = 0;
foreach (var copter in _copterManager.Copters)
{
copter.GetCommunicationNumber(out copterrec, out coptersend);
allrec += copterrec;
allsend += coptersend;
copter.ResetCommunicationNumber();
}
allrec /= 5;
allsend /= 5;
if (_copterManager.Copters.Count>0)
Communinfo = "接收:" + allrec + "/s;发送:"+ allsend+"/s 单机:"+ allrec/ _copterManager.Copters.Count+"/s;"+
allsend / _copterManager.Copters.Count+"/s";
}
private CopterManager _copterManager;
@ -43,6 +74,13 @@ namespace Plane.FormationCreator.ViewModels
private int _virtualCopterId = 1;
private LatLng? _lastVirtualCopterLocation;
private string _Communinfo = "0字节/秒";
public string Communinfo
{
get { return _Communinfo; }
set { Set(nameof(Communinfo), ref _Communinfo, value); }
}
private ICommand _AddVirtualCopterCommand;
public ICommand AddVirtualCopterCommand

View File

@ -42,6 +42,8 @@
Command="{Binding FloatCommand}" />
<Button Content="参数"
Command="{Binding ParamModify}" />
<Button Content="参数文件"
Command="{Binding LoadParamfile}" />
</WrapPanel>
<WrapPanel>

View File

@ -66,7 +66,9 @@
<Button Content="清除"
Margin="5,0,5,0"
Command="{Binding ClearCoptersCommand}" />
<TextBlock Text="{Binding Path=Communinfo}"
Margin="5,5,0,0"/>
</StackPanel>
</Grid>