diff --git a/Plane.FormationCreator.sln b/Plane.FormationCreator.sln
index adcb603..902217f 100644
--- a/Plane.FormationCreator.sln
+++ b/Plane.FormationCreator.sln
@@ -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
diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs
index cc675a4..b0aa765 100644
--- a/Plane.FormationCreator/App.xaml.cs
+++ b/Plane.FormationCreator/App.xaml.cs
@@ -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)
{
diff --git a/Plane.FormationCreator/Formation/Copter.cs b/Plane.FormationCreator/Formation/Copter.cs
index 8ee4b29..cacb720 100644
--- a/Plane.FormationCreator/Formation/Copter.cs
+++ b/Plane.FormationCreator/Formation/Copter.cs
@@ -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()];
}
diff --git a/Plane.FormationCreator/Plane.FormationCreator.csproj b/Plane.FormationCreator/Plane.FormationCreator.csproj
index afcdca2..333062b 100644
--- a/Plane.FormationCreator/Plane.FormationCreator.csproj
+++ b/Plane.FormationCreator/Plane.FormationCreator.csproj
@@ -145,6 +145,7 @@
+
diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
index 312f20d..ef40b4f 100644
--- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
@@ -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();
diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
index 6d89ce6..909d6c8 100644
--- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
@@ -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
diff --git a/Plane.FormationCreator/Views/ControlPanelView.xaml b/Plane.FormationCreator/Views/ControlPanelView.xaml
index cdf738a..352967e 100644
--- a/Plane.FormationCreator/Views/ControlPanelView.xaml
+++ b/Plane.FormationCreator/Views/ControlPanelView.xaml
@@ -42,6 +42,8 @@
Command="{Binding FloatCommand}" />
+
diff --git a/Plane.FormationCreator/Views/CopterListView.xaml b/Plane.FormationCreator/Views/CopterListView.xaml
index 0faa079..7abe854 100644
--- a/Plane.FormationCreator/Views/CopterListView.xaml
+++ b/Plane.FormationCreator/Views/CopterListView.xaml
@@ -66,7 +66,9 @@
-
+
+