From 3cdecf870387a06f3e1aa587ffe6f87f510fa54a Mon Sep 17 00:00:00 2001 From: zxd Date: Mon, 1 Jul 2019 21:45:44 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E9=80=9A=E4=BF=A1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E7=9A=84=E6=B7=BB=E5=8A=A0=E5=92=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9"=20=E6=8F=90=E4=BA=A4=E4=BA=86=E5=89=8D=E9=9D=A2?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9C=AAadd=E7=9A=84=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=8D=83=E5=AF=BBRtk=E5=8F=91?= =?UTF-8?q?=E9=80=81:NTRIP=20=E6=B7=BB=E5=8A=A0=E7=BC=BA=E5=8F=B7=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=20=E6=B7=BB=E5=8A=A0GPS=E7=B1=BB=E5=9E=8B=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=20=E9=99=90=E5=88=B6=E5=B0=8F=E6=AD=A6=E5=86=85?= =?UTF-8?q?=E8=92=99=E5=9C=B0=E5=8C=BA=E9=83=A8=E5=88=86=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8(=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=B7=B2=E6=B3=A8=E9=87=8A)=20This=20reverts=20commit=20725c4b?= =?UTF-8?q?6d718336630680f32040165ee19379bcbd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plane.FormationCreator/App.xaml.cs | 5 +- Plane.FormationCreator/Formation/Copter.cs | 2 + .../Formation/CopterManager.cs | 8 +- .../Formation/FlightTaskManager.cs | 12 +- .../Formation/FlightTask_FlyTo.cs | 11 +- .../Formation/GroupManager.cs | 174 ++ Plane.FormationCreator/MainWindow.xaml | 4 +- .../Plane.FormationCreator.csproj | 3 + Plane.FormationCreator/Util/CommNTRIP.cs | 277 ++ Plane.FormationCreator/Util/ICorrections.cs | 24 + Plane.FormationCreator/Util/rtcm3.cs | 2283 +++++++++++++++++ .../ViewModels/ConnectViewModel.cs | 74 +- .../ViewModels/ControlPanelViewModel.cs | 126 +- .../ViewModels/CopterListViewModel.cs | 39 + .../ViewModels/GroupsViewModel.cs | 26 + .../Views/ConnectWindow.xaml | 34 +- .../Views/ControlPanelView.xaml | 20 +- .../Views/CopterAttributeView.xaml | 32 + .../Views/CopterAttributeView.xaml.cs | 31 + .../Views/CopterGroupsView.xaml | 61 + .../Views/CopterGroupsView.xaml.cs | 32 + .../Views/CopterListView.xaml | 5 +- .../Views/ModifyTaskView.xaml | 4 +- 23 files changed, 3134 insertions(+), 153 deletions(-) create mode 100644 Plane.FormationCreator/Formation/GroupManager.cs create mode 100644 Plane.FormationCreator/Util/CommNTRIP.cs create mode 100644 Plane.FormationCreator/Util/ICorrections.cs create mode 100644 Plane.FormationCreator/Util/rtcm3.cs create mode 100644 Plane.FormationCreator/ViewModels/GroupsViewModel.cs create mode 100644 Plane.FormationCreator/Views/CopterAttributeView.xaml create mode 100644 Plane.FormationCreator/Views/CopterAttributeView.xaml.cs create mode 100644 Plane.FormationCreator/Views/CopterGroupsView.xaml create mode 100644 Plane.FormationCreator/Views/CopterGroupsView.xaml.cs diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs index 996f9f2..1682c13 100644 --- a/Plane.FormationCreator/App.xaml.cs +++ b/Plane.FormationCreator/App.xaml.cs @@ -140,13 +140,12 @@ namespace Plane.FormationCreator UdpServerConnectionManager.Instance.StartReceiving(); */ + //初始化地面站连接 CommModuleManager.Instance.CommunicationReceived += CommtionReceivedCopterInfo; CommModuleManager.Instance.CommunicationCopterDisconnect += CommCopterDisconnect; CommModuleManager.Instance.CommunicationConnected += CommCopterconnected; - - CommModuleManager.Instance.Connect(); - //CommModuleManager.Instance.test(); + } catch (Exception ex) { diff --git a/Plane.FormationCreator/Formation/Copter.cs b/Plane.FormationCreator/Formation/Copter.cs index 8c8d5be..c16fd4e 100644 --- a/Plane.FormationCreator/Formation/Copter.cs +++ b/Plane.FormationCreator/Formation/Copter.cs @@ -23,6 +23,8 @@ namespace Plane.FormationCreator.Formation Brush = _brushes[NextBrushIndex()]; RecordLat = lat; RecordLng = lng; + Latitude = lat; + Longitude = lng; //RaiseLocationChangedIfNeeded(); } diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index 2c9c860..474ce82 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -20,9 +20,13 @@ namespace Plane.FormationCreator.Formation /// public int AddCopter(ICopter entityObject) { - ////给第三方时候限制数量和时间用 - DateTime dateTime2019 = DateTime.Parse("2019-06-20"); + DateTime dateTime2019 = DateTime.Parse("2019-09-20"); + + //新增飞机区域限制:内蒙 +// if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756 +// || entityObject.Longitude < 97.3493089056 || entityObject.Longitude > 115.8006783856) +// return 0; if (DateTime.UtcNow > dateTime2019) { diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 6787b79..9042eb9 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -1374,13 +1374,19 @@ namespace Plane.FormationCreator.Formation } } + TimeSpan timeSpan; + DateTime taskStartTime; public async Task RunTaskAsync() - { - Message.Show("任务开始"); + taskStartTime = DateTime.Now; + Message.Show($"{DateTime.Now.ToString("HH:mm:ss")}:任务开始"); await RunAsync(); if ((IsPaused ?? false) == false) - Message.Show("任务完成"); + { + timeSpan = DateTime.Now - taskStartTime; + Message.Show($"{DateTime.Now.ToString("HH:mm:ss")}:任务完成"); + Message.Show($"总时长 = {timeSpan.Minutes}分{timeSpan.Seconds}秒"); + } } public async Task RunAsync() diff --git a/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs b/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs index ecd4079..fc01eb5 100644 --- a/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs +++ b/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs @@ -169,7 +169,7 @@ namespace Plane.FormationCreator.Formation if (prevTask.TaskType == FlightTaskType.FlyTo && prevTask.LoiterTime == 0) flyToTime += prevTask.RuningTaskRemaining; } - int LEDIndex = 0; + //while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 :所有Copter到达目标点开始飞下个航点 while (ts.TotalMilliseconds < (flyToTime + loiterTime)) //按时间轴飞:当前任务时间到达后自动飞往下个航点 { @@ -212,21 +212,20 @@ namespace Plane.FormationCreator.Formation double time = 0; for (int i = 0; i < LedControl.Count; i++) { + var led = LedControl[i]; time += led.Delay * 1000; if (ts.TotalMilliseconds >= time) - { LEDRGB = info.LEDInfos[i].LEDRGB; - LEDIndex = i; - - } else break; } - Message.Show(LEDIndex.ToString()); info.Copter.LEDColor = LEDRGB; + } + + if (ts.TotalMilliseconds / 10 > sendFlyToTimes) // 每500ms发送一遍指点坐标 { sendFlyToTimes++; diff --git a/Plane.FormationCreator/Formation/GroupManager.cs b/Plane.FormationCreator/Formation/GroupManager.cs new file mode 100644 index 0000000..b1e10e1 --- /dev/null +++ b/Plane.FormationCreator/Formation/GroupManager.cs @@ -0,0 +1,174 @@ +using Plane.Copters; +using GalaSoft.MvvmLight; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plane.FormationCreator.Util; +using System.Windows.Input; +using GalaSoft.MvvmLight.Command; +using Microsoft.Practices.ServiceLocation; + +namespace Plane.FormationCreator.Formation +{ + public class GroupManager: ObservableObject + { + public ObservableCollection copterGroups { get; } = new ObservableCollection(); + private CopterManager _copterManager = ServiceLocator.Current.GetInstance(); + private string _LastSelectedGroup; + public string LastSelectedGroup + { + get { return _LastSelectedGroup; } + set { Set(nameof(LastSelectedGroup), ref _LastSelectedGroup, value); } + } + public GroupManager() + { + } + + public void AddGroup(string name = "") + { + CopterGroup group = new CopterGroup(name); + copterGroups.Add(group); + group.RemoveGroupEvent += new CopterGroup.RemoveGroupEventHandler(GroupRemove); + group.SelectedGroupEvent += new CopterGroup.SelectedGroupEventHandler(SelectedGroup); + } + + public void SelectedGroup(object sender) + { + CopterGroup groups = sender as CopterGroup; + LastSelectedGroup = groups.groupName; + } + + public void GroupRemove(object sender) + { + CopterGroup groups = sender as CopterGroup; + copterGroups.Remove(groups); + } + + + public IEnumerable ExportGroups() + { + return copterGroups; + } + + public void ImportGroupsInfo(dynamic groupsInfo) + { + copterGroups.Clear(); + foreach (var group in groupsInfo) + { + string name = group.groupName; + CopterGroup copterGroup = new CopterGroup(name); + foreach (var index in group.copterIndexList) + { + copterGroup.copterIndexList.Add(Convert.ToInt32(index)); + } + copterGroups.Add(copterGroup); + copterGroup.RemoveGroupEvent += new CopterGroup.RemoveGroupEventHandler(GroupRemove); + copterGroup.SelectedGroupEvent += new CopterGroup.SelectedGroupEventHandler(SelectedGroup); + } + } + + + private ICommand _AddGroupsCommand; + public ICommand AddGroupsCommand + { + get + { + return _AddGroupsCommand ?? (_AddGroupsCommand = new RelayCommand(async => + { + AddGroup(); + })); + } + } + + + + } + + public class CopterGroup : ObservableObject + { + private CopterManager _copterManager = ServiceLocator.Current.GetInstance(); + public CopterGroup(string name = "") + { + groupName = name != "" ? name : "新分组"; + + } + public string groupName { get; set; } + public List copterIndexList { get; } = new List(); + + public delegate void RemoveGroupEventHandler(object sender); + public event RemoveGroupEventHandler RemoveGroupEvent; + private ICommand _RemoveGroupCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand RemoveGroupCommand + { + get + { + return _RemoveGroupCommand ?? (_RemoveGroupCommand = new RelayCommand(async => + { + RemoveGroupEvent(this); + })); + } + } + + + public delegate void SelectedGroupEventHandler(object sender); + public event SelectedGroupEventHandler SelectedGroupEvent; + private ICommand _SelectCoptersCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand SelectCoptersCommand + { + get + { + return _SelectCoptersCommand ?? (_SelectCoptersCommand = new RelayCommand(async => + { + _copterManager.Select(null); + _copterManager.shiftkeydown = true; + foreach (var copterIndex in copterIndexList) + { + //if (_copterManager.Copters.Count > copterIndex) + // { + //_copterManager.Select(_copterManager.Copters[copterIndex]); + ICopter copter = null; +// try +// { +// copter = _copterManager.Copters.First(o => o.Name == (copterIndex + 1).ToString()); +// } +// catch (Exception) +// { +// continue; +// } + copter = _copterManager.Copters.FirstOrDefault(o => o.Name == (copterIndex + 1).ToString()); + if (copter != null) + { + _copterManager.Select(copter); + } + //} + } + _copterManager.shiftkeydown = false; + SelectedGroupEvent(this); + })); + } + } + + private ICommand _SetGroupCoptersCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand SetGroupCoptersCommand + { + get + { + return _SetGroupCoptersCommand ?? (_SetGroupCoptersCommand = new RelayCommand(async => + { + copterIndexList.Clear(); + foreach (var copter in _copterManager.SelectedCopters) + { + copterIndexList.Add(_copterManager.Copters.IndexOf(copter)); + } + })); + } + } + } +} diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index f3618a1..99688e1 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -92,7 +92,7 @@