[feat] 调整双通道发送框架和界面

为了广播通道能服务于所有广播命令,调整广播发送框架,
 将通道选择从rtk发送界面移到设置界面
 右下角加入广播通道是否打开的提示
 RTK发送状态的提示从按钮旁边移动到主界面状态栏,并加入更多信息
 调整连接状态图标

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
xu 2024-06-28 18:29:06 +08:00
parent 12262ff53d
commit 32110aab07
10 changed files with 217 additions and 92 deletions

View File

@ -13,11 +13,11 @@
<Application.Resources>
<materialDesign:PackIcon x:Key="CheckIcon"
x:Shared="False"
Kind="Check"
Kind="LanConnect"
Foreground="#2196F3" />
<materialDesign:PackIcon x:Key="CloseIcon"
x:Shared="False"
Kind="Close"
Kind="LanDisconnect"
Foreground="White" />
<cnv:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<cnv:BooleanToVisibilityConverter x:Key="InversiveBooleanToVisibilityConverter"

View File

@ -1,5 +1,6 @@
using GalaSoft.MvvmLight;
using Microsoft.Practices.ServiceLocation;
using Newtonsoft.Json.Linq;
using Plane.CommunicationManagement;
using Plane.FormationCreator.ViewModels;
using Plane.Util;
@ -37,7 +38,7 @@ namespace Plane.FormationCreator.Formation
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private bool _rtcmthreadrun = false;
private bool _smallrtcmdata = false; //减少传输数据--用于带宽不够的通讯模块-对数传广播无效
private bool _enrecom = false;//是否转发到另外串口
// rtcm发送类型0:直接发送,
// 11秒只发一种卫星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<FlightTaskManager>();
@ -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;
}

View File

@ -267,20 +267,18 @@
<TextBlock Margin="10,4"
Text="{Binding Message}" Width="480" MouseUp="LogShowHide"/>
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="0,8" BorderBrush="LightGray" BorderThickness="1"/>
<TextBlock Margin="10,4"
Width="300" Text="{Binding SysStatusText}" />
<TextBlock Margin="10,4" Width="300" Text="{Binding SysStatusText}" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="0,8" BorderBrush="LightGray" BorderThickness="1"/>
<TextBlock Margin="10,4" Width="400"
Text="{Binding CopterListViewModel.SelectedCopter.StatusText}" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="0,8" BorderBrush="LightGray" BorderThickness="1"/>
<TextBlock Margin="10,4" Width="200"
Text="{Binding ControlPanelViewModel.RTKState}" />
<TextBlock Margin="10,4" Width="210"
Text="{Binding ControlPanelViewModelData.RTKState}" />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="0,8" BorderBrush="LightGray" BorderThickness="1"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text="{Binding Loginstate}" Margin="0,4,14,0"/>
<TextBlock Text="广播端口:" Margin="4"/>
<ContentPresenter Margin="0,4,4,0" Content="{Binding BoardcastPortOpened, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
<TextBlock Text="通信连接:" Margin="4"/>
<ContentPresenter Margin="0,4,14,0" Content="{Binding CommunicationModuleConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
</StackPanel>

View File

@ -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<string> serialRePorts { get; } = new ObservableCollection<string>();
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<RtcmInfoViewModel>();
private ICommand _Openboardport;
public ICommand Openboardport
{
get
{
return _Openboardport ?? (_Openboardport = new RelayCommand<string>(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
{

View File

@ -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<ControlPanelViewModel>();
}
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<ControlPanelViewModel>();
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
{

View File

@ -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<string> serialPorts { get; } = new ObservableCollection<string>();
public ObservableCollection<string> serialRePorts { get; } = new ObservableCollection<string>();
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);
}));

View File

@ -24,11 +24,10 @@
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="50" />
<RowDefinition Height="30" />
<RowDefinition Height="40" />
<RowDefinition Height="30" />
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -64,9 +63,20 @@
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2" Name="panel7" >
<Button Content="{Binding btnBoardPortStr}" Width="115" Margin="5,5,5,5" Command="{Binding Openboardport}"/>
<ComboBox Width="90" Height="25" Foreground="White" SelectedIndex="0"
ItemsSource="{Binding serialRePorts, Mode=OneWay}"
SelectedValue="{Binding SerialPortResend}"
DropDownOpened="ComboBox_DropDownOpened"/>
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding BoardPortStatusStr}" />
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left"
Grid.Row="2"
Grid.Row="3"
Name="panel2" >
<TextBlock Margin="5" VerticalAlignment="Center" Text="总数:" />
<TextBox Width="45" VerticalContentAlignment="Center" Text="{Binding CopterSum}" Margin="5,5,5,5" />
@ -77,7 +87,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left"
Grid.Row="3"
Grid.Row="4"
Name="panel3" >
<Button Content="空中升级" Width="90" Margin="5,5,5,5" Command="{Binding UpdateAllCopterCommand}"></Button>
<Button Content="搜索飞机" Width="90" Margin="5,5,5,5" Command="{Binding QueryAllCopterCommand}"/>
@ -87,9 +97,9 @@
<Image Margin="0,0,0,0" x:Name="image1" Grid.RowSpan="2" Grid.Row="4" Source="/Resources/Logo_small.png" HorizontalAlignment="Left" />
<TextBlock Margin="5" Grid.Row="5" x:Name="about_ver" HorizontalAlignment="Right" VerticalAlignment="Bottom" Text="版本V2.0.1213" />
<TextBlock Margin="5" Grid.Row="6" HorizontalAlignment="Right" x:Name="about_buildtm" VerticalAlignment="Bottom" Text="编译日期2020.12.12" />
<Image Margin="0,0,0,0" x:Name="image1" Grid.RowSpan="2" Grid.Row="5" Source="/Resources/Logo_small.png" HorizontalAlignment="Left" />
<TextBlock Margin="5" Grid.Row="6" x:Name="about_ver" HorizontalAlignment="Right" VerticalAlignment="Bottom" Text="版本V2.0.1213" />
<TextBlock Margin="5" Grid.Row="7" HorizontalAlignment="Right" x:Name="about_buildtm" VerticalAlignment="Bottom" Text="编译日期2020.12.12" />

View File

@ -55,5 +55,11 @@ namespace Plane.FormationCreator.Views
//txtIPs.Focus();
}
ConnectViewModel _ConnectViewModel = ServiceLocator.Current.GetInstance<ConnectViewModel>();
private void ComboBox_DropDownOpened(object sender, EventArgs e)
{
_ConnectViewModel.RefreshPorts();
}
}
}

View File

@ -46,11 +46,6 @@
<Button Content="通讯统计"
Command="{Binding GetCommsumCommand}" />
<TextBlock
Margin="5,5,5,5" Foreground ="Red" VerticalAlignment="Center"
Text="{Binding RTKState}"
/>
</WrapPanel>
<WrapPanel>
<Button Content="参数设置"

View File

@ -27,14 +27,11 @@
<Label Margin="0,6,6,6" Height="28" Content="{Binding RtcmManager.rtcmInfoList.Count,UpdateSourceTrigger=PropertyChanged}"></Label>
</StackPanel>
<StackPanel Margin="6,0,0,6" Orientation="Horizontal">
<CheckBox x:Name="checkBox" Content="同时发送到(57600)"
<CheckBox x:Name="checkBox" Content="双通道发送"
Margin="4,5,5,0" Width="130"
IsChecked="{Binding ResendToComMK}"/>
<ComboBox Width="90" Height="25" Foreground="White" SelectedIndex="0"
ItemsSource="{Binding serialRePorts, Mode=OneWay}"
SelectedValue="{Binding SerialPortResend}"
DropDownOpened="ComboBox_DropDownOpened"/>
<CheckBox x:Name="cBsmalldata" Content="减少广播数据"
<TextBlock Margin="0,4,0,0" Text="{Binding BoardPortsStatus}"/>
<CheckBox x:Name="cBsmalldata" Content="低带宽模式"
Margin="20,5,5,0" Width="95"
IsChecked="{Binding SmalldataMK}"/>
</StackPanel>