From 32110aab070846c2d9cf08758cee7b1a0759f171 Mon Sep 17 00:00:00 2001 From: xu Date: Fri, 28 Jun 2024 18:29:06 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E8=B0=83=E6=95=B4=E5=8F=8C=E9=80=9A?= =?UTF-8?q?=E9=81=93=E5=8F=91=E9=80=81=E6=A1=86=E6=9E=B6=E5=92=8C=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=20=20=E4=B8=BA=E4=BA=86=E5=B9=BF=E6=92=AD=E9=80=9A?= =?UTF-8?q?=E9=81=93=E8=83=BD=E6=9C=8D=E5=8A=A1=E4=BA=8E=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=B9=BF=E6=92=AD=E5=91=BD=E4=BB=A4,=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=B9=BF=E6=92=AD=E5=8F=91=E9=80=81=E6=A1=86=E6=9E=B6=EF=BC=8C?= =?UTF-8?q?=20=20=E5=B0=86=E9=80=9A=E9=81=93=E9=80=89=E6=8B=A9=E4=BB=8Ertk?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=95=8C=E9=9D=A2=E7=A7=BB=E5=88=B0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=95=8C=E9=9D=A2=20=20=E5=8F=B3=E4=B8=8B=E8=A7=92?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=B9=BF=E6=92=AD=E9=80=9A=E9=81=93=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=89=93=E5=BC=80=E7=9A=84=E6=8F=90=E7=A4=BA=20=20RTK?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=8A=B6=E6=80=81=E7=9A=84=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BB=8E=E6=8C=89=E9=92=AE=E6=97=81=E8=BE=B9=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=E4=B8=BB=E7=95=8C=E9=9D=A2=E7=8A=B6=E6=80=81=E6=A0=8F?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=8A=A0=E5=85=A5=E6=9B=B4=E5=A4=9A=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=20=E8=B0=83=E6=95=B4=E8=BF=9E=E6=8E=A5=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- Plane.FormationCreator/App.xaml | 4 +- .../Formation/RtcmManager.cs | 65 +++++++----- Plane.FormationCreator/MainWindow.xaml | 12 +-- .../ViewModels/ConnectViewModel.cs | 98 ++++++++++++++++++- .../ViewModels/MainViewModel.cs | 29 +++++- .../ViewModels/RtcmInfoViewModel.cs | 53 ++++------ .../Views/ConnectWindow.xaml | 28 ++++-- .../Views/ConnectWindow.xaml.cs | 6 ++ .../Views/ControlPanelView.xaml | 5 - .../Views/RtcmInfoView.xaml | 9 +- 10 files changed, 217 insertions(+), 92 deletions(-) diff --git a/Plane.FormationCreator/App.xaml b/Plane.FormationCreator/App.xaml index fdcfb47..620528d 100644 --- a/Plane.FormationCreator/App.xaml +++ b/Plane.FormationCreator/App.xaml @@ -13,11 +13,11 @@ (); private bool _rtcmthreadrun = false; private bool _smallrtcmdata = false; //减少传输数据--用于带宽不够的通讯模块-对数传广播无效 - private bool _enrecom = false;//是否转发到另外串口 + // rtcm发送类型0:直接发送, // 1:1秒只发一种卫星,1秒发GPS,第2秒发北斗,第3秒发格洛纳斯,其他数据随来随发 @@ -100,19 +101,33 @@ namespace Plane.FormationCreator.Formation return typename; } + private void SetRTKStatestr() + { + string rtksstr= ""; + // ResendToCom + if (Rtcmthreadrun) + { + rtksstr = "RTK发送中 "; + + if (SmallRtcmData) + rtksstr += ",低带宽模式 "; + if (ResendToCom) + rtksstr += ",双通道发送 "; + rtksstr += "..."; + } + else + rtksstr = "RTK未发送"; + + ControlPanelVM.RTKState = rtksstr; + + } + public bool Rtcmthreadrun { get { return _rtcmthreadrun; } set { Set(nameof(Rtcmthreadrun), ref _rtcmthreadrun, value); - - if (value) - ControlPanelVM.RTKState = "RTK发送中..."; - else - ControlPanelVM.RTKState = "RTK未发送"; - - - + SetRTKStatestr(); } } @@ -122,6 +137,7 @@ namespace Plane.FormationCreator.Formation set { Set(nameof(SmallRtcmData), ref _smallrtcmdata, value); + SetRTKStatestr(); } } @@ -212,6 +228,17 @@ namespace Plane.FormationCreator.Formation get { return _stationTime; } set { Set(nameof(StationTime), ref _stationTime, value); } } + private bool _sesendtocom; + public bool ResendToCom + { + get { return _sesendtocom; } + set { + Set(nameof(ResendToCom), ref _sesendtocom, value); + SetRTKStatestr(); + } + } + + private DispatcherTimer dispatcherTimer = null; public RtcmManager() @@ -290,8 +317,9 @@ namespace Plane.FormationCreator.Formation { return SerialPort.GetPortNames(); } + - public async Task Open(string CMB_serialport, string reserialport="") + public async Task Open(string CMB_serialport) { if (CMB_serialport == "") return; FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance(); @@ -373,12 +401,6 @@ namespace Plane.FormationCreator.Formation if (comPort.IsOpen) { Rtcmthreadrun = true; - _enrecom = false; - if (reserialport != "") - { - _enrecom=_commModuleManager.OpenResendRtcmserial(reserialport); - - } await RtcmLoop(); } } @@ -487,19 +509,12 @@ namespace Plane.FormationCreator.Formation nmea.resetParser(); string msgshowname = rtcm_typename(seenmsg); //Plane.Windows.Messages.Message.Show("--收到[" + seenmsg + "]:"+ msgshowname+" ,长度:"+ rtcm.length); - //广播数据直接发送不受小带宽数据选项影响 - if (_enrecom) - { - // Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss") + "--广播Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")"); - _commModuleManager.BroadcastGpsDataAsync(rtcm.packet, (ushort)rtcm.length); - } - //直接发送 if (!SmallRtcmData) { //发送到飞机 // Console.WriteLine(DateTime.UtcNow.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, ResendToCom); //累加消息数量,用于界面显示 bpsusefull += rtcm.length; } @@ -615,7 +630,7 @@ namespace Plane.FormationCreator.Formation if (Ensend) { //Console.WriteLine(DateTime.UtcNow.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, ResendToCom); //累加消息数量,用于界面显示 bpsusefull += rtcm.length; } diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index 59ce667..ec1b8f4 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -267,20 +267,18 @@ - + - - - + + + diff --git a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs index 76188eb..961c927 100644 --- a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs @@ -25,16 +25,31 @@ using Plane.Protocols; using Microsoft.Practices.ServiceLocation; using System.Windows.Media; using Plane.FormationCreator.Views; +using System.Collections.ObjectModel; +using Plane.Util; +using System.IO.Ports; +using SerialPort = Plane.Util.SerialPort; namespace Plane.FormationCreator.ViewModels { public class ConnectViewModel : ViewModelBase { + public ConnectViewModel(CopterManager copterManager) { _copterManager = copterManager; + RefreshPorts(); } - + public void RefreshPorts() + { + serialRePorts.Clear(); + string[] commports = SerialPort.GetPortNames(); + foreach (var item in commports) + { + serialRePorts.Add(item); + } + } + private CommModuleManager _commModuleManager = CommModuleManager.Instance; private CopterManager _copterManager; private const int PORT = 5250; @@ -67,6 +82,16 @@ namespace Plane.FormationCreator.ViewModels set { Set(nameof(IsProcessing), ref _IsProcessing, value); } } + public ObservableCollection serialRePorts { get; } = new ObservableCollection(); + private string _serialPortResend; + public string SerialPortResend + { + + get { return _serialPortResend; } + set { Set(nameof(SerialPortResend), ref _serialPortResend, value); } + + } + private ICommand _ConnectCommand; public ICommand ConnectCommand { @@ -79,7 +104,64 @@ namespace Plane.FormationCreator.ViewModels )); } } + RtcmInfoViewModel _rtcmInfoViewModel = ServiceLocator.Current.GetInstance(); + private ICommand _Openboardport; + public ICommand Openboardport + { + get + { + return _Openboardport ?? (_Openboardport = new RelayCommand(async connectionType => + { + if (_commModuleManager.Recomisopen) + { + //当前是否使用了广播端口 + if (_rtcmInfoViewModel.ResendToComMK) + { + if (Alert.Show("将同时关闭双通道发送RTK数据,继续吗?", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning) + == MessageBoxResult.OK) + { + _rtcmInfoViewModel.ResendToComMK = false; + } + else + { + return; + } + } + _commModuleManager.CloseResendRtcmserial(); + btnBoardPortStr = "打开广播端口"; + BoardPortStatusStr = _commModuleManager.BoardPortStatusStr; + Message.BoardOpen(false); + } + else + { + if ((SerialPortResend != null)) + { + if (!_commModuleManager.OpenResendRtcmserial(SerialPortResend)) + { + Alert.Show($"打开串口失败", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + } + else + { + btnBoardPortStr = "关闭广播端口"; + Message.BoardOpen(true); + } + BoardPortStatusStr = _commModuleManager.BoardPortStatusStr; + + } + else + { + Alert.Show($"请选择需要广播的端口", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + } + } + )); + } + } + + + private ICommand _SendCommand; public ICommand SendCommand { @@ -149,6 +231,20 @@ namespace Plane.FormationCreator.ViewModels set { Set(nameof(CopterColor), ref _CopterColor, value); } } + private string _BoardPortStatusStr = "端口未打开"; + public string BoardPortStatusStr + { + get { return _BoardPortStatusStr; } + set { Set(nameof(BoardPortStatusStr), ref _BoardPortStatusStr, value); } + } + + private string _btnBoardPortStr = "打开广播端口"; + public string btnBoardPortStr + { + get { return _btnBoardPortStr; } + set { Set(nameof(btnBoardPortStr), ref _btnBoardPortStr, value); } + } + private ICommand _WriteIdCommand; public ICommand WriteIdCommand { diff --git a/Plane.FormationCreator/ViewModels/MainViewModel.cs b/Plane.FormationCreator/ViewModels/MainViewModel.cs index 64819b3..5aef63d 100644 --- a/Plane.FormationCreator/ViewModels/MainViewModel.cs +++ b/Plane.FormationCreator/ViewModels/MainViewModel.cs @@ -35,10 +35,15 @@ namespace Plane.FormationCreator.ViewModels //连接信息 Plane.Windows.Messages.Message.Configure(connectAction: connected => this.CommunicationModuleConnected = connected); + //广播是否打开 + Plane.Windows.Messages.Message.Configureboard(boardportAction: opened => this.BoardcastPortOpened = opened); + + this.SwitchVelocityModeButtonContent = GetSwitchVelocityModeButtonContent(); AppEx.Current.PropertyChanged += AppEx_PropertyChanged; _copterManager.netStatusChanged += CopterManagernetStatusChanged; + ControlPanelViewModelData = ServiceLocator.Current.GetInstance(); } private CopterListViewModel _copterListViewModel; @@ -88,10 +93,18 @@ namespace Plane.FormationCreator.ViewModels Logs += (Environment.NewLine + value); } } + private ControlPanelViewModel _controlPanelViewModelData; + public ControlPanelViewModel ControlPanelViewModelData + { + get { return _controlPanelViewModelData; } + set + { + Set(nameof(ControlPanelViewModelData), ref _controlPanelViewModelData, value); + } + } - - + // public ControlPanelViewModel ControlPanelViewModelData = ServiceLocator.Current.GetInstance(); private bool _CommunicationModuleConnected; public bool CommunicationModuleConnected @@ -103,6 +116,18 @@ namespace Plane.FormationCreator.ViewModels } } + + private bool _BoardcastPortOpened=false; + public bool BoardcastPortOpened + { + get { return _BoardcastPortOpened; } + set + { + Set(nameof(BoardcastPortOpened), ref _BoardcastPortOpened, value); + } + } + + private string _SysStatusText="系统信息"; public string SysStatusText { diff --git a/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs b/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs index 6ddfe7d..1334c81 100644 --- a/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs +++ b/Plane.FormationCreator/ViewModels/RtcmInfoViewModel.cs @@ -1,5 +1,6 @@ using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; +using Plane.CommunicationManagement; using Plane.FormationCreator.Formation; using Plane.Windows.Messages; using System; @@ -18,9 +19,19 @@ namespace Plane.FormationCreator.ViewModels private RtcmManager _rtcmManager; public RtcmManager RtcmManager { get { return _rtcmManager; } } - + //方式 public ObservableCollection serialPorts { get; } = new ObservableCollection(); - public ObservableCollection serialRePorts { get; } = new ObservableCollection(); + + private CommModuleManager _commModuleManager = CommModuleManager.Instance; + + public string BoardPortsStatus + { + get + { + return _commModuleManager.BoardPortStatusStr; + } + } + private string _serialPortsSelectdValue; @@ -32,14 +43,7 @@ namespace Plane.FormationCreator.ViewModels } - private string _serialPortResend; - public string SerialPortResend - { - get { return _serialPortResend; } - set { Set(nameof(SerialPortResend), ref _serialPortResend, value); } - - } private bool _smalldatamk; public bool SmalldataMK @@ -61,14 +65,15 @@ namespace Plane.FormationCreator.ViewModels if (value) { //发送 - if (_rtcmManager.Rtcmthreadrun) + if (!_commModuleManager.Recomisopen) { - Alert.Show($"请先关闭RTK", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + Alert.Show($"请在设置里面打开广播端口", "提示", MessageBoxButton.OK, MessageBoxImage.Information); return; } } Set(nameof(ResendToComMK), ref _resendtocommk, value); + _rtcmManager.ResendToCom = value; } } @@ -84,7 +89,6 @@ namespace Plane.FormationCreator.ViewModels foreach (var item in commports) { serialPorts.Add(item); - serialRePorts.Add(item); } SerialPortsSelectdValue = serialPorts[0]; } @@ -94,7 +98,6 @@ namespace Plane.FormationCreator.ViewModels public void RefreshPorts() { string lastSelectValue = SerialPortsSelectdValue; - string lastSelectValue_re = SerialPortResend; serialPorts.Clear(); serialPorts.Add("魔方基站"); serialPorts.Add("千寻"); @@ -105,17 +108,6 @@ namespace Plane.FormationCreator.ViewModels } if (serialPorts.Contains(lastSelectValue)) SerialPortsSelectdValue = lastSelectValue; - - serialRePorts.Clear(); - - foreach (var item in commports) - { - serialRePorts.Add(item); - } - if (serialRePorts.Contains(lastSelectValue_re)) - SerialPortResend = lastSelectValue_re; - - } private ICommand _ConnectRtcmCommand; @@ -127,18 +119,9 @@ namespace Plane.FormationCreator.ViewModels { //是否转发到特定端口 string resendserial = ""; - if (ResendToComMK) - { - if ((SerialPortResend!=null)&&(SerialPortResend != "")) - resendserial = SerialPortResend; - else - { - Alert.Show($"请选择需要转发的端口", "提示", MessageBoxButton.OK, MessageBoxImage.Information); - return; - } - } + _rtcmManager.ResendToCom = ResendToComMK; if (!_rtcmManager.Rtcmthreadrun) - await _rtcmManager.Open(SerialPortsSelectdValue,resendserial); + await _rtcmManager.Open(SerialPortsSelectdValue); else await _rtcmManager.Close(SerialPortsSelectdValue); })); diff --git a/Plane.FormationCreator/Views/ConnectWindow.xaml b/Plane.FormationCreator/Views/ConnectWindow.xaml index 4dbef57..5f60a4b 100644 --- a/Plane.FormationCreator/Views/ConnectWindow.xaml +++ b/Plane.FormationCreator/Views/ConnectWindow.xaml @@ -24,11 +24,10 @@ - - - - + + + @@ -64,9 +63,20 @@ + + +