加入RTK转发的广播端口

This commit is contained in:
pxzleo 2023-10-15 11:09:53 +08:00
parent c3a3877323
commit 1403000ef9
4 changed files with 79 additions and 8 deletions

View File

@ -25,15 +25,18 @@ namespace Plane.FormationCreator.Formation
private Hashtable msgseen = new Hashtable(); private Hashtable msgseen = new Hashtable();
private ICommsSerial comPort; private ICommsSerial comPort;
private ICommsSerial RecomPort;
private CommModuleManager _commModuleManager = CommModuleManager.Instance; private CommModuleManager _commModuleManager = CommModuleManager.Instance;
public ObservableCollection<RtcmInfo> rtcmInfoList { get; } = new ObservableCollection<RtcmInfo>(); public ObservableCollection<RtcmInfo> rtcmInfoList { get; } = new ObservableCollection<RtcmInfo>();
private ControlPanelViewModel ControlPanelVM = ServiceLocator.Current.GetInstance<ControlPanelViewModel>(); private ControlPanelViewModel ControlPanelVM = ServiceLocator.Current.GetInstance<ControlPanelViewModel>();
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>(); private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private bool _rtcmthreadrun = false; private bool _rtcmthreadrun = false;
private bool _enrecom = false;//是否转发到另外串口
// rtcm发送类型0:直接发送, // rtcm发送类型0:直接发送,
// 11秒只发一种卫星1秒发GPS,第2秒发北斗第3秒发格洛纳斯其他数据随来随发 // 11秒只发一种卫星1秒发GPS,第2秒发北斗第3秒发格洛纳斯其他数据随来随发
private int _rtcmsendtype = 1; private int _rtcmsendtype = 1;
private int _resendtocom = 1;
const int MSG_GPS = 1074; const int MSG_GPS = 1074;
const int MSG_GLONASS = 1084; const int MSG_GLONASS = 1084;
const int MSG_Beidou = 1124; const int MSG_Beidou = 1124;
@ -244,7 +247,7 @@ namespace Plane.FormationCreator.Formation
return SerialPort.GetPortNames(); return SerialPort.GetPortNames();
} }
public async Task Open(string CMB_serialport) public async Task Open(string CMB_serialport, string reserialport="")
{ {
if (CMB_serialport == "") return; if (CMB_serialport == "") return;
FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>(); FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
@ -320,18 +323,26 @@ namespace Plane.FormationCreator.Formation
} }
catch (Exception ex) catch (Exception ex)
{ {
//Message.Show(ex.Message); Alert.Show("数据端口打开失败:"+ ex.Message, "提示");
} }
if (comPort.IsOpen) if (comPort.IsOpen)
{ {
Rtcmthreadrun = true; Rtcmthreadrun = true;
_enrecom = false;
if (reserialport != "")
{
_enrecom=_commModuleManager.OpenResendRtcmserial(reserialport);
}
await RtcmLoop(); await RtcmLoop();
} }
} }
public async Task Close(string CMB_serialport) public async Task Close(string CMB_serialport)
{ {
//如果需要关闭转发端口
_commModuleManager.CloseResendRtcmserial();
await _commModuleManager.CloseRtcmLoop(); await _commModuleManager.CloseRtcmLoop();
Rtcmthreadrun = false; Rtcmthreadrun = false;
comPort.Close(); comPort.Close();
@ -363,6 +374,8 @@ namespace Plane.FormationCreator.Formation
} }
//发送RTK数据线程循环
private async Task RtcmLoop() private async Task RtcmLoop()
{ {
int reconnecttimeout = 10; int reconnecttimeout = 10;
@ -403,8 +416,9 @@ namespace Plane.FormationCreator.Formation
//一次读取180个字节 //一次读取180个字节
int read = comPort.Read(buffer, 0, Math.Min(buffer.Length, comPort.BytesToRead)); int read = comPort.Read(buffer, 0, Math.Min(buffer.Length, comPort.BytesToRead));
if (read > 0) if (read > 0)
{
lastrecv = DateTime.Now; lastrecv = DateTime.Now;
}
bps += read; bps += read;
for (int a = 0; a < read; a++) 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); // 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+")"); 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 //else
// Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--放弃发送-----Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")"); // Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "--放弃发送-----Rtcm长度: " + (ushort)rtcm.length + " 类型: " + msgshowname + " (" + seenmsg + ")");

View File

@ -8,6 +8,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input; using System.Windows.Input;
namespace Plane.FormationCreator.ViewModels namespace Plane.FormationCreator.ViewModels
@ -19,6 +20,8 @@ namespace Plane.FormationCreator.ViewModels
public RtcmManager RtcmManager { get { return _rtcmManager; } } public RtcmManager RtcmManager { get { return _rtcmManager; } }
public ObservableCollection<string> serialPorts { get; } = new ObservableCollection<string>(); public ObservableCollection<string> serialPorts { get; } = new ObservableCollection<string>();
public ObservableCollection<string> serialRePorts { get; } = new ObservableCollection<string>();
private string _serialPortsSelectdValue; private string _serialPortsSelectdValue;
public 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) public RtcmInfoViewModel(RtcmManager rtcmManager)
{ {
_rtcmManager = rtcmManager; _rtcmManager = rtcmManager;
@ -39,6 +73,7 @@ namespace Plane.FormationCreator.ViewModels
foreach (var item in commports) foreach (var item in commports)
{ {
serialPorts.Add(item); serialPorts.Add(item);
serialRePorts.Add(item);
} }
SerialPortsSelectdValue = serialPorts[0]; SerialPortsSelectdValue = serialPorts[0];
} }
@ -67,8 +102,20 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _ConnectRtcmCommand ?? (_ConnectRtcmCommand = new RelayCommand(async() => 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) if (!_rtcmManager.Rtcmthreadrun)
await _rtcmManager.Open(SerialPortsSelectdValue); await _rtcmManager.Open(SerialPortsSelectdValue,resendserial);
else else
await _rtcmManager.Close(SerialPortsSelectdValue); await _rtcmManager.Close(SerialPortsSelectdValue);
})); }));

View File

@ -578,7 +578,8 @@ namespace Plane.FormationCreator.Views
// routePoint.Lng = info.TargetLng; // routePoint.Lng = info.TargetLng;
if (Route != null) if (Route != null)
{ {
Route.Points.RemoveAt(1); if (Route.Points.Count>1)
Route.Points.RemoveAt(1);
Route.Points.Add(marker.Position); Route.Points.Add(marker.Position);
this.Route.RegenerateShape(_map); this.Route.RegenerateShape(_map);
} }

View File

@ -73,6 +73,15 @@
</StackPanel> </StackPanel>
</Border> </Border>
<CheckBox x:Name="checkBox" Content="同时发送到:"
Margin="20,30,5,20" Width="90"
IsChecked="{Binding ResendToComMK}"/>
<ComboBox Width="120" Height="25" Foreground="White" SelectedIndex="0"
Margin="10" ItemsSource="{Binding serialRePorts, Mode=OneWay}"
SelectedValue="{Binding SerialPortResend}"
DropDownOpened="ComboBox_DropDownOpened"/>
</StackPanel> </StackPanel>
<ItemsControl Grid.Row="1" <ItemsControl Grid.Row="1"