通信模块协议的添加和修改

小批量、读写通信地面站配置、修改连接id总数
This commit is contained in:
zxd 2019-04-11 13:20:32 +08:00
parent 0f19e2addf
commit 725c4b6d71
3 changed files with 109 additions and 10 deletions

View File

@ -169,7 +169,7 @@ namespace Plane.FormationCreator.Formation
if (prevTask.TaskType == FlightTaskType.FlyTo && prevTask.LoiterTime == 0) if (prevTask.TaskType == FlightTaskType.FlyTo && prevTask.LoiterTime == 0)
flyToTime += prevTask.RuningTaskRemaining; flyToTime += prevTask.RuningTaskRemaining;
} }
int LEDIndex = 0;
//while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 所有Copter到达目标点开始飞下个航点 //while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 所有Copter到达目标点开始飞下个航点
while (ts.TotalMilliseconds < (flyToTime + loiterTime)) //按时间轴飞:当前任务时间到达后自动飞往下个航点 while (ts.TotalMilliseconds < (flyToTime + loiterTime)) //按时间轴飞:当前任务时间到达后自动飞往下个航点
{ {
@ -212,20 +212,21 @@ namespace Plane.FormationCreator.Formation
double time = 0; double time = 0;
for (int i = 0; i < LedControl.Count; i++) for (int i = 0; i < LedControl.Count; i++)
{ {
var led = LedControl[i]; var led = LedControl[i];
time += led.Delay * 1000; time += led.Delay * 1000;
if (ts.TotalMilliseconds >= time) if (ts.TotalMilliseconds >= time)
{
LEDRGB = info.LEDInfos[i].LEDRGB; LEDRGB = info.LEDInfos[i].LEDRGB;
LEDIndex = i;
}
else else
break; break;
} }
Message.Show(LEDIndex.ToString());
info.Copter.LEDColor = LEDRGB; info.Copter.LEDColor = LEDRGB;
} }
if (ts.TotalMilliseconds / 10 > sendFlyToTimes) // 每500ms发送一遍指点坐标 if (ts.TotalMilliseconds / 10 > sendFlyToTimes) // 每500ms发送一遍指点坐标
{ {
sendFlyToTimes++; sendFlyToTimes++;

View File

@ -86,7 +86,7 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _SendCommand ?? (_SendCommand = new RelayCommand(async () => return _SendCommand ?? (_SendCommand = new RelayCommand(async () =>
{ {
await SendCommandAsync(CopterNum); await commModule.SetCommCount(CopterCount, (short)(CopterStartNum - 1));
} }
)); ));
} }
@ -132,6 +132,27 @@ namespace Plane.FormationCreator.ViewModels
set { Set(nameof(CopterColor), ref _CopterColor, value); } set { Set(nameof(CopterColor), ref _CopterColor, value); }
} }
private byte _TransmittedPower = 5;
public byte TransmittedPower
{
get { return _TransmittedPower; }
set { Set(nameof(TransmittedPower), ref _TransmittedPower, value); }
}
private short _CopterCount;
public short CopterCount
{
get { return _CopterCount; }
set { Set(nameof(CopterCount), ref _CopterCount, value); }
}
private short _CopterStartNum;
public short CopterStartNum
{
get { return _CopterStartNum; }
set { Set(nameof(CopterStartNum), ref _CopterStartNum, value); }
}
private ICommand _WriteIdCommand; private ICommand _WriteIdCommand;
public ICommand WriteIdCommand public ICommand WriteIdCommand
{ {
@ -215,6 +236,9 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
/// <summary>
/// 全部1S一次闪灯 主要用于测试通信
/// </summary>
private ICommand _CommDataAsync; private ICommand _CommDataAsync;
public ICommand CommDataAsync public ICommand CommDataAsync
{ {
@ -228,6 +252,54 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
/// <summary>
/// 设置回传功率
/// </summary>
private ICommand _CommSetPowerAsync;
public ICommand CommSetPowerAsync
{
get
{
return _CommSetPowerAsync ?? (_CommSetPowerAsync = new RelayCommand(async () =>
{
if (TransmittedPower >= 1 && TransmittedPower <= 16)
await commModule.SetCopterCommBackPower((short)CopterNum, TransmittedPower);
else
Alert.Show("功率范围只能设置为1-16");
}));
}
}
/// <summary>
/// 获取配置
/// </summary>
private ICommand _CommGetCurrSysParmAsync;
public ICommand CommGetCurrSysParmAsync
{
get
{
return _CommGetCurrSysParmAsync ?? (_CommGetCurrSysParmAsync = new RelayCommand(async () =>
{
await commModule.GetCurr_Sys_Parm();
}));
}
}
/// <summary>
/// 改写配置
/// </summary>
private ICommand _CommSetCurrSysParmAsync;
public ICommand CommSetCurrSysParmAsync
{
get
{
return _CommSetCurrSysParmAsync ?? (_CommSetCurrSysParmAsync = new RelayCommand(async () =>
{
await commModule.SetCurr_Sys_Parm();
}));
}
}
private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos) private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
{ {
List<IMission> missions = new List<IMission>(); List<IMission> missions = new List<IMission>();

View File

@ -68,6 +68,8 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
@ -89,7 +91,8 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Grid.Row="1" Grid.Row="1"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
Name="panel1"> Name="panel1"
Visibility="Collapsed">
<ec:ProgressButton HorizontalAlignment="Center" <ec:ProgressButton HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
@ -133,7 +136,7 @@
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
Name="panel2"> Name="panel2">
<Button Content="通信模块状态" Margin="5" Command="{Binding Path=StateInquireCommand}"/> <Button Content="通信模块状态" Margin="5" Command="{Binding Path=StateInquireCommand}"/>
<Button Content="设置总数" Margin="5" Command="{Binding Path=SendCommand}" />
<Button Content="切换写航点" Margin="5" Command="{Binding Path=ChangeWriteMissionCommand}" /> <Button Content="切换写航点" Margin="5" Command="{Binding Path=ChangeWriteMissionCommand}" />
@ -142,21 +145,44 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Grid.Row="3" Grid.Row="3"
Grid.ColumnSpan="3"> Grid.ColumnSpan="3">
<Label Content="ID:"/>
<TextBox Margin="2,5,5,5" Width="30" Text="{Binding CopterNum}"></TextBox> <TextBox Margin="2,5,5,5" Width="30" Text="{Binding CopterNum}"></TextBox>
<Button Content=" 对频 " Margin="5,5,0,5" Command="{Binding Path=WriteIdCommand}" /> <Button Content=" 对频 " Margin="5,5,0,5" Command="{Binding Path=WriteIdCommand}" />
<Button Content="闪灯" Margin="5" Command="{Binding CommDataAsync}"/> <Button Content=" 闪灯 " Margin="5" Command="{Binding CommDataAsync}"/>
<TextBox Width="80" Text="{Binding CopterColor}"/> <TextBox Width="80" Text="{Binding CopterColor}"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Grid.Row="4" Grid.Row="4"
Grid.ColumnSpan="3">
<Button Content="设置回传功率" Command="{Binding CommSetPowerAsync}"/>
<TextBox Margin="5,0" Width="80" Text="{Binding TransmittedPower}"/>
<Button Margin="5,0" Content="读取配置" Command="{Binding CommGetCurrSysParmAsync}"/>
<Button Margin="5,0" Content="™写入配置" Command="{Binding CommSetCurrSysParmAsync}"/>
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
Grid.Row="5"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
Name="panel3"> Name="panel3">
<Button Content="空中升级" Margin="5" Command="{Binding UpdateAllCopterCommand}"></Button> <Button Content="空中升级" Margin="5" Command="{Binding UpdateAllCopterCommand}"></Button>
<Button Content="搜索飞机" Margin="5" Command="{Binding QueryAllCopterCommand}"/> <Button Content="搜索飞机" Margin="5" Command="{Binding QueryAllCopterCommand}"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
Grid.Row="6"
Grid.ColumnSpan="3"
>
<Button Content="设置总数" Margin="5" Command="{Binding Path=SendCommand}" />
<Label Content="总数:"/>
<TextBox Width="50" Text="{Binding CopterCount}"/>
<Label Content="起始号:"/>
<TextBox Width="50" Text="{Binding CopterStartNum}"/>
</StackPanel>
</Grid> </Grid>
</c:MetroWindow> </c:MetroWindow>