Commit bf264c4b by liulongfei

协议改变

parent 733f36f4
=================================================
=================================================
4 3 1 2
1 2 3 4
=================================================
1 2 3 4
̨ 2 1 3 4
=================================================
\ No newline at end of file
...@@ -64,7 +64,7 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -64,7 +64,7 @@ namespace VIZ.GimbalAI.Controller.Connection
{ {
provider.Execute(data); provider.Execute(data);
} }
// 下发数据 // 下发数据
SerialPortEndpointManager manager = ConnectionManager.SerialPortConnection.GetEndpointManager(this.UpEndpointManagerKey); SerialPortEndpointManager manager = ConnectionManager.SerialPortConnection.GetEndpointManager(this.UpEndpointManagerKey);
if (manager == null) if (manager == null)
......
...@@ -69,7 +69,6 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -69,7 +69,6 @@ namespace VIZ.GimbalAI.Controller.Connection
return (UInt16)(buffer[index] + (buffer[index + 1] << 8)); return (UInt16)(buffer[index] + (buffer[index + 1] << 8));
} }
/// <summary> /// <summary>
/// 获取两个字节数据的值,没有正负值 /// 获取两个字节数据的值,没有正负值
/// </summary> /// </summary>
...@@ -82,6 +81,28 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -82,6 +81,28 @@ namespace VIZ.GimbalAI.Controller.Connection
} }
/// <summary> /// <summary>
/// 获取四个字节数据的值,没有正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected UInt32 GetValue_4_NoPN(byte[] buffer, int index)
{
return (UInt32)(buffer[index] + (buffer[index + 1] << 8) + (buffer[index + 2] << 16) + (buffer[index + 3] << 24));
}
/// <summary>
/// 获取四个字节数据的值,没有正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected Int32 GetValue_4_NoPN2(byte[] buffer, int index)
{
return (Int32)(buffer[index] + (buffer[index + 1] << 8) + (buffer[index + 2] << 16) + (buffer[index + 3] << 24));
}
/// <summary>
/// 获取1个字节数据 /// 获取1个字节数据
/// </summary> /// </summary>
/// <param name="pn">符号位</param> /// <param name="pn">符号位</param>
...@@ -155,6 +176,42 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -155,6 +176,42 @@ namespace VIZ.GimbalAI.Controller.Connection
} }
/// <summary> /// <summary>
/// 获取4个字节数据
/// </summary>
/// <param name="value">值</param>
/// <returns>字节数据</returns>
protected byte[] GetBuffer_4(UInt32 value)
{
// 00000000
// 11111111
byte[] result = new byte[4];
result[0] = (byte)(value & 0b00000000000000000000000011111111);
result[1] = (byte)((value & 0b00000000000000001111111100000000) >> 8);
result[2] = (byte)((value & 0b00000000111111110000000000000000) >> 16);
result[3] = (byte)((value & 0b11111111000000000000000000000000) >> 24);
return result;
}
/// <summary>
/// 获取4个字节数据
/// </summary>
/// <param name="value">值</param>
/// <returns>字节数据</returns>
protected byte[] GetBuffer_4(Int32 value)
{
// 00000000
// 11111111
byte[] result = new byte[4];
result[0] = (byte)(value & 0b00000000000000000000000011111111);
result[1] = (byte)((value & 0b00000000000000001111111100000000) >> 8);
result[2] = (byte)((value & 0b00000000111111110000000000000000) >> 16);
result[3] = (byte)((value & 0b11111111000000000000000000000000) >> 24);
return result;
}
/// <summary>
/// 获取带PN的值 /// 获取带PN的值
/// </summary> /// </summary>
/// <param name="pn">符号位</param> /// <param name="pn">符号位</param>
......
...@@ -35,13 +35,13 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -35,13 +35,13 @@ namespace VIZ.GimbalAI.Controller.Connection
/// <summary> /// <summary>
/// 俯仰角度值 /// 俯仰角度值
/// </summary> /// </summary>
[ConnBitLength(15)] [ConnBitLength(16)]
public Int16 Vertical { get; set; } public Int16 Vertical { get; set; }
/// <summary> /// <summary>
/// 方位角度值 /// 方位角度值
/// </summary> /// </summary>
[ConnBitLength(15)] [ConnBitLength(16)]
public Int16 Horizontal { get; set; } public Int16 Horizontal { get; set; }
/// <summary> /// <summary>
...@@ -99,6 +99,36 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -99,6 +99,36 @@ namespace VIZ.GimbalAI.Controller.Connection
public UInt16 Real_Focus { get; set; } public UInt16 Real_Focus { get; set; }
/// <summary> /// <summary>
/// 方位位置值
/// </summary>
[ConnBitLength(32)]
public UInt32 Real_Horizontal { get; set; }
/// <summary>
/// 俯仰位置值
/// </summary>
[ConnBitLength(32)]
public UInt32 Real_Vertical { get; set; }
/// <summary>
/// 同步帧尾 固定值 0xAA
/// </summary>
[ConnBitLength(8)]
public byte SyncEnd_1 { get; set; }
/// <summary>
/// 同步帧尾 固定值 0xBB
/// </summary>
[ConnBitLength(8)]
public byte SyncEnd_2 { get; set; }
/// <summary>
/// 同步帧尾 固定值 0xCC
/// </summary>
[ConnBitLength(8)]
public byte SyncEnd_3 { get; set; }
/// <summary>
/// 校验和 /// 校验和
/// (序号1+……+序号52)&0xFF /// (序号1+……+序号52)&0xFF
/// </summary> /// </summary>
...@@ -152,8 +182,29 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -152,8 +182,29 @@ namespace VIZ.GimbalAI.Controller.Connection
// 焦点位置 // 焦点位置
buffer[index++] = this.GetBuffer_2_low(this.Real_Focus); buffer[index++] = this.GetBuffer_2_low(this.Real_Focus);
buffer[index++] = this.GetBuffer_2_heigh(this.Real_Focus); buffer[index++] = this.GetBuffer_2_heigh(this.Real_Focus);
// 方位位置值
byte[] buffer_real_horizontal = this.GetBuffer_4(this.Real_Horizontal);
buffer[index++] = buffer_real_horizontal[0];
buffer[index++] = buffer_real_horizontal[1];
buffer[index++] = buffer_real_horizontal[2];
buffer[index++] = buffer_real_horizontal[3];
// 俯仰位置值
byte[] buffer_real_vertical = this.GetBuffer_4(this.Real_Vertical);
buffer[index++] = buffer_real_vertical[0];
buffer[index++] = buffer_real_vertical[1];
buffer[index++] = buffer_real_vertical[2];
buffer[index++] = buffer_real_vertical[3];
// 备用 // 备用
index += 28; index += 17;
// 同步帧尾 1
buffer[index++] = this.SyncEnd_1;
// 同步帧尾 2
buffer[index++] = this.SyncEnd_2;
// 同步帧尾 3
buffer[index++] = this.SyncEnd_3;
// 校验值 // 校验值
buffer[index++] = this.Check; buffer[index++] = this.Check;
...@@ -205,8 +256,23 @@ namespace VIZ.GimbalAI.Controller.Connection ...@@ -205,8 +256,23 @@ namespace VIZ.GimbalAI.Controller.Connection
// 焦点位置 // 焦点位置
this.Real_Focus = this.GetValue_2_NoPN(buffer, index); this.Real_Focus = this.GetValue_2_NoPN(buffer, index);
index += 2; index += 2;
// 备用 1 // 方位位置值
index += 28; this.Real_Horizontal = this.GetValue_4_NoPN(buffer, index);
index += 4;
// 俯仰位置值
this.Real_Vertical = this.GetValue_4_NoPN(buffer, index);
index += 4;
// 备用
index += 17;
// 同步帧尾 1
this.SyncEnd_1 = this.GetValue_1(buffer, index++);
// 同步帧尾 2
this.SyncEnd_2 = this.GetValue_1(buffer, index++);
// 同步帧尾 3
this.SyncEnd_3 = this.GetValue_1(buffer, index++);
// 校验值 // 校验值
this.Check = buffer[index++]; this.Check = buffer[index++];
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
xmlns:resource="clr-namespace:Viz.GimbalAI.Controller.Module.Resource;assembly=Viz.GimbalAI.Controller.Module.Resource" xmlns:resource="clr-namespace:Viz.GimbalAI.Controller.Module.Resource;assembly=Viz.GimbalAI.Controller.Module.Resource"
mc:Ignorable="d" Background="White" mc:Ignorable="d" Background="White"
d:DataContext="{d:DesignInstance Type=local:MainViewModel}" d:DataContext="{d:DesignInstance Type=local:MainViewModel}"
d:DesignHeight="850" d:DesignWidth="1200"> d:DesignHeight="1000" d:DesignWidth="1200">
<UserControl.Resources> <UserControl.Resources>
<resource:GimbalPackage_down_CheckValueConverter x:Key="GimbalPackage_down_CheckValueConverter"></resource:GimbalPackage_down_CheckValueConverter> <resource:GimbalPackage_down_CheckValueConverter x:Key="GimbalPackage_down_CheckValueConverter"></resource:GimbalPackage_down_CheckValueConverter>
<resource:GimbalPackage_up_CheckValueConverter x:Key="GimbalPackage_up_CheckValueConverter"></resource:GimbalPackage_up_CheckValueConverter> <resource:GimbalPackage_up_CheckValueConverter x:Key="GimbalPackage_up_CheckValueConverter"></resource:GimbalPackage_up_CheckValueConverter>
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<common:LabelValue2 Label="命令状态:" Text1="{Binding Path=CurrentCommandStatus}" Margin="5,0,5,0"></common:LabelValue2> <common:LabelValue2 Label="命令状态:" Text1="{Binding Path=CurrentCommandStatus}" Margin="5,0,5,0"></common:LabelValue2>
<Button Content="发送测试" Width="120" Height="30" Click="Button_Click" Grid.Column="1" HorizontalAlignment="Right"></Button>
</Grid> </Grid>
</GroupBox> </GroupBox>
...@@ -185,6 +186,10 @@ ...@@ -185,6 +186,10 @@
<RowDefinition Height="40"></RowDefinition> <RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition> <RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition> <RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
...@@ -273,12 +278,40 @@ ...@@ -273,12 +278,40 @@
Text2="{Binding Path=UpData.Real_Focus}" Text2="{Binding Path=UpData.Real_Focus}"
Margin="5,0,5,0"></common:LabelValue2> Margin="5,0,5,0"></common:LabelValue2>
<!-- 方位位置值 -->
<common:LabelValue2 Grid.Row="13" Grid.Column="0" Label="方位位置值:"
Text1="{Binding Path=UpData.Real_Horizontal,StringFormat=X6}"
Text2="{Binding Path=UpData.Real_Horizontal}"
Margin="5,0,5,0"></common:LabelValue2>
<!-- 俯仰位置值 -->
<common:LabelValue2 Grid.Row="14" Grid.Column="0" Label="俯仰位置值:"
Text1="{Binding Path=UpData.Real_Vertical,StringFormat=X6}"
Text2="{Binding Path=UpData.Real_Vertical}"
Margin="5,0,5,0"></common:LabelValue2>
<!-- 同步帧尾 -->
<common:LabelValue2 Grid.Row="15" Grid.Column="0" Label="同步帧尾1:"
Text1="{Binding Path=UpData.SyncEnd_1,StringFormat=X6}"
Text2="{Binding Path=UpData.SyncEnd_1}"
Margin="5,0,5,0"></common:LabelValue2>
<common:LabelValue2 Grid.Row="15" Grid.Column="1" Label="同步帧尾2:"
Text1="{Binding Path=UpData.SyncEnd_2,StringFormat=X6}"
Text2="{Binding Path=UpData.SyncEnd_2}"
Margin="5,0,5,0"></common:LabelValue2>
<common:LabelValue2 Grid.Row="16" Grid.Column="0" Label="同步帧尾3:"
Text1="{Binding Path=UpData.SyncEnd_3,StringFormat=X6}"
Text2="{Binding Path=UpData.SyncEnd_3}"
Margin="5,0,5,0"></common:LabelValue2>
<!-- 校验和 --> <!-- 校验和 -->
<common:LabelValue2 Grid.Row="13" Grid.Column="0" Label="校验和:" <common:LabelValue2 Grid.Row="17" Grid.Column="0" Label="校验和:"
Text1="{Binding Path=UpData.Check,StringFormat=X6}" Text1="{Binding Path=UpData.Check,StringFormat=X6}"
Text2="{Binding Path=UpData.Check}" Text2="{Binding Path=UpData.Check}"
Margin="5,0,5,0"></common:LabelValue2> Margin="5,0,5,0"></common:LabelValue2>
<common:LabelValue2 Grid.Row="13" Grid.Column="1" Label="计算校验和:" <common:LabelValue2 Grid.Row="17" Grid.Column="1" Label="计算校验和:"
Text1="{Binding Path=UpData,Converter={StaticResource GimbalPackage_up_CheckValueConverter},StringFormat=X6}" Text1="{Binding Path=UpData,Converter={StaticResource GimbalPackage_up_CheckValueConverter},StringFormat=X6}"
Text2="{Binding Path=UpData,Converter={StaticResource GimbalPackage_up_CheckValueConverter}}" Text2="{Binding Path=UpData,Converter={StaticResource GimbalPackage_up_CheckValueConverter}}"
Margin="5,0,5,0"></common:LabelValue2> Margin="5,0,5,0"></common:LabelValue2>
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -12,7 +13,10 @@ using System.Windows.Media; ...@@ -12,7 +13,10 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using VIZ.Framework.Connection;
using VIZ.Framework.Core; using VIZ.Framework.Core;
using VIZ.GimbalAI.Controller.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.Module namespace VIZ.GimbalAI.Controller.Module
{ {
...@@ -27,5 +31,28 @@ namespace VIZ.GimbalAI.Controller.Module ...@@ -27,5 +31,28 @@ namespace VIZ.GimbalAI.Controller.Module
WPFHelper.BindingViewModel(this, new MainViewModel()); WPFHelper.BindingViewModel(this, new MainViewModel());
} }
private void Button_Click(object sender, RoutedEventArgs e)
{
SerialPortEndpointManager down_endpoint_manager = ConnectionManager.SerialPortConnection.GetEndpointManager(SerialPortKeys.DOWN);
GimbalPackage_up up = new GimbalPackage_up();
up.SyncHead_1 = 0x58;
up.SyncHead_2 = 0xA0;
up.Command = (byte)GimbalPackage_Commands.Normal;
up.Vertical = 100;
up.Horizontal = 100;
up.Zoom = 100;
up.Aperture = 100;
up.Focus = 100;
up.Roll = 100;
up.Real_Horizontal_Angle = -60;
up.Real_Vertical_Angle = 60;
up.Check = up.GetCheckValue();
byte[] buffer = up.ToBuffer();
down_endpoint_manager.Send(buffer);
}
} }
} }
...@@ -63,6 +63,8 @@ namespace VIZ.GimbalAI.Controller.UnitTest ...@@ -63,6 +63,8 @@ namespace VIZ.GimbalAI.Controller.UnitTest
up.Roll = 1000; up.Roll = 1000;
up.Real_Horizontal_Angle = -60; up.Real_Horizontal_Angle = -60;
up.Real_Vertical_Angle = 60; up.Real_Vertical_Angle = 60;
up.Real_Horizontal = 1000;
up.Real_Vertical = 500;
up.Check = up.GetCheckValue(); up.Check = up.GetCheckValue();
byte[] buffer = up.ToBuffer(); byte[] buffer = up.ToBuffer();
......
...@@ -57,6 +57,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VIZ.GimbalAI.Controller.Con ...@@ -57,6 +57,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VIZ.GimbalAI.Controller.Con
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Viz.GimbalAI.Controller.Module.Resource", "Viz.GimbalAI.Controller.Module.Resource\Viz.GimbalAI.Controller.Module.Resource.csproj", "{0A9657ED-FDF9-48B7-8B78-A94814EC211F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Viz.GimbalAI.Controller.Module.Resource", "Viz.GimbalAI.Controller.Module.Resource\Viz.GimbalAI.Controller.Module.Resource.csproj", "{0A9657ED-FDF9-48B7-8B78-A94814EC211F}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "05-Doc", "05-Doc", "{BD74E48A-3E90-4280-8422-9CA78FD2E149}"
ProjectSection(SolutionItems) = preProject
Doc\云台连接线.txt = Doc\云台连接线.txt
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:VIZ.GimbalAI.Controller" xmlns:local="clr-namespace:VIZ.GimbalAI.Controller"
xmlns:module="clr-namespace:VIZ.GimbalAI.Controller.Module;assembly=VIZ.GimbalAI.Controller.Module" xmlns:module="clr-namespace:VIZ.GimbalAI.Controller.Module;assembly=VIZ.GimbalAI.Controller.Module"
mc:Ignorable="d" WindowStartupLocation="CenterScreen" mc:Ignorable="d" WindowStartupLocation="CenterScreen"
Title="智能云台控制器" Height="900" Width="1200"> Title="智能云台控制器" Height="1050" Width="1200">
<Grid> <Grid>
<module:MainView Margin="20"></module:MainView> <module:MainView Margin="20"></module:MainView>
</Grid> </Grid>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment