From 09da3f24baa5d91998069ab2da0125fa8e294675 Mon Sep 17 00:00:00 2001 From: xu Date: Mon, 27 Dec 2021 12:39:28 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E5=8A=A0=E5=85=A5=E5=9B=9E=E4=BC=A0?= =?UTF-8?q?=E5=8A=9F=E7=8E=87=E8=AE=BE=E7=BD=AE=EF=BC=8C=E5=9C=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=AA=97=E5=8F=A3=E9=87=8C=E9=9D=A2=202.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=88=A0=E9=99=A4=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E9=A3=9E=E6=9C=BA=203.=20=E5=8F=91=E9=80=81=E8=B5=B7=E9=A3=9E?= =?UTF-8?q?=E4=BB=8E10=E6=AC=A1=E5=8F=98=E4=B8=BA20=E6=AC=A1=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=204.=E5=8A=A0=E5=85=A5256=E4=B8=AA=E8=88=AA=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E4=BB=BB=E5=8A=A1=E9=99=90=E5=88=B6=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=205.=E5=8A=A0=E5=85=A5=E8=AE=A1=E7=AE=97=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=95=B0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/CopterManager.cs | 38 ++++- .../Formation/FlightTaskManager.cs | 2 +- .../Formation/GroupManager.cs | 19 ++- Plane.FormationCreator/MainWindow.xaml | 4 +- .../ViewModels/ConnectViewModel.cs | 14 ++ .../ViewModels/ControlPanelViewModel.cs | 155 ++++++++++++------ .../ViewModels/ModifyTaskViewModel.cs | 80 +++++++++ .../Views/ConnectWindow.xaml | 3 +- .../Views/ControlPanelView.xaml | 14 +- .../Views/CopterListView.xaml.cs | 47 ++++-- .../Views/ModifyTaskView.xaml | 7 +- 11 files changed, 304 insertions(+), 79 deletions(-) diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index ea79b06..3f220cf 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -25,7 +25,7 @@ namespace Plane.FormationCreator.Formation public class CopterCollection : ObservableCollection { //软件过期时间---过期将无法添加飞机,并自动退出 - public static DateTime Expire_App = DateTime.Parse("2022-06-10"); + public static DateTime Expire_App = DateTime.Parse("2022-12-31"); //超级用户过期时间--过期将无法使用内置超级用户登录 public static DateTime Expire_SuperUser = Expire_App; //允许飞行的飞机数量 @@ -627,7 +627,9 @@ namespace Plane.FormationCreator.Formation if ((username== supername) && (password== superpass) &&(DateTime.UtcNow < CopterCollection.Expire_SuperUser) ) { - NetLogined(supername, superDispname, -1, -1, LEVEL_ADMIN); + // NetLogined(supername, superDispname, -1, -1, LEVEL_ADMIN); + NetLogined(supername, superDispname,6, 50, LEVEL_NORMAL); + VersionControl.SaveLogininfoToIni(supername, superpass, savepassword); //超级密码是否保存---不要就不保存 return; } @@ -776,6 +778,38 @@ namespace Plane.FormationCreator.Formation } + + public async Task DelSelCopters() + { + if (AcceptingControlCopters == null || AcceptingControlCopters.Count() ==0) + { + return; + } + + foreach (var copter in AcceptingControlCopters) + { + await copter.DisconnectAsync(); + + if(Copters.Contains(copter)) + { + Copters.Remove(copter); + } + + //标记是否跳过,这个已经没用了,随便删除第一个 + CopterStatus.RemoveAt(0); + + + } + await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 + + //wifi + // if (VersionControl.ConType == 1) + // UdpServerConnectionManager.Instance.ClearConnections(); + } + + + + public bool EnAddCopter_Real() { if (EnCopterNumber == -1) return true; diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index db2e67b..735ac5a 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -222,7 +222,7 @@ namespace Plane.FormationCreator.Formation { str = ts.Seconds + "秒"; } - Message.ShowStatus($"选中 [{value.TaskIndex+1} {value.TaskCnName }] 从{str}开始执行,需{ GetTaskTime(value.TaskIndex)}秒"); + Message.ShowStatus($"选中 [{value.TaskIndex+1} {value.TaskCnName }] 从{str}开始执行,需{ GetTaskTime(value.TaskIndex)}秒,共{Tasks.Count}个任务"); } else Message.ShowStatus($"无任务选中"); diff --git a/Plane.FormationCreator/Formation/GroupManager.cs b/Plane.FormationCreator/Formation/GroupManager.cs index b1e10e1..d8c3031 100644 --- a/Plane.FormationCreator/Formation/GroupManager.cs +++ b/Plane.FormationCreator/Formation/GroupManager.cs @@ -133,15 +133,16 @@ namespace Plane.FormationCreator.Formation // { //_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()); + // try + // { + // copter = _copterManager.Copters.First(o => o.Name == (copterIndex + 1).ToString()); + // } + // catch (Exception) + // { + // continue; + // } + string strcoptername = _copterManager.Copters[copterIndex].Name; + copter = _copterManager.Copters.FirstOrDefault(o => o.Name == strcoptername); if (copter != null) { _copterManager.Select(copter); diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index 8985dc8..59ce667 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -273,8 +273,10 @@ - + + diff --git a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs index f0f7e4f..76188eb 100644 --- a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs @@ -256,6 +256,20 @@ namespace Plane.FormationCreator.ViewModels } + private ICommand _SetModulePowerCommand; + public ICommand SetModulePowerCommand + { + get + { + return _SetModulePowerCommand ?? (_SetModulePowerCommand = new RelayCommand(async () => + { + int mPower = int.Parse(CopterColor); + await commModule.SetModulePower((short)CopterNum, (short)mPower); + })); + } + } + + private ICommand _CommDataAsync; public ICommand CommDataAsync diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index 413bce0..ed8b4b9 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -126,54 +126,69 @@ namespace Plane.FormationCreator.ViewModels minVol = float.Parse(inputDialog.Answer); else return; - //测试电池 - await _commModuleManager.TestBattery((short)0, minVol); - if (minVol == 0.0) return; - Message.Show("---请检查飞机灯光---"); - Message.Show(string.Format("---绿 色 电压高于 {0:F2}v (单节高于 {1:F2}v)--- ", minVol , minVol / 4.0f)); - Message.Show(string.Format("---黄 色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol , minVol / 4.0f)); - Message.Show(string.Format("---棕 色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.2, (minVol - 0.2) / 4.0f)); - Message.Show(string.Format("---洋红色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.4, (minVol - 0.4) / 4.0f)); - Message.Show(string.Format("---亮红色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.6, (minVol - 0.6) / 4.0f)); - Message.Show("---输入0恢复灯光---"); + //测试电池 + await _commModuleManager.TestBattery((short)0, minVol); + if (minVol == 0.0) return; + Message.Show("---请检查飞机灯光---"); + Message.Show(string.Format("---绿 色 电压高于 {0:F2}v (单节高于 {1:F2}v)--- ", minVol, minVol / 4.0f)); + Message.Show(string.Format("---黄 色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol, minVol / 4.0f)); + Message.Show(string.Format("---棕 色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.2, (minVol - 0.2) / 4.0f)); + Message.Show(string.Format("---洋红色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.4, (minVol - 0.4) / 4.0f)); + Message.Show(string.Format("---亮红色 电压低于 {0:F2}v (单节低于 {1:F2}v)--- ", minVol - 0.6, (minVol - 0.6) / 4.0f)); + Message.Show("---输入0恢复灯光---"); - Message.Show("--------------开始检测单机电压--------------"); - Dictionary dic_voltage = new Dictionary(); - await Task.WhenAll(_copterManager.Copters.Select(async c => - { - float voltageSum = 0.0f; - string name = c.Name; - - for (int i = 0; i < 5; i++) + Message.Show("--------------开始检测单机电压--------------"); + Dictionary dic_voltage = new Dictionary(); + await Task.WhenAll(_copterManager.Copters.Select(async c => { - - voltageSum += c.Voltage; - await Task.Delay(1000).ConfigureAwait(false); - } - float voltageAverage = voltageSum / 5; - if (name != null && name != "") - { - lock(locker) + float voltageSum = 0.0f; + string name = c.Name; + + for (int i = 0; i < 5; i++) { - dic_voltage.Add(name, voltageAverage); + + voltageSum += c.Voltage; + await Task.Delay(1000).ConfigureAwait(false); } - } - })).ConfigureAwait(false); - await Task.Run(async () => { + float voltageAverage = voltageSum / 5; + if (name != null && name != "") + { + lock (locker) + { + dic_voltage.Add(name, voltageAverage); + } + } + })).ConfigureAwait(false); + + Dictionary dic_voltage_Order = dic_voltage.OrderByDescending(o => o.Value).ToDictionary(o => o.Key, o => o.Value); - bool showch = false; + bool showch = false; + ICopter vcopter = null; + _copterManager.shiftkeydown = true; + //清除选择 + _copterManager.Select(null); foreach (KeyValuePair kv in dic_voltage_Order) { - if ((!showch) &&(minVol>0.00) && (kv.Value<=minVol)) + if ((!showch) && (minVol > 0.00) && (kv.Value <= minVol)) { - Message.Show(string.Format("以下飞机电压低于[{0}V,单节{1:F2}]", minVol, minVol/4)); + Message.Show(string.Format("以下飞机电压低于[{0}V,单节{1:F2}]", minVol, minVol / 4)); showch = true; } - Message.Show(string.Format("{0} --> 5秒平均电压:{1:F2},单节{2:F2}", kv.Key, kv.Value, kv.Value/4)); + Message.Show(string.Format("{0} --> 5秒平均电压:{1:F2},单节{2:F2}", kv.Key, kv.Value, kv.Value / 4)); + + + //选中低电压飞机 + if ((minVol > 0.00) && (kv.Value <= minVol)) + { + vcopter = _copterManager.Copters.FirstOrDefault(o => o.Name == kv.Key); + if (vcopter != null) + _copterManager.Select(vcopter); //需要访问UI线程 + } await Task.Delay(5).ConfigureAwait(false); } + await Task.Delay(500).ConfigureAwait(false); + _copterManager.shiftkeydown = false; Message.Show(string.Format("----检测电压完成,检测总数:{0}----", dic_voltage.Count)); - }).ConfigureAwait(false); //todo:增加电压阈值变成不同颜色灯 })); } @@ -390,6 +405,30 @@ namespace Plane.FormationCreator.ViewModels } } + + private ICommand _DelCommand; + public ICommand DelCommand + { + get + { + return _DelCommand ?? (_DelCommand = new RelayCommand(async () => + { + FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance(); + if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0) + { + if (_flightTaskManager.Tasks.Count > 0) + { + Alert.Show("有航点任务无法删除飞机,请先清除航点!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + await _copterManager.DelSelCopters(); + } + })); + } + } + + private ICommand _MotorTestCommand; public ICommand MotorTestCommand { @@ -616,8 +655,11 @@ namespace Plane.FormationCreator.ViewModels DateTime MissionTime = DateTime.UtcNow.AddSeconds(5); DateTime MissionTime_log = DateTime.Now.AddSeconds(5); Message.Show("任务开始:" + MissionTime_log.ToString()); + + IEnumerable selcopters = _copterManager.AcceptingControlCopters; + //循环3次 发送起飞命令 避免通信问题 - for (int i = 0; i < 10; i++) + for (int i = 0; i < 20; i++) { /*await _commModuleManager.DoMissionStartAsync(_copterManager.Copters, @@ -630,7 +672,7 @@ namespace Plane.FormationCreator.ViewModels */ - await _commModuleManager.DoMissionStartAsync(_copterManager.AcceptingControlCopters, + await _commModuleManager.DoMissionStartAsync(selcopters, MissionTime.Hour, MissionTime.Minute, MissionTime.Second, @@ -650,17 +692,25 @@ namespace Plane.FormationCreator.ViewModels */ - await Task.Delay(10).ConfigureAwait(false); + await Task.Delay(20).ConfigureAwait(false); } //_copterManager.Net_LogStartMission(MissionTime_log, _flightTaskManager.OriginLng, _flightTaskManager.OriginLat); Alert.Show("所有选中飞机开始执行航点任务。请勿多次开始任务!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + })); + } + } - - - - - + private ICommand _ThrowoutCommand; + public ICommand ThrowoutCommand + { + get + { + return _ThrowoutCommand ?? (_ThrowoutCommand = new RelayCommand( () => + { + // await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync())); + if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0) + _commModuleManager.ThrowoutAsync(_copterManager.AcceptingControlCopters); })); } } @@ -1346,9 +1396,9 @@ namespace Plane.FormationCreator.ViewModels DateTime MissionTime_log = DateTime.Now.AddSeconds(5); Message.Show("任务开始:" + MissionTime_log.ToString()); //循环3次 发送起飞命令 避免通信问题 - for (int i = 0; i < 10; i++) + for (int i = 0; i < 20; i++) { - await _commModuleManager.DoMissionStartAsync(_copterManager.Copters, + await _commModuleManager.DoMissionStartAsync(null, MissionTime.Hour, MissionTime.Minute, MissionTime.Second, @@ -1368,7 +1418,7 @@ namespace Plane.FormationCreator.ViewModels } */ - await Task.Delay(10).ConfigureAwait(false); + await Task.Delay(20).ConfigureAwait(false); } _copterManager.Net_LogStartMission(MissionTime_log, _flightTaskManager.OriginLng, _flightTaskManager.OriginLat); @@ -1532,7 +1582,7 @@ namespace Plane.FormationCreator.ViewModels } } - /// + /// /// 用通讯模块 写入航点信息 /// /// copterIndex @@ -1612,11 +1662,18 @@ namespace Plane.FormationCreator.ViewModels //_commModuleManager.missionWriteState.Add(int.Parse(_copterManager.Copters[i].Id), state); if (!result) { - Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输失败!"); + + if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) + Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输失败!"); + else + Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输失败!"); } else { - Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输完成!"); + if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) + Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输完成!"); + else + Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输完成!"); } await Task.Delay(500).ConfigureAwait(false); } diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index 464fd89..57592aa 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -401,6 +401,86 @@ namespace Plane.FormationCreator.ViewModels })); } } + private void GetMaxMissions() + { + int missiontmp = 0; + + string maxCopterName = ""; + int maxmission = 0; + string minCopterName = ""; + int minmission = 65535; + + ICopter vcopter = _copterManager.SelectedCopters.FirstOrDefault(); + if (vcopter == null) + { + Alert.Show($"请先选中飞机!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + + + int coptercount = _copterManager.Copters.Count; + + + for (int i = 0; i < coptercount; i++) + { + missiontmp = 0; + + var currcopter = _copterManager.Copters[i]; + + foreach (var capter in _copterManager.SelectedCopters) + { + if (currcopter == capter) + { + for (int j = 0; j < _flightTaskManager.Tasks.Count; j++) + { + missiontmp++; + missiontmp += _flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos.Count(); + } + + if (missiontmp > maxmission) + { + maxCopterName = _copterManager.Copters[i].Name; + maxmission = missiontmp; + } + + if (missiontmp < minmission) + { + minCopterName = _copterManager.Copters[i].Name; + minmission = missiontmp; + } + + } + + } + + + + + + } + if (maxmission>256) + Alert.Show($"飞机:[ {maxCopterName} ] 有最多任务数量:{maxmission} 已超出256的最大航点限制,请减少灯光; \n飞机:[ {minCopterName} ] 有最少任务数量:{minmission}", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + else + Alert.Show($"飞机:[ {maxCopterName} ] 有最多任务数量:{maxmission} \n飞机:[ {minCopterName} ] 有最少任务数量:{minmission} \n (航点加灯光不能超过256个任务)", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return ; + } + + private ICommand _CheckMissionCountCommand; + public ICommand CheckMissionCountCommand + + { + get + { + return _CheckMissionCountCommand ?? (_CheckMissionCountCommand = new RelayCommand(async => + { + GetMaxMissions(); + + })); + } + } + + + //调整所有任务经度 private ICommand _ModiAllPosCommand; public ICommand ModiAllPosCommand diff --git a/Plane.FormationCreator/Views/ConnectWindow.xaml b/Plane.FormationCreator/Views/ConnectWindow.xaml index 78fa6a8..4dbef57 100644 --- a/Plane.FormationCreator/Views/ConnectWindow.xaml +++ b/Plane.FormationCreator/Views/ConnectWindow.xaml @@ -8,7 +8,7 @@ xmlns:ec="clr-namespace:Plane.Windows.Controls;assembly=Plane.Windows" mc:Ignorable="d" Title="" - Width="500" + Width="565.58" Height="325.107" WindowStartupLocation="CenterScreen" @@ -48,6 +48,7 @@