diff --git a/Plane.FormationCreator/Formation/RtcmManager.cs b/Plane.FormationCreator/Formation/RtcmManager.cs index a5f9971..361b99d 100644 --- a/Plane.FormationCreator/Formation/RtcmManager.cs +++ b/Plane.FormationCreator/Formation/RtcmManager.cs @@ -25,15 +25,18 @@ namespace Plane.FormationCreator.Formation private Hashtable msgseen = new Hashtable(); private ICommsSerial comPort; + private ICommsSerial RecomPort; 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; + private bool _enrecom = false;//是否转发到另外串口 + // rtcm发送类型0:直接发送, // 1:1秒只发一种卫星,1秒发GPS,第2秒发北斗,第3秒发格洛纳斯,其他数据随来随发 private int _rtcmsendtype = 1; - + private int _resendtocom = 1; const int MSG_GPS = 1074; const int MSG_GLONASS = 1084; const int MSG_Beidou = 1124; @@ -244,7 +247,7 @@ namespace Plane.FormationCreator.Formation return SerialPort.GetPortNames(); } - public async Task Open(string CMB_serialport) + public async Task Open(string CMB_serialport, string reserialport="") { if (CMB_serialport == "") return; FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance(); @@ -320,18 +323,26 @@ namespace Plane.FormationCreator.Formation } catch (Exception ex) { - //Message.Show(ex.Message); + Alert.Show("数据端口打开失败:"+ ex.Message, "提示"); } - + if (comPort.IsOpen) { Rtcmthreadrun = true; + _enrecom = false; + if (reserialport != "") + { + _enrecom=_commModuleManager.OpenResendRtcmserial(reserialport); + + } await RtcmLoop(); } } public async Task Close(string CMB_serialport) { + //如果需要关闭转发端口 + _commModuleManager.CloseResendRtcmserial(); await _commModuleManager.CloseRtcmLoop(); Rtcmthreadrun = false; comPort.Close(); @@ -363,6 +374,8 @@ namespace Plane.FormationCreator.Formation } + + //发送RTK数据线程循环 private async Task RtcmLoop() { int reconnecttimeout = 10; @@ -403,8 +416,9 @@ namespace Plane.FormationCreator.Formation //一次读取180个字节 int read = comPort.Read(buffer, 0, Math.Min(buffer.Length, comPort.BytesToRead)); if (read > 0) + { lastrecv = DateTime.Now; - + } bps += read; for (int a = 0; a < read; a++) { @@ -463,7 +477,7 @@ namespace Plane.FormationCreator.Formation { // Plane.Windows.Messages.Message.Show(DateTime.Now.ToString("HH:mm:ss")+"--Rtcm长度: " + (ushort)rtcm.length+" , 类型: "+ seenmsg); Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " ("+ seenmsg+")"); - await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length); + await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length, _enrecom); } //else // Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--放弃发送-----Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")"); diff --git a/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs b/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs index be4fb31..cb27aa7 100644 --- a/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs +++ b/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs @@ -8,6 +8,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Input; namespace Plane.FormationCreator.ViewModels @@ -19,6 +20,8 @@ namespace Plane.FormationCreator.ViewModels public RtcmManager RtcmManager { get { return _rtcmManager; } } public ObservableCollection serialPorts { get; } = new ObservableCollection(); + public ObservableCollection serialRePorts { get; } = new ObservableCollection(); + private string _serialPortsSelectdValue; public string SerialPortsSelectdValue @@ -29,6 +32,37 @@ namespace Plane.FormationCreator.ViewModels } + private string _serialPortResend; + public string SerialPortResend + { + + get { return _serialPortResend; } + set { Set(nameof(SerialPortResend), ref _serialPortResend, value); } + + } + + private bool _resendtocommk; + public bool ResendToComMK + { + get { return _resendtocommk; } + set + { + + if (value) + { //发送 + if (_rtcmManager.Rtcmthreadrun) + { + Alert.Show($"请先关闭RTK", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + + } + Set(nameof(ResendToComMK), ref _resendtocommk, value); + } + } + + + public RtcmInfoViewModel(RtcmManager rtcmManager) { _rtcmManager = rtcmManager; @@ -39,6 +73,7 @@ namespace Plane.FormationCreator.ViewModels foreach (var item in commports) { serialPorts.Add(item); + serialRePorts.Add(item); } SerialPortsSelectdValue = serialPorts[0]; } @@ -67,8 +102,20 @@ namespace Plane.FormationCreator.ViewModels { return _ConnectRtcmCommand ?? (_ConnectRtcmCommand = new RelayCommand(async() => { + //是否转发到特定端口 + string resendserial = ""; + if (ResendToComMK) + { + if ((SerialPortResend!=null)&&(SerialPortResend != "")) + resendserial = SerialPortResend; + else + { + Alert.Show($"请选择需要转发的端口", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + } if (!_rtcmManager.Rtcmthreadrun) - await _rtcmManager.Open(SerialPortsSelectdValue); + await _rtcmManager.Open(SerialPortsSelectdValue,resendserial); else await _rtcmManager.Close(SerialPortsSelectdValue); })); diff --git a/Plane.FormationCreator/Views/MapView_CopterDrawing.cs b/Plane.FormationCreator/Views/MapView_CopterDrawing.cs index 9075b2b..3ad650c 100644 --- a/Plane.FormationCreator/Views/MapView_CopterDrawing.cs +++ b/Plane.FormationCreator/Views/MapView_CopterDrawing.cs @@ -578,7 +578,8 @@ namespace Plane.FormationCreator.Views // routePoint.Lng = info.TargetLng; if (Route != null) { - Route.Points.RemoveAt(1); + if (Route.Points.Count>1) + Route.Points.RemoveAt(1); Route.Points.Add(marker.Position); this.Route.RegenerateShape(_map); } diff --git a/Plane.FormationCreator/Views/RtcmInfoView.xaml b/Plane.FormationCreator/Views/RtcmInfoView.xaml index 24f84db..9dfcc88 100644 --- a/Plane.FormationCreator/Views/RtcmInfoView.xaml +++ b/Plane.FormationCreator/Views/RtcmInfoView.xaml @@ -73,6 +73,15 @@ + + + +