继续修改wifi,可以批量起飞等功能

This commit is contained in:
xu 2020-03-11 15:34:31 +08:00
parent da086831bf
commit 3aa4879511
7 changed files with 52 additions and 15 deletions

View File

@ -173,31 +173,41 @@ namespace Plane.FormationCreator
{
_logger.Log(e.Message );
}
//wifi模式添加飞机
private async Task AddOrUpdateCopter(string ip, IConnection Connection)
{
var copters = _copterManager.Copters;
var copterStatus = _copterManager.CopterStatus;
var copter = copters.FirstOrDefault(c => c.Id == ip);
string[] iparr = ip.Split('.');
string vIPID = String.Format("{0:D3}", int.Parse(iparr[2])) + String.Format("{0:D3}", int.Parse(iparr[3]));
var copter = copters.FirstOrDefault(c => c.Id == vIPID);
if (copter == null)
{
if (!_copterManager.EnAddCopter_Real())
{
UdpServerConnectionManager.Instance.DeleteConnections(ip);
}
else
{
await Dispatcher.BeginInvoke(new Action(() =>
{
if (_copterManager.EnAddCopter_Real())
{
copter = new Copter(Connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng)
{
Id = ip,
Name = ip.Substring(ip.LastIndexOf('.') + 1)
Id = vIPID,
Name = vIPID // ip.Substring(ip.LastIndexOf('.') + 1)
};
int _index;
_index = copters.AddCopter(copter);
copterStatus.Insert(_index, false);
copter.TextReceived += Copter_TextReceived;
}
}));
}
}
else
{
copter.Connection = Connection;

View File

@ -591,6 +591,20 @@ namespace Plane.FormationCreator.Formation
public async Task ClearCopters()
{
foreach (var copter in Copters)
{
await copter.DisconnectAsync();
}
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
Copters.Clear();
CopterStatus.Clear();
//wifi
if (VersionControl.ConType==1)
UdpServerConnectionManager.Instance.ClearConnections();
}
public bool EnAddCopter_Real()
{

View File

@ -27,7 +27,7 @@ namespace Plane.FormationCreator.Formation
private CommModuleManager _commModuleManager = CommModuleManager.Instance;
public ObservableCollection<RtcmInfo> rtcmInfoList { get; } = new ObservableCollection<RtcmInfo>();
private ControlPanelViewModel ControlPanelVM = ServiceLocator.Current.GetInstance<ControlPanelViewModel>();
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private bool _rtcmthreadrun = false;
public bool Rtcmthreadrun
{
@ -313,6 +313,7 @@ namespace Plane.FormationCreator.Formation
//用于双频RTK发送
// await _commModuleManager.InjectGpsRTCMDataAsync(rtcm.packet, rtcm.length);
//用于单频rtk发送
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
await _commModuleManager.InjectGpsDataAsync(rtcm.packet, (ushort)rtcm.length);
string msgname = "Rtcm" + seenmsg;

View File

@ -235,7 +235,7 @@
<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="200"
<TextBlock Margin="10,4" Width="400"
Text="{Binding CopterListViewModel.SelectedCopter.StatusText}" />
</StackPanel>

View File

@ -314,6 +314,7 @@ namespace Plane.FormationCreator.ViewModels
{
return _AllLandCommand ?? (_AllLandCommand = new RelayCommand(async () =>
{
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
await _commModuleManager.LandAsync();
/*
await Task.WhenAll(_copterManager.Copters.Select(async c =>
@ -409,6 +410,7 @@ namespace Plane.FormationCreator.ViewModels
// await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync()));
for (int i = 0; i < 3; i++)
{
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
await _commModuleManager.UnlockAsync();
await Task.Delay(1000).ConfigureAwait(false);
}
@ -536,6 +538,7 @@ namespace Plane.FormationCreator.ViewModels
if (Alert.Show("您确定要上锁吗?飞行器将无视转速,立即强制停止运转!!!", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.OK)
{
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
await _commModuleManager.LockAsync(_copterManager.AcceptingControlCopters);
//await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LockAsync()));
}
@ -702,7 +705,10 @@ namespace Plane.FormationCreator.ViewModels
if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count)
num = await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count)
{
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
num = await _commModuleManager.SetParamAsync(paramstr, paramvalue);
}
Alert.Show($"广播完成! 当前序列号:{num}");
}
else
@ -896,6 +902,7 @@ namespace Plane.FormationCreator.ViewModels
}
*/
//稳定方案的rtk发送用于单频
_commModuleManager.SetAllCoptersForWifi(_copterManager.Copters);
await _commModuleManager.InjectGpsDataAsync(packet, (ushort)packet.Length);
}
await Task.Delay(10).ConfigureAwait(false);

View File

@ -441,6 +441,8 @@ namespace Plane.FormationCreator.ViewModels
return _ClearCoptersCommand ?? (_ClearCoptersCommand = new RelayCommand(async () =>
{
_flightTaskManager.Pause();
await _copterManager.ClearCopters();
/*
foreach (var copter in _copterManager.Copters)
{
await copter.DisconnectAsync();
@ -448,10 +450,13 @@ namespace Plane.FormationCreator.ViewModels
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
_copterManager.Copters.Clear();
_copterManager.CopterStatus.Clear();
*/
_mapManager.ClearCopters();
_view3DManager.ClearCopters();
_flightTaskManager.ClearTasks();
// UdpServerConnectionManager.Instance.ClearConnections();
_virtualCopterId = 1;
_lastVirtualCopterLocation = null;
_flightTaskManager.OriginLat = 0;

View File

@ -30,7 +30,7 @@
<Button Content="开始校准" Width="100" Margin="10, 0"
Command="{Binding CalibrationCompassCommand}"/>
<Button Content="放弃校准" Width="100" Margin="10, 0"
Command="{Binding CancelCalibrationCompassCommand}"/>
Command="{Binding CancelCalibrationCompassCommand}" Visibility="Collapsed"/>
</WrapPanel>
<ProgressBar Margin="0,20" Height="18" Width="220" Value="{Binding CompassPercent, UpdateSourceTrigger=PropertyChanged}"/>