diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index 3f220cf..2771ab0 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -181,8 +181,11 @@ namespace Plane.FormationCreator.Formation { const string LoginPage = "checkforapp.php"; - const string supername = "admin"; - const string superpass = "admin0622"; + // const string supername = "admin"; + // const string superpass = "admin0622"; + const string supername = "user"; + const string superpass = "123456"; + const string TEMP_MISSIONFILE = @".\gcs.dat"; //飞控版本控制 public int FC_VER_NO = 1;//"4.1.2" 这个版本以前版本灯光比较少no=1 //"4.5"以后no=2; diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 735ac5a..f4e5352 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -222,6 +222,23 @@ namespace Plane.FormationCreator.Formation { str = ts.Seconds + "秒"; } + + if (value.ModifyingSingleCopterInfo == null) + { + var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); + + foreach (var info in value.SingleCopterInfos) + { + if (info.Copter == selectedCopter) + { + value.ModifyingSingleCopterInfo = info; + break; + } + } + + } + + Message.ShowStatus($"选中 [{value.TaskIndex+1} {value.TaskCnName }] 从{str}开始执行,需{ GetTaskTime(value.TaskIndex)}秒,共{Tasks.Count}个任务"); } else Message.ShowStatus($"无任务选中"); @@ -1500,7 +1517,11 @@ namespace Plane.FormationCreator.Formation } public void SetAllTaskFlytime() { - for (int taskIndex = 1; taskIndex < Tasks.Count; taskIndex++) + //起飞航点0需要单独计算 + //第一个航点1,是调整航点根据地面摆放情况调整,默认2+1秒 + //从2开始自动计算 + Tasks[1].FlytoTime = 2; + for (int taskIndex = 2; taskIndex < Tasks.Count; taskIndex++) SetTaskFlytime(taskIndex); } @@ -2253,6 +2274,20 @@ namespace Plane.FormationCreator.Formation public async Task RunTaskAsync() { if (Tasks.Count == 0) return; + + //检查有没有真实飞机--真实飞机不能模拟,因为位置来自物理飞机--只能全部是模拟飞机才行 + foreach (var copter in _copterManager.Copters) + { + if (!(copter is IFakeCopter)) + { + Alert.Show($"模拟任务需要全部是模拟飞机,编号:{copter.Id } 不是模拟飞机,请检查"); + return ; + } + + } + + + if (CurrentRunningTaskIndex == 0) { taskStartTime = DateTime.Now; diff --git a/Plane.FormationCreator/Formation/RtcmManager.cs b/Plane.FormationCreator/Formation/RtcmManager.cs index c25d0dd..2c3f042 100644 --- a/Plane.FormationCreator/Formation/RtcmManager.cs +++ b/Plane.FormationCreator/Formation/RtcmManager.cs @@ -319,11 +319,36 @@ namespace Plane.FormationCreator.Formation } + private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + public static long CurrentTimeMillis() + { + return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; + } + private async Task RtcmLoop() { int reconnecttimeout = 10; DateTime lastrecv = DateTime.MinValue; + //系统毫秒数 + long ls_send_ms = CurrentTimeMillis(); + + long ls_send_gps = CurrentTimeMillis(); + long ls_send_glonass = CurrentTimeMillis(); + long ls_send_baidu = CurrentTimeMillis(); + + const int MSG_GPS = 1074; + const int MSG_GLONASS = 1084; + const int MSG_Beidou = 1124; + + int MSG_BasePos = 1005; + int MSG_REV = 1033; + + int Send_type = 0; + bool Ensend = false; + int last_mag = 0; + //新版本打包发送模式 //await _commModuleManager.StartRtcmLoop(); @@ -356,8 +381,8 @@ namespace Plane.FormationCreator.Formation } //rtcm size=180 - byte[] buffer = new byte[180]; - + byte[] buffer = new byte[180];// new byte[180]; + //一次读取180个字节 int read = comPort.Read(buffer, 0, Math.Min(buffer.Length, comPort.BytesToRead)); if (read > 0) lastrecv = DateTime.Now; @@ -366,15 +391,57 @@ namespace Plane.FormationCreator.Formation for (int a = 0; a < read; a++) { int seenmsg = -1; - // rtcm + // rtcm类解析RTCM数据 如果 rtcm.Read>0解析成功返回消息号码-1解析失败 if ((seenmsg = rtcm.Read(buffer[a])) > 0) { bpsusefull += rtcm.length; _commModuleManager.SetAllCoptersForWifi(_copterManager.Copters); - //用于双频RTK发送 - await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length); +/* 在数据量大的时候这样可以减少数据量,但测试结果是老方法更可靠,固定更快,特别是使用物理基站时 + switch (seenmsg) + { + case MSG_GPS: + if ((CurrentTimeMillis() - ls_send_gps) > 1000) + { + ls_send_gps = CurrentTimeMillis(); + Ensend = true; + } + break; + + case MSG_GLONASS: + if ((CurrentTimeMillis() - ls_send_glonass) > 1000) + { + ls_send_glonass = CurrentTimeMillis(); + Ensend = true; + } + break; + case MSG_Beidou: + if ((CurrentTimeMillis() - ls_send_baidu) > 1000) + { + ls_send_baidu = CurrentTimeMillis(); + Ensend = true; + } + break; + } + + if ((seenmsg == MSG_REV) || (seenmsg == MSG_BasePos)) Ensend = true; + + //Plane.Windows.Messages.Message.Show("---["+ seenmsg + "]RTCM:" + rtcm.length); + + // await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length); + /* if (rtcm.length <= 180) + Ensend = true; + else Ensend = false; + */ + if (Ensend) + { + // await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length); + + Ensend = false; + + } + */ //老的单频rtk发送 - //await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length); + await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length); string msgname = "Rtcm" + seenmsg; diff --git a/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs b/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs index f5f9e91..12ae6f1 100644 --- a/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs @@ -166,14 +166,20 @@ namespace Plane.FormationCreator.ViewModels float StepDis_Row = _flightTaskManager.ColumnDistance; //行内间距-列间距 float StepDis_Col = _flightTaskManager.RowDistance ; //列间距-行间距 float FindDis =Math.Min(StepDis_Row, StepDis_Col)*0.8f; //查找半径 + //如果选中的飞机总数大于2--需要2-3架用来确认行列方向,只有一行飞机就选2架,多行需要3架 if (_copterManager.AcceptingControlCopters.Count() >= 2) { var copters = _copterManager.AcceptingControlCopters.ToList(); var firstCopter = copters[0]; var secondCopter = copters[1]; ICopter thirdCopter=null; - if (_copterManager.AcceptingControlCopters.Count()>2) + if (_copterManager.AcceptingControlCopters.Count() > 2) + { thirdCopter = copters[2]; + Message.Show($"选中了3架飞机,将自动查找所有行列的飞机"); + } + else + Message.Show($"选中了2架飞机,将查找一行飞机"); //行角度(1,2) 用于查找每行的飞机位置 @@ -185,22 +191,37 @@ namespace Plane.FormationCreator.ViewModels ICopter FindedCopter = firstCopter; ICopter LastCopter = firstCopter; ILocation2D LastRowHewadCopter = firstCopter; - + + Message.Show($"开始查找飞机:行角度{RowDirect},列角度{ColDirect},列间距{StepDis_Row},行间距{StepDis_Col},查找半径{FindDis}米..."); + firstCopter.VirtualId = 1; + int rowindex = 1; while (FindedCopter!=null) { //按一行找飞机 FindedCopter = FindNextCopter(LastCopter, RowDirect, StepDis_Row, FindDis); //一行找不到了 找下一行的前3架飞机 - if ((FindedCopter == null)&&(thirdCopter!=null)) - FindedCopter = FindNextColHeadCopter(out LastRowHewadCopter,LastRowHewadCopter, ColDirect, StepDis_Col, RowDirect, StepDis_Row, 3, FindDis); - //如果找到了分配ID + if ((FindedCopter == null) && (thirdCopter != null)) + { + rowindex++; + FindedCopter = FindNextColHeadCopter(out LastRowHewadCopter, LastRowHewadCopter, ColDirect, StepDis_Col, RowDirect, StepDis_Row, 3, FindDis); + if (FindedCopter != null) + Message.Show($"开始第{rowindex}行--找到飞机"); + else + Message.Show($"开始第{rowindex}行--无飞机"); + } + //如果找到了分配ID if (FindedCopter != null) { FindedCopter.VirtualId = GetVID(LastCopter.VirtualId); - Message.Show($"分配飞机VID:{FindedCopter.VirtualId}"); + // Message.Show($"分配ID={FindedCopter.Id}飞机VID:={FindedCopter.VirtualId}"); LastCopter = FindedCopter; - } + }else + { + + Message.Show($"未找到飞机,自动分配结束"); + + } } } _copterManager.ReSort(); diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index ed8b4b9..037978c 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -257,7 +257,7 @@ namespace Plane.FormationCreator.ViewModels Array.Reverse(test); string data = string.Join(".", test); string copters = string.Join(",", kv.Value.ToArray()); - Message.Show(string.Format("返回数据{0}:{1}", data, copters)); + Message.Show(string.Format("返回数据{0}({1}):{2}", data, kv.Key,copters)); await Task.Delay(5).ConfigureAwait(false); } Message.Show("----统计完成----"); @@ -314,8 +314,10 @@ namespace Plane.FormationCreator.ViewModels Message.Show($"------------"); } Message.Show($"==机头方向=="); + //从小到大排个序 + Dictionary> SortedHeading = Heading.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value); - foreach (var item in Heading) + foreach (var item in SortedHeading) { Message.Show($"{item.Key} 度:{string.Join(",", item.Value)}"); Message.Show($"------------"); @@ -770,7 +772,18 @@ namespace Plane.FormationCreator.ViewModels })); } } - + private ICommand _GetCommsumCommand; + public ICommand GetCommsumCommand + { + get + { + return _GetCommsumCommand ?? (_GetCommsumCommand = new RelayCommand(async () => + { + //if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0) + await _commModuleManager.GetCommsumAsync(); + })); + } + } //打开校准界面 private ICommand _CalibrationSingleCommand; public ICommand CalibrationSingleCommand @@ -1690,25 +1703,33 @@ namespace Plane.FormationCreator.ViewModels foreach (LEDInfo ledInfo in LEDInfos) { float ledinterval=0; - //拉烟的ID 老版本只有8种,新固件增加了 - int fireno = 8; Color color = (Color)ColorConverter.ConvertFromString("#" + ledInfo.LEDRGB); int ledMode = ledInfo.LEDMode; //拉烟任务模式ID是50,需要改为50 if (_copterManager.FC_VER_NO == 1) { - fireno = 8; //老版本是闪烁频率,且不能为小数 ledinterval = ledInfo.LEDInterval; + //老版本ledMode == 8 对应拉烟,飞控对应50,ledinterval对应通道号 + if (ledMode==8) ledMode = 50; } else { - fireno = 15; //新版本飞控 是闪烁间隔单位是100ms,地面站还是频率可以有1位小数,用户输入0.5hz 飞控应该是(1/0.5)*10=20 - ledinterval = (1/ledInfo.LEDInterval); - } + ledinterval = (1 / ledInfo.LEDInterval); - if (ledMode == fireno) ledMode = 50; + //新版本 ledMode=16是抛物,飞控对应50,ledinterval对应10 --固定的 + if (ledMode == 16) + { + ledMode = 50; + ledinterval = 10; + } + else //新版本ledMode == 15 对应拉烟,飞控对应50,ledinterval对应通道号 + if (ledMode == 15) + { + ledMode = 50; + } + } IMission LEDMission = Mission.CreateLEDControlMission( (int)(ledInfo.Delay * 10), ledMode, diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index 57592aa..0fe587c 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -2021,7 +2021,16 @@ public ICommand VerticlAlignmentCommand //必须大于1架 if (_copterManager.SelectedCopters.Count() <= 1) + { + Alert.Show("必须选中多于一架飞机"); return; + } + if (EndTime<= BeginTime) + { + Alert.Show("结束时间必须大于开始时间(非持续时间!)"); + return; + } + //旋转飞机矩阵 if (CopterDirection != 0) diff --git a/Plane.FormationCreator/Views/ControlPanelView.xaml b/Plane.FormationCreator/Views/ControlPanelView.xaml index 587a547..cf08c2e 100644 --- a/Plane.FormationCreator/Views/ControlPanelView.xaml +++ b/Plane.FormationCreator/Views/ControlPanelView.xaml @@ -43,6 +43,8 @@