From 3aa48795118092af782488940e1c59eabdff7746 Mon Sep 17 00:00:00 2001 From: xu Date: Wed, 11 Mar 2020 15:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E4=BF=AE=E6=94=B9wifi?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=89=B9=E9=87=8F=E8=B5=B7=E9=A3=9E?= =?UTF-8?q?=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plane.FormationCreator/App.xaml.cs | 26 +++++++++++++------ .../Formation/CopterManager.cs | 14 ++++++++++ .../Formation/RtcmManager.cs | 9 ++++--- Plane.FormationCreator/MainWindow.xaml | 2 +- .../ViewModels/ControlPanelViewModel.cs | 7 +++++ .../ViewModels/CopterListViewModel.cs | 7 ++++- .../Views/CalibrationWindow.xaml | 2 +- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs index 88cc3ed..655c457 100644 --- a/Plane.FormationCreator/App.xaml.cs +++ b/Plane.FormationCreator/App.xaml.cs @@ -173,30 +173,40 @@ namespace Plane.FormationCreator { _logger.Log(e.Message ); } + //wifi模式添加飞机 private async Task AddOrUpdateCopter(string ip, IConnection Connection) { var copters = _copterManager.Copters; var copterStatus = _copterManager.CopterStatus; - var copter = copters.FirstOrDefault(c => c.Id == ip); + string[] iparr = ip.Split('.'); + string vIPID = String.Format("{0:D3}", int.Parse(iparr[2])) + String.Format("{0:D3}", int.Parse(iparr[3])); + + var copter = copters.FirstOrDefault(c => c.Id == vIPID); if (copter == null) { - await Dispatcher.BeginInvoke(new Action(() => + if (!_copterManager.EnAddCopter_Real()) { - if (_copterManager.EnAddCopter_Real()) + UdpServerConnectionManager.Instance.DeleteConnections(ip); + } + else + { + await Dispatcher.BeginInvoke(new Action(() => { + + copter = new Copter(Connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng) { - Id = ip, - Name = ip.Substring(ip.LastIndexOf('.') + 1) - + Id = vIPID, + Name = vIPID // ip.Substring(ip.LastIndexOf('.') + 1) }; int _index; _index = copters.AddCopter(copter); copterStatus.Insert(_index, false); copter.TextReceived += Copter_TextReceived; - } - })); + + })); + } } else { diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index f2d93ac..c770d27 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -591,6 +591,20 @@ namespace Plane.FormationCreator.Formation + public async Task ClearCopters() + { + foreach (var copter in Copters) + { + await copter.DisconnectAsync(); + } + await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 + Copters.Clear(); + CopterStatus.Clear(); + //wifi + if (VersionControl.ConType==1) + UdpServerConnectionManager.Instance.ClearConnections(); + } + public bool EnAddCopter_Real() { diff --git a/Plane.FormationCreator/Formation/RtcmManager.cs b/Plane.FormationCreator/Formation/RtcmManager.cs index b146fdc..99bd83b 100644 --- a/Plane.FormationCreator/Formation/RtcmManager.cs +++ b/Plane.FormationCreator/Formation/RtcmManager.cs @@ -27,7 +27,7 @@ namespace Plane.FormationCreator.Formation private CommModuleManager _commModuleManager = CommModuleManager.Instance; public ObservableCollection rtcmInfoList { get; } = new ObservableCollection(); private ControlPanelViewModel ControlPanelVM = ServiceLocator.Current.GetInstance(); - + private CopterManager _copterManager = ServiceLocator.Current.GetInstance(); private bool _rtcmthreadrun = false; public bool Rtcmthreadrun { @@ -310,10 +310,11 @@ namespace Plane.FormationCreator.Formation if ((seenmsg = rtcm.Read(buffer[a])) > 0) { bpsusefull += rtcm.length; - //用于双频RTK发送 - // await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length); + //用于双频RTK发送 + // await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length); //用于单频rtk发送 - await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length); + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); + await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length); string msgname = "Rtcm" + seenmsg; diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index 15b5073..a83b122 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -235,7 +235,7 @@ - diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index edcf281..eb72fb5 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -314,6 +314,7 @@ namespace Plane.FormationCreator.ViewModels { return _AllLandCommand ?? (_AllLandCommand = new RelayCommand(async () => { + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); await _commModuleManager.LandAsync(); /* await Task.WhenAll(_copterManager.Copters.Select(async c => @@ -409,6 +410,7 @@ namespace Plane.FormationCreator.ViewModels // await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync())); for (int i = 0; i < 3; i++) { + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); await _commModuleManager.UnlockAsync(); await Task.Delay(1000).ConfigureAwait(false); } @@ -536,6 +538,7 @@ namespace Plane.FormationCreator.ViewModels if (Alert.Show("您确定要上锁吗?飞行器将无视转速,立即强制停止运转!!!", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) { + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); await _commModuleManager.LockAsync(_copterManager.AcceptingControlCopters); //await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LockAsync())); } @@ -702,7 +705,10 @@ namespace Plane.FormationCreator.ViewModels if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count) num = await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters); else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count) + { + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); num = await _commModuleManager.SetParamAsync(paramstr, paramvalue); + } Alert.Show($"广播完成! 当前序列号:{num}"); } else @@ -896,6 +902,7 @@ namespace Plane.FormationCreator.ViewModels } */ //稳定方案的rtk发送,用于单频 + _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); await _commModuleManager.InjectGpsDataAsync(packet, (ushort)packet.Length); } await Task.Delay(10).ConfigureAwait(false); diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs index 135d5d9..db2d193 100644 --- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs +++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs @@ -441,6 +441,8 @@ namespace Plane.FormationCreator.ViewModels return _ClearCoptersCommand ?? (_ClearCoptersCommand = new RelayCommand(async () => { _flightTaskManager.Pause(); + await _copterManager.ClearCopters(); + /* foreach (var copter in _copterManager.Copters) { await copter.DisconnectAsync(); @@ -448,10 +450,13 @@ namespace Plane.FormationCreator.ViewModels await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 _copterManager.Copters.Clear(); _copterManager.CopterStatus.Clear(); + */ + _mapManager.ClearCopters(); _view3DManager.ClearCopters(); _flightTaskManager.ClearTasks(); - //UdpServerConnectionManager.Instance.ClearConnections(); + // UdpServerConnectionManager.Instance.ClearConnections(); + _virtualCopterId = 1; _lastVirtualCopterLocation = null; _flightTaskManager.OriginLat = 0; diff --git a/Plane.FormationCreator/Views/CalibrationWindow.xaml b/Plane.FormationCreator/Views/CalibrationWindow.xaml index 897162b..c6d3afc 100644 --- a/Plane.FormationCreator/Views/CalibrationWindow.xaml +++ b/Plane.FormationCreator/Views/CalibrationWindow.xaml @@ -30,7 +30,7 @@