diff --git a/Plane.FormationCreator/Formation/Extensions.cs b/Plane.FormationCreator/Formation/Extensions.cs index 53e8350..cda1a89 100644 --- a/Plane.FormationCreator/Formation/Extensions.cs +++ b/Plane.FormationCreator/Formation/Extensions.cs @@ -54,8 +54,8 @@ namespace Plane.FormationCreator.Formation public static bool ArrivedTarget(this ICopter copter, double targetLat, double targetLng, float targetAlt) { - return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2; - // return copter.DistanceTo(targetLat, targetLng, targetAlt) < 1.5; + // return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2; + return copter.DistanceTo(targetLat, targetLng, targetAlt) < 0.6; //到达航点精度 // return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2; // added by ZJF } @@ -71,7 +71,7 @@ namespace Plane.FormationCreator.Formation public static bool IsTooCloseTo(this ICopter copter, ICopter copter2) { - return copter.DistanceTo(copter2) < 2; + return copter.DistanceTo(copter2) < 0.5; //最近距离2米 } } } diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index f5e9f36..7a4c4f5 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -14,11 +14,19 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using Plane.Communication; namespace Plane.FormationCreator.ViewModels { public class ControlPanelViewModel : ViewModelBase { + // serialport + internal static IConnection Rtkport ; + private static System.Threading.Thread thrtk; + private static bool trkthreadrun = false; + + + public ControlPanelViewModel(FormationController formationController, CopterManager copterManager) { _formationController = formationController; @@ -127,6 +135,156 @@ namespace Plane.FormationCreator.ViewModels })); } } + private string _RTKcomvalue = "COM3"; + public string RTKcomvalue + { + get { return _RTKcomvalue; } + set { Set(nameof(RTKcomvalue), ref _RTKcomvalue, value); } + } + + //RTK收发线程 + private static void mainloop() + { + + + + } + + + private async Task ReadRTKPacketAsync() + { + if (!Rtkport.IsOpen) + { + return null; + } + + // limit to 110 byte packets + byte[] buffer = new byte[180]; + int length = 0; + + try + { + if (Rtkport.BytesToRead() > 0)//while (Rtkport.BytesToRead() > 0) + + + { + int read = await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, Rtkport.BytesToRead())); + + // sendData(buffer, (byte)read); + + } + + /* + if (await Rtkport.ReadAsync(buffer, 0, 1) == 0) + { + // 做简单数据解析,得到协议类型,后续数据长度等 + } + //根据数据长度读取实际数据 + if (await Rtkport.ReadAsync(buffer, 1, 1) == 0) + { + + } + */ + + } + catch (Exception ex) + { + return null; + } + return buffer; + + } + + + + private ICommand _SendRTKCommand; + public ICommand SendRTKCommand + { + get + { + return _SendRTKCommand ?? (_SendRTKCommand = new RelayCommand(async () => + { + Rtkport = new SerialPortConnection(RTKcomvalue,57600) as IConnection; + await Rtkport.OpenAsync(); + if (!Rtkport.IsOpen) + { + Alert.Show("无法打开" + RTKcomvalue , "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + trkthreadrun = true; //开始运行后台任务 + /* //线程方式后台运行rtk转发任务 + thrtk = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop)) + { + IsBackground = true, + Name = "injectgps" + }; + thrtk.Start(); + */ + //后台任务方式运行rtk转发任务 + await Task.Run(async () => + { + //读取RTK数据循环 + while (trkthreadrun) + { + //读入RTK数据 + var packet = await ReadRTKPacketAsync().ConfigureAwait(false); + //分发到每个飞机 + foreach (var copter in _copterManager.Copters) + { + await copter.InjectGpsDataAsync(packet, (ushort)packet.Length); + } + + + await Task.Delay(200).ConfigureAwait(false); + + } + }).ConfigureAwait(false); + + /* + + await Task.Run(() => + { + if (!Rtkport.IsOpen) + { + return null; + } + + // var packet = await ReadRTKPacketAsync().ConfigureAwait(false); + + while (trkthreadrun) + { + + await ReadRTKPacketAsync(); + + // if (await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, 110)) > 0) + { + + + + + + } + + + + + + + + + } + + + });*/ + + + })); + } + } + + + + private ICommand _LandCommand; public ICommand LandCommand diff --git a/Plane.FormationCreator/Views/ControlPanelView.xaml b/Plane.FormationCreator/Views/ControlPanelView.xaml index baa7ba2..705cc08 100644 --- a/Plane.FormationCreator/Views/ControlPanelView.xaml +++ b/Plane.FormationCreator/Views/ControlPanelView.xaml @@ -59,6 +59,19 @@ Text="{Binding AltP, UpdateSourceTrigger=PropertyChanged}" /> + + +