Commit ec03b6e5 by liulongfei

1. 上行数据解析

2. 下行数据接恶习
3. 上行下行数据展示界面制作
4. 项目逻辑
parent 41385b86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Connection;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台包解析器 -- 下行
/// </summary>
/// <remarks>
/// 1. 下行数据不保留当前状态,需要本程序保留当前状态
/// 2. 发送 0x00 指令清除当前状态
/// </remarks>
public class GimbalPackageDownProvider : ConnFixedBufferPackageProvider
{
/// <summary>
/// 云台包解析器
/// </summary>
/// <param name="fixedBufferSize">包大小</param>
/// <param name="downEndpointManagerKey">下行终结点管理器键</param>
public GimbalPackageDownProvider(int fixedBufferSize, string downEndpointManagerKey) : base(fixedBufferSize)
{
this.DownEndpointManagerKey = downEndpointManagerKey;
}
/// <summary>
/// 下行终结点管理器键
/// </summary>
public string DownEndpointManagerKey { get; private set; }
/// <summary>
/// 处理器集合
/// </summary>
private List<IGimbalDownProvider> providers = new List<IGimbalDownProvider>();
/// <summary>
/// 执行
/// </summary>
/// <param name="info">信息</param>
protected override void Execute(ConnFixedBufferInfo info)
{
// 解析数据
GimbalPackage_down data = new GimbalPackage_down();
data.FromBuffer(info.Buffer);
// 处理数据
foreach (IGimbalDownProvider provider in this.providers)
{
provider.Execute(data);
}
// 下发数据
SerialPortEndpointManager manager = ConnectionManager.SerialPortConnection.GetEndpointManager(this.DownEndpointManagerKey);
if (manager == null)
return;
byte[] buffer = data.ToBuffer();
manager.Send(buffer);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Connection;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台包解析器 上行
/// </summary>
/// <remarks>
/// 1. 上行数据保留有状态
/// </remarks>
public class GimbalPackageUpProvider : ConnFixedBufferPackageProvider
{
/// <summary>
/// 云台包解析器
/// </summary>
/// <param name="fixedBufferSize">包大小</param>
/// <param name="upEndpointManagerKey">上行终结点管理器键</param>
public GimbalPackageUpProvider(int fixedBufferSize, string upEndpointManagerKey) : base(fixedBufferSize)
{
this.UpEndpointManagerKey = upEndpointManagerKey;
}
/// <summary>
/// 上行终结点管理器键
/// </summary>
public string UpEndpointManagerKey { get; private set; }
/// <summary>
/// 处理器集合
/// </summary>
private List<IGimbalUpProvider> providers = new List<IGimbalUpProvider>();
/// <summary>
/// 执行
/// </summary>
/// <param name="info">信息</param>
protected override void Execute(ConnFixedBufferInfo info)
{
// 解析数据
GimbalPackage_up data = new GimbalPackage_up();
data.FromBuffer(info.Buffer);
// 处理数据
foreach (IGimbalUpProvider provider in this.providers)
{
provider.Execute(data);
}
// 上发数据
SerialPortEndpointManager manager = ConnectionManager.SerialPortConnection.GetEndpointManager(this.UpEndpointManagerKey);
if (manager == null)
return;
byte[] buffer = data.ToBuffer();
manager.Send(buffer);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台解析器 -- 下行
/// </summary>
public interface IGimbalDownProvider
{
/// <summary>
/// 执行
/// </summary>
/// <param name="data">数据</param>
void Execute(GimbalPackage_down data);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台数据包序列化
/// </summary>
public interface IGimbalPackageSerialize
{
/// <summary>
/// 将对象转化为二进制数据
/// </summary>
/// <returns>二进制数据</returns>
byte[] ToBuffer();
/// <summary>
/// 从二进制数据中获取数据
/// </summary>
/// <param name="buffer">二进制数据</param>
void FromBuffer(byte[] buffer);
/// <summary>
/// 获取校验值
/// </summary>
/// <returns>是否通过校验</returns>
byte GetCheckValue();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台解析器 -- 上行
/// </summary>
public interface IGimbalUpProvider
{
/// <summary>
/// 执行
/// </summary>
/// <param name="data">数据</param>
void Execute(GimbalPackage_up data);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Connection;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台下行数据包
/// </summary>
public class GimbalPackage_down : GimbalPackageBase
{
/// <summary>
/// 同步帧头 固定值 0xA5
/// </summary>
[ConnBitLength(8)]
public byte SyncHead_1 { get; set; }
/// <summary>
/// 同步帧头 固定值 0xE7
/// </summary>
[ConnBitLength(8)]
public byte SyncHead_2 { get; set; }
/// <summary>
/// 命令正反装指令
/// 0 -- 正装 | 1 -- 负装
/// </summary>
[ConnBitLength(1)]
public byte Command_PN { get; set; }
/// <summary>
/// 命令 指令
/// <see cref="GimbalPackage_Commands"/>
/// </summary>
[ConnBitLength(7)]
public byte Command { get; set; }
/// <summary>
/// 俯仰值方向
/// 0 -- 正数 | 1 -- 负数
/// </summary>
[ConnBitLength(1)]
public byte Vertical_PN { get; set; }
/// <summary>
/// 俯仰值
/// </summary>
[ConnBitLength(15)]
public UInt16 Vertical { get; set; }
/// <summary>
/// 方位值方向
/// 0 -- 正数 | 1 -- 负数
/// </summary>
[ConnBitLength(1)]
public byte Horizontal_PN { get; set; }
/// <summary>
/// 方位值
/// </summary>
[ConnBitLength(15)]
public UInt16 Horizontal { get; set; }
/// <summary>
/// 横滚控制
/// </summary>
[ConnBitLength(16)]
public UInt16 Roll { get; set; }
/// <summary>
/// 变焦控制
/// </summary>
[ConnBitLength(16)]
public UInt16 Zoom { get; set; }
/// <summary>
/// 光圈
/// </summary>
[ConnBitLength(16)]
public UInt16 Aperture { get; set; }
/// <summary>
/// 聚焦
/// </summary>
[ConnBitLength(16)]
public UInt16 Focus { get; set; }
/// <summary>
/// 品牌
/// </summary>
[ConnBitLength(8)]
public byte Brand { get; set; }
/// <summary>
/// 跟踪俯仰值方向
/// 0 -- 正数 | 1 -- 负数
/// </summary>
[ConnBitLength(1)]
public byte Track_Vertical_PN { get; set; }
/// <summary>
/// 跟踪俯仰值
/// </summary>
[ConnBitLength(15)]
public UInt16 Track_Vertical { get; set; }
/// <summary>
/// 跟踪方位值方向
/// 0 -- 正数 | 1 -- 负数
/// </summary>
[ConnBitLength(1)]
public byte Track_Horizontal_PN { get; set; }
/// <summary>
/// 跟踪方位值
/// </summary>
[ConnBitLength(15)]
public UInt16 Track_Horizontal { get; set; }
/// <summary>
/// 心跳
/// </summary>
[ConnBitLength(8)]
public byte Heart { get; set; }
/// <summary>
/// 校验和
/// (序号1+……+序号52)&0xFF
/// </summary>
[ConnBitLength(8)]
public byte Check { get; set; }
/// <summary>
/// 将对象转化为二进制数据
/// </summary>
/// <returns>二进制数据</returns>
public override byte[] ToBuffer()
{
byte[] buffer = new byte[53];
int index = 0;
// 同步帧头 1
buffer[index++] = this.SyncHead_1;
// 同步帧头 2
buffer[index++] = this.SyncHead_2;
// 命令字
buffer[index++] = this.GetBuffer_1(this.Command_PN, this.Command);
// 俯仰
buffer[index++] = this.GetBuffer_2_low(this.Vertical_PN, this.Vertical);
buffer[index++] = this.GetBuffer_2_heigh(this.Vertical_PN, this.Vertical);
// 方位
buffer[index++] = this.GetBuffer_2_low(this.Horizontal_PN, this.Horizontal);
buffer[index++] = this.GetBuffer_2_heigh(this.Horizontal_PN, this.Horizontal);
// 横滚
buffer[index++] = this.GetBuffer_2_low(this.Roll);
buffer[index++] = this.GetBuffer_2_heigh(this.Roll);
// 变焦
buffer[index++] = this.GetBuffer_2_low(this.Zoom);
buffer[index++] = this.GetBuffer_2_heigh(this.Zoom);
// 光圈
buffer[index++] = this.GetBuffer_2_low(this.Aperture);
buffer[index++] = this.GetBuffer_2_heigh(this.Aperture);
// 聚焦
buffer[index++] = this.GetBuffer_2_low(this.Focus);
buffer[index++] = this.GetBuffer_2_heigh(this.Focus);
// 品牌
buffer[index++] = this.Brand;
// 跟踪俯仰
buffer[index++] = this.GetBuffer_2_low(this.Track_Vertical_PN, this.Track_Vertical);
buffer[index++] = this.GetBuffer_2_heigh(this.Track_Vertical_PN, this.Track_Vertical);
// 跟踪方位
buffer[index++] = this.GetBuffer_2_low(this.Track_Horizontal_PN, this.Track_Horizontal);
buffer[index++] = this.GetBuffer_2_heigh(this.Track_Horizontal_PN, this.Track_Horizontal);
// 备用
index += 31;
// 心跳
buffer[index++] = this.Heart;
// 校验值
buffer[index++] = this.Check;
return buffer;
}
/// <summary>
/// 从二进制数据中获取数据
/// </summary>
/// <param name="buffer">二进制数据</param>
public override void FromBuffer(byte[] buffer)
{
int index = 0;
// 同步帧头 1
this.SyncHead_1 = buffer[index++];
// 同步帧头 2
this.SyncHead_2 = buffer[index++];
// 命令字
this.Command_PN = this.GetPN_1(buffer, index);
this.Command = this.GetValue_1(buffer, index);
index += 1;
// 俯仰
this.Vertical_PN = this.GetPN_2(buffer, index);
this.Vertical = this.GetValue_2(buffer, index);
index += 2;
// 方位
this.Horizontal_PN = this.GetPN_2(buffer, index);
this.Horizontal = this.GetValue_2(buffer, index);
index += 2;
// 横滚
this.Roll = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 变焦
this.Zoom = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 光圈
this.Aperture = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 聚焦
this.Focus = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 品牌
this.Brand = buffer[index++];
// 跟踪俯仰
this.Track_Vertical_PN = this.GetPN_2(buffer, index);
this.Track_Vertical = this.GetValue_2(buffer, index);
index += 2;
// 跟踪方位
this.Track_Horizontal_PN = this.GetPN_2(buffer, index);
this.Track_Horizontal = this.GetValue_2(buffer, index);
index += 2;
// 备用
index += 31;
// 心跳
this.Heart = buffer[index++];
// 校验值
this.Check = buffer[index++];
}
/// <summary>
/// 获取校验值
/// </summary>
/// <returns>是否通过校验</returns>
public override byte GetCheckValue()
{
long sum = 0;
// 同步帧头 1
sum += this.SyncHead_1;
// 同步帧头 2
sum += this.SyncHead_2;
// 命令字
sum += this.GetValueWithPN(this.Command_PN, this.Command);
// 俯仰
sum += this.GetValueWithPN(this.Vertical_PN, this.Vertical);
// 方位
sum += this.GetValueWithPN(this.Horizontal_PN, this.Horizontal);
// 横滚
sum += this.Roll;
// 变焦
sum += this.Zoom;
// 光圈
sum += this.Aperture;
// 聚焦
sum += this.Focus;
// 品牌
sum += this.Brand;
// 跟踪俯仰
sum += this.GetValueWithPN(this.Track_Vertical_PN, this.Track_Vertical);
// 跟踪方位
sum += this.GetValueWithPN(this.Track_Horizontal_PN, this.Track_Horizontal);
// 备用
// 心跳
sum += this.Heart;
return (byte)(sum & 0xFF);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台数据包基类
/// </summary>
public abstract class GimbalPackageBase : IGimbalPackageSerialize
{
/// <summary>
/// 获取一个字节数据的正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <returns>当前位序</returns>
protected byte GetPN_1(byte[] buffer, int index)
{
return (byte)((buffer[index] & 0b10000000) >> 7);
}
/// <summary>
/// 获取一个字节数据的值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected byte GetValue_1(byte[] buffer, int index)
{
return (byte)(buffer[index] & 0b01111111);
}
/// <summary>
/// 获取两个字节数据的额正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <returns>当前位序</returns>
protected byte GetPN_2(byte[] buffer, int index)
{
return (byte)((buffer[index + 1] & 0b10000000) >> 7);
}
/// <summary>
/// 获取两个字节数据的值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected UInt16 GetValue_2(byte[] buffer, int index)
{
return (UInt16)(buffer[index] + ((buffer[index + 1] & 0b01111111) << 8));
}
/// <summary>
/// 获取两个字节数据的值,没有正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected UInt16 GetValue_2_NoPN(byte[] buffer, int index)
{
return (UInt16)(buffer[index] + (buffer[index + 1] << 8));
}
/// <summary>
/// 获取两个字节数据的值,没有正负值
/// </summary>
/// <param name="buffer">Buffer</param>
/// <param name="index">当前位序</param>
/// <returns>值</returns>
protected Int16 GetValue_2_NoPN2(byte[] buffer, int index)
{
return (Int16)(buffer[index] + (buffer[index + 1] << 8));
}
/// <summary>
/// 获取1个字节数据
/// </summary>
/// <param name="pn">符号位</param>
/// <param name="value">值</param>
/// <returns>字节数据</returns>
protected byte GetBuffer_1(byte pn, byte value)
{
return (byte)(((UInt16)pn << 7) + value);
}
/// <summary>
/// 获取2个字节数据的低位
/// </summary>
/// <param name="pn">符号</param>
/// <param name="value">值</param>
/// <returns>低位字节</returns>
protected byte GetBuffer_2_low(byte pn, UInt16 value)
{
return (byte)((value + (pn << 15)) & 0b0000000011111111);
}
/// <summary>
/// 获取2个字节数据的高位
/// </summary>
/// <param name="pn">符号</param>
/// <param name="value">值</param>
/// <returns>高位字节</returns>
protected byte GetBuffer_2_heigh(byte pn, UInt16 value)
{
return (byte)(((value + (pn << 15)) & 0b1111111100000000) >> 8);
}
/// <summary>
/// 获取2个字节数据的低位
/// </summary>
/// <param name="value">值</param>
/// <returns>低位字节</returns>
protected byte GetBuffer_2_low(UInt16 value)
{
return (byte)(value & 0b0000000011111111);
}
/// <summary>
/// 获取2个字节数据的高位
/// </summary>
/// <param name="value">值</param>
/// <returns>高位数据</returns>
protected byte GetBuffer_2_heigh(UInt16 value)
{
return (byte)((value & 0b1111111100000000) >> 8);
}
/// <summary>
/// 获取2个字节数据的低位
/// </summary>
/// <param name="value">值</param>
/// <returns>低位字节</returns>
protected byte GetBuffer_2_low(Int16 value)
{
return (byte)(value & 0b0000000011111111);
}
/// <summary>
/// 获取2个字节数据的高位
/// </summary>
/// <param name="value">值</param>
/// <returns>高位数据</returns>
protected byte GetBuffer_2_heigh(Int16 value)
{
return (byte)((value & 0b1111111100000000) >> 8);
}
/// <summary>
/// 获取带PN的值
/// </summary>
/// <param name="pn">符号位</param>
/// <param name="value">值</param>
/// <returns>带PN的值</returns>
protected UInt16 GetValueWithPN(byte pn, byte value)
{
return (UInt16)((pn << 7) + value);
}
/// <summary>
/// 获取带PN的值
/// </summary>
/// <param name="pn">符号位</param>
/// <param name="value">值</param>
/// <returns>带PN的值</returns>
protected UInt16 GetValueWithPN(byte pn, UInt16 value)
{
return (UInt16)(value + ((UInt16)(pn) << 15));
}
/// <summary>
/// 将对象转化为二进制数据
/// </summary>
/// <returns>二进制数据</returns>
public abstract byte[] ToBuffer();
/// <summary>
/// 从二进制数据中获取数据
/// </summary>
/// <param name="buffer">二进制数据</param>
public abstract void FromBuffer(byte[] buffer);
/// <summary>
/// 获取校验值
/// </summary>
/// <returns>是否通过校验</returns>
public abstract byte GetCheckValue();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.Connection
{
/// <summary>
/// 云台上行数据包
/// </summary>
public class GimbalPackage_up : GimbalPackageBase
{
/// <summary>
/// 同步帧头 固定值 0x58
/// </summary>
[ConnBitLength(8)]
public byte SyncHead_1 { get; set; }
/// <summary>
/// 同步帧头 固定值 0xA0
/// </summary>
[ConnBitLength(8)]
public byte SyncHead_2 { get; set; }
/// <summary>
/// 状态字
/// <see cref="GimbalPackage_Commands"/>
/// </summary>
[ConnBitLength(8)]
public byte Command { get; set; }
/// <summary>
/// 俯仰角度值
/// </summary>
[ConnBitLength(15)]
public Int16 Vertical { get; set; }
/// <summary>
/// 方位角度值
/// </summary>
[ConnBitLength(15)]
public Int16 Horizontal { get; set; }
/// <summary>
/// 横滚角度值
/// </summary>
[ConnBitLength(16)]
public Int16 Roll { get; set; }
/// <summary>
/// 变焦值
/// </summary>
[ConnBitLength(16)]
public UInt16 Zoom { get; set; }
/// <summary>
/// 光圈值
/// </summary>
[ConnBitLength(16)]
public UInt16 Aperture { get; set; }
/// <summary>
/// 聚焦值
/// </summary>
[ConnBitLength(16)]
public UInt16 Focus { get; set; }
/// <summary>
/// 心跳指令
/// </summary>
[ConnBitLength(8)]
public byte Heart { get; set; }
/// <summary>
/// 处理后的俯仰角
/// </summary>
[ConnBitLength(16)]
public Int16 Real_Vertical_Angle { get; set; }
/// <summary>
/// 处理后的方位角
/// </summary>
[ConnBitLength(16)]
public Int16 Real_Horizontal_Angle { get; set; }
/// <summary>
/// 处理后的变焦值
/// </summary>
[ConnBitLength(16)]
public UInt16 Real_Zoom { get; set; }
/// <summary>
/// 处理后的焦点位置
/// </summary>
[ConnBitLength(16)]
public UInt16 Real_Focus { get; set; }
/// <summary>
/// 校验和
/// (序号1+……+序号52)&0xFF
/// </summary>
[ConnBitLength(8)]
public byte Check { get; set; }
/// <summary>
/// 将对象转化为二进制数据
/// </summary>
/// <returns>二进制数据</returns>
public override byte[] ToBuffer()
{
byte[] buffer = new byte[53];
int index = 0;
// 同步帧头 1
buffer[index++] = this.SyncHead_1;
// 同步帧头 2
buffer[index++] = this.SyncHead_2;
// 命令字
buffer[index++] = this.Command;
// 俯仰
buffer[index++] = this.GetBuffer_2_low(this.Vertical);
buffer[index++] = this.GetBuffer_2_heigh(this.Vertical);
// 方位
buffer[index++] = this.GetBuffer_2_low(this.Horizontal);
buffer[index++] = this.GetBuffer_2_heigh(this.Horizontal);
// 横滚
buffer[index++] = this.GetBuffer_2_low(this.Roll);
buffer[index++] = this.GetBuffer_2_heigh(this.Roll);
// 变焦
buffer[index++] = this.GetBuffer_2_low(this.Zoom);
buffer[index++] = this.GetBuffer_2_heigh(this.Zoom);
// 光圈
buffer[index++] = this.GetBuffer_2_low(this.Aperture);
buffer[index++] = this.GetBuffer_2_heigh(this.Aperture);
// 聚焦
buffer[index++] = this.GetBuffer_2_low(this.Focus);
buffer[index++] = this.GetBuffer_2_heigh(this.Focus);
// 心跳
buffer[index++] = this.Heart;
// 处理后的俯仰角度值
buffer[index++] = this.GetBuffer_2_low(this.Real_Vertical_Angle);
buffer[index++] = this.GetBuffer_2_heigh(this.Real_Vertical_Angle);
// 处理后的方位角度值
buffer[index++] = this.GetBuffer_2_low(this.Real_Horizontal_Angle);
buffer[index++] = this.GetBuffer_2_heigh(this.Real_Horizontal_Angle);
// 变焦值
buffer[index++] = this.GetBuffer_2_low(this.Real_Zoom);
buffer[index++] = this.GetBuffer_2_heigh(this.Real_Zoom);
// 焦点位置
buffer[index++] = this.GetBuffer_2_low(this.Real_Focus);
buffer[index++] = this.GetBuffer_2_heigh(this.Real_Focus);
// 备用
index += 28;
// 校验值
buffer[index++] = this.Check;
return buffer;
}
/// <summary>
/// 从二进制数据中获取数据
/// </summary>
/// <param name="buffer">二进制数据</param>
public override void FromBuffer(byte[] buffer)
{
int index = 0;
// 同步帧头 1
this.SyncHead_1 = buffer[index++];
// 同步帧头 2
this.SyncHead_2 = buffer[index++];
// 命令字
this.Command = buffer[index++];
// 俯仰
this.Vertical = this.GetValue_2_NoPN2(buffer, index);
index += 2;
// 方位
this.Horizontal = this.GetValue_2_NoPN2(buffer, index);
index += 2;
// 横滚
this.Roll = this.GetValue_2_NoPN2(buffer, index);
index += 2;
// 变焦
this.Zoom = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 光圈
this.Aperture = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 聚焦
this.Focus = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 心跳
this.Heart = buffer[index++];
// 处理后的俯仰角度值
this.Real_Vertical_Angle = this.GetValue_2_NoPN2(buffer, index);
index += 2;
// 处理后的方位角度值
this.Real_Horizontal_Angle = this.GetValue_2_NoPN2(buffer, index);
index += 2;
// 变焦值
this.Real_Zoom = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 焦点位置
this.Real_Focus = this.GetValue_2_NoPN(buffer, index);
index += 2;
// 备用 1
index += 28;
// 校验值
this.Check = buffer[index++];
}
/// <summary>
/// 获取校验值
/// </summary>
/// <returns>是否通过校验</returns>
public override byte GetCheckValue()
{
long sum = 0;
// 同步帧头 1
sum += this.SyncHead_1;
// 同步帧头 2
sum += this.SyncHead_2;
// 命令字
sum += this.Command;
// 俯仰
sum += this.Vertical;
// 方位
sum += this.Horizontal;
// 横滚
sum += this.Roll;
// 变焦
sum += this.Zoom;
// 光圈
sum += this.Aperture;
// 聚焦
sum += this.Focus;
// 心跳
sum += this.Heart;
// 处理后的俯仰角度值
sum += this.Real_Vertical_Angle;
// 处理后的方位角度值
sum += this.Real_Horizontal_Angle;
// 变焦值
sum += this.Real_Zoom;
// 焦点位置
sum += this.Real_Focus;
// 备用 1
return (byte)(sum & 0xFF);
}
}
}
......@@ -49,8 +49,16 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -60,6 +68,41 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerialPort\Gimbal\GimbalPackageUpProvider.cs" />
<Compile Include="SerialPort\Gimbal\GimbalPackageDownProvider.cs" />
<Compile Include="SerialPort\Gimbal\IGimbalUpProvider.cs" />
<Compile Include="SerialPort\Gimbal\IGimbalDownProvider.cs" />
<Compile Include="SerialPort\Gimbal\IGimbalPackageSerialize.cs" />
<Compile Include="SerialPort\Gimbal\Signal\Down\GimbalPackage_down.cs" />
<Compile Include="SerialPort\Gimbal\Signal\GimbalPackageBase.cs" />
<Compile Include="SerialPort\Gimbal\Signal\Up\GimbalPackage_up.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Connection\VIZ.Framework.Connection.csproj">
<Project>{e07528dd-9dee-47c2-b79d-235ecfa6b003}</Project>
<Name>VIZ.Framework.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661e82-c86a-4611-a028-c34f6ac85c97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Domain\VIZ.GimbalAI.Controller.Domain.csproj">
<Project>{B41ABF07-77AB-4373-B43E-DF82FBFDA3CD}</Project>
<Name>VIZ.GimbalAI.Controller.Domain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="SerialPort\Gimbal\Enum\" />
<Folder Include="SerialPort\Gimbal\Provider\Down\" />
<Folder Include="SerialPort\Gimbal\Provider\Up\" />
<Folder Include="SerialPort\Gimbal\Sender\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
</packages>
\ No newline at end of file
......@@ -49,8 +49,13 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -61,5 +66,8 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
</packages>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Controller.Domain
{
/// <summary>
/// 应用程序域
/// </summary>
public class ApplicationDomainEx : ApplicationDomain
{
/// <summary>
/// 当前云台命令状态
/// </summary>
public static GimbalPackage_Commands CurrentGimbalCommandStatus { get; set; } = GimbalPackage_Commands.None;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Controller.Domain
{
/// <summary>
/// 云台指令命令信号
/// </summary>
public enum GimbalPackage_Commands : byte
{
/// <summary>
/// 清除指令
/// </summary>
[Description("清除")]
None = 0x00,
/// <summary>
/// 正常操作
/// </summary>
[Description("正常")]
Normal = 0x01,
/// <summary>
/// 回零指令
/// </summary>
[Description("回零")]
Home = 0x03,
/// <summary>
/// 跟踪指令
/// </summary>
[Description("跟踪")]
Track = 0x05,
/// <summary>
/// 使能指令
/// </summary>
[Description("使能")]
En = 0x08,
}
}
......@@ -59,7 +59,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationDomainEx.cs" />
<Compile Include="Enum\GimbalPackage_Commands.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661E82-C86A-4611-A028-C34F6AC85C97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using VIZ.Framework.Connection;
using VIZ.Framework.Core;
using VIZ.GimbalAI.Controller.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.Module
{
/// <summary>
/// 云台信号保存控制器
/// </summary>
public class GimbalSignalSaveController
{
/// <summary>
/// 云台信号保存控制器
/// </summary>
/// <param name="support">支持</param>
public GimbalSignalSaveController(IGimbalSignalSaveSupport support)
{
this.Support = support;
}
/// <summary>
/// 支持
/// </summary>
public IGimbalSignalSaveSupport Support { get; private set; }
/// <summary>
/// 消息队列
/// </summary>
public ConcurrentQueue<ConnFixedBufferMessage> MessageQueue { get; private set; } = new ConcurrentQueue<ConnFixedBufferMessage>();
/// <summary>
/// 是否正在执行
/// </summary>
public bool IsRunning { get; private set; }
/// <summary>
/// 处理线程
/// </summary>
private System.Threading.Thread thread;
/// <summary>
/// 文件流
/// </summary>
private FileStream fileStream;
/// <summary>
/// 启动
/// </summary>
public void Start()
{
string floder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
if (!Directory.Exists(floder))
{
Directory.CreateDirectory(floder);
}
string path = Path.Combine(floder, $"data_{DateTime.Now.ToString("yyyy_MM_dd___HH_mm_ss")}.json");
this.fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
this.IsRunning = true;
this.thread = new System.Threading.Thread(this.Execute);
this.thread.IsBackground = true;
this.thread.Start();
}
/// <summary>
/// 停止
/// </summary>
public void Stop()
{
this.fileStream?.Flush();
this.fileStream?.Close();
this.fileStream?.Dispose();
this.fileStream = null;
this.IsRunning = false;
this.thread = null;
}
/// <summary>
/// 执行
/// </summary>
private void Execute()
{
while (this.IsRunning)
{
System.Threading.Thread.Sleep(500);
bool isUpdateUI_down = false;
bool isUpdateUI_up = false;
while (this.MessageQueue.Count > 0)
{
if (!this.MessageQueue.TryDequeue(out ConnFixedBufferMessage msg))
continue;
// 记录日志
GimbalPackage_down down;
GimbalPackage_up up;
this.Save(msg, out down, out up);
// 更新界面
if (!isUpdateUI_down && down != null)
{
isUpdateUI_down = true;
WPFHelper.BeginInvoke(() =>
{
this.Support.DownData = down;
this.Support.CurrentCommandStatus = ApplicationDomainEx.CurrentGimbalCommandStatus;
});
}
if (!isUpdateUI_up && up != null)
{
isUpdateUI_up = true;
WPFHelper.BeginInvoke(() =>
{
this.Support.UpData = up;
this.Support.CurrentCommandStatus = ApplicationDomainEx.CurrentGimbalCommandStatus;
});
}
}
this.fileStream?.Flush();
}
}
/// <summary>
/// 保存消息
/// </summary>
/// <param name="msg"></param>
private void Save(ConnFixedBufferMessage msg, out GimbalPackage_down down, out GimbalPackage_up up)
{
down = null;
up = null;
if (msg.Provider is GimbalPackageDownProvider)
{
// 下行数据
GimbalPackage_down data = new GimbalPackage_down();
data.FromBuffer(msg.Buffer);
string json = JsonConvert.SerializeObject(data);
json += "\n";
byte[] buffer = Encoding.UTF8.GetBytes(json);
this.fileStream?.Write(buffer, 0, buffer.Length);
down = data;
}
else if (msg.Provider is GimbalPackageUpProvider)
{
// 上行数据
GimbalPackage_up data = new GimbalPackage_up();
data.FromBuffer(msg.Buffer);
string json = JsonConvert.SerializeObject(data);
json += "\n";
byte[] buffer = Encoding.UTF8.GetBytes(json);
this.fileStream?.Write(buffer, 0, buffer.Length);
up = data;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.GimbalAI.Controller.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.Module
{
/// <summary>
/// 云台信号保存支持
/// </summary>
public interface IGimbalSignalSaveSupport
{
/// <summary>
/// 下行数据
/// </summary>
GimbalPackage_down DownData { get; set; }
/// <summary>
/// 上行数据
/// </summary>
GimbalPackage_up UpData { get; set; }
/// <summary>
/// 当前命令状态
/// </summary>
GimbalPackage_Commands CurrentCommandStatus { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.GimbalAI.Controller.Module
{
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new MainViewModel());
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Connection;
using VIZ.Framework.Core;
using VIZ.Framework.Module;
using VIZ.GimbalAI.Controller.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.Module
{
/// <summary>
/// 主视图模型
/// </summary>
public class MainViewModel : ViewModelBase, IGimbalSignalSaveSupport
{
public MainViewModel()
{
// 初始化命令
this.InitCommand();
// 初始化消息
this.InitMessage();
// 初始化控制器
this.InitController();
}
/// <summary>
/// 初始化命令
/// </summary>
private void InitCommand()
{
this.OpenDataFolderCommand = new VCommand(this.OpenDataFolder);
}
/// <summary>
/// 初始化消息
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<AppShutDownMessage>(this, this.OnAppShutDownMessage);
ApplicationDomainEx.MessageManager.Register<ConnFixedBufferMessage>(this, this.OnConnFixedBufferMessage);
}
/// <summary>
/// 初始化控制器
/// </summary>
private void InitController()
{
this.GimbalSignalSaveController = new GimbalSignalSaveController(this);
this.GimbalSignalSaveController.Start();
}
/// <summary>
/// 云台信号保存控制器
/// </summary>
private GimbalSignalSaveController GimbalSignalSaveController;
// ------------------------------------------------------------------------------------
// Property
// ------------------------------------------------------------------------------------
#region CurrentCommandStatus -- 当前命令状态
private GimbalPackage_Commands currentCommandStatus;
/// <summary>
/// 当前命令状态
/// </summary>
public GimbalPackage_Commands CurrentCommandStatus
{
get { return currentCommandStatus; }
set { currentCommandStatus = value; this.RaisePropertyChanged(nameof(CurrentCommandStatus)); }
}
#endregion
#region DownData -- 下行数据
private GimbalPackage_down downData;
/// <summary>
/// 下行数据
/// </summary>
public GimbalPackage_down DownData
{
get { return downData; }
set { downData = value; this.RaisePropertyChanged(nameof(DownData)); }
}
#endregion
#region UpData -- 上行数据
private GimbalPackage_up upData;
/// <summary>
/// 上行数据
/// </summary>
public GimbalPackage_up UpData
{
get { return upData; }
set { upData = value; this.RaisePropertyChanged(nameof(UpData)); }
}
#endregion
// ------------------------------------------------------------------------------------
// Command
// ------------------------------------------------------------------------------------
#region OpenDataFolderCommand -- 打开数据文件夹命令
/// <summary>
/// 打开数据文件夹命令
/// </summary>
public VCommand OpenDataFolderCommand { get; set; }
/// <summary>
/// 打开数据文件夹
/// </summary>
private void OpenDataFolder()
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
if (!Directory.Exists(path))
return;
System.Diagnostics.Process.Start(path);
}
#endregion
// ------------------------------------------------------------------------------------
// Message
// ------------------------------------------------------------------------------------
/// <summary>
/// 应用程序停止消息
/// </summary>
/// <param name="msg">消息</param>
private void OnAppShutDownMessage(AppShutDownMessage msg)
{
this.GimbalSignalSaveController.Stop();
}
/// <summary>
/// 处理上行 & 下行 数据消息
/// </summary>
/// <param name="msg">消息</param>
private void OnConnFixedBufferMessage(ConnFixedBufferMessage msg)
{
this.GimbalSignalSaveController.MessageQueue.Enqueue(msg);
}
// ------------------------------------------------------------------------------------
// Public Function
// ------------------------------------------------------------------------------------
}
}
......@@ -50,8 +50,16 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
......@@ -66,12 +74,22 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Page Include="MainView\View\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="MainView\Controller\GimbalSignalSaveController\GimbalSignalSaveController.cs" />
<Compile Include="MainView\Controller\GimbalSignalSaveController\IGimbalSignalSaveSupport.cs" />
<Compile Include="MainView\ViewModel\MainViewModel.cs" />
<Compile Include="MainView\View\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
......@@ -89,10 +107,61 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Common.Resource\VIZ.Framework.Common.Resource.csproj">
<Project>{76ef480a-e486-41b7-b7a5-2a849fc8d5bf}</Project>
<Name>VIZ.Framework.Common.Resource</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Common\VIZ.Framework.Common.csproj">
<Project>{92834c05-703e-4f05-9224-f36220939d8f}</Project>
<Name>VIZ.Framework.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Connection\VIZ.Framework.Connection.csproj">
<Project>{e07528dd-9dee-47c2-b79d-235ecfa6b003}</Project>
<Name>VIZ.Framework.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661e82-c86a-4611-a028-c34f6ac85c97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Module\VIZ.Framework.Module.csproj">
<Project>{47cf6fb0-e37d-4ef1-afc7-03db2bca8892}</Project>
<Name>VIZ.Framework.Module</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Storage\VIZ.Framework.Storage.csproj">
<Project>{06b80c09-343d-4bb2-aeb1-61cfbfbf5cad}</Project>
<Name>VIZ.Framework.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Connection\VIZ.GimbalAI.Controller.Connection.csproj">
<Project>{4da87ec9-2bb4-4233-9e1b-495d9b6290c6}</Project>
<Name>VIZ.GimbalAI.Controller.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Core\VIZ.GimbalAI.Controller.Core.csproj">
<Project>{51de8c1e-e026-4e0b-b6b2-4922736866a6}</Project>
<Name>VIZ.GimbalAI.Controller.Core</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Domain\VIZ.GimbalAI.Controller.Domain.csproj">
<Project>{b41abf07-77ab-4373-b43e-df82fbfda3cd}</Project>
<Name>VIZ.GimbalAI.Controller.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Storage\VIZ.GimbalAI.Controller.Storage.csproj">
<Project>{aeb04581-0586-4388-b53f-95b6482c807e}</Project>
<Name>VIZ.GimbalAI.Controller.Storage</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Setup\Provider\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
</packages>
\ No newline at end of file
......@@ -49,8 +49,13 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -61,5 +66,8 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
</packages>
\ No newline at end of file
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using VIZ.Framework.Connection;
using VIZ.GimbalAI.Controller.Connection;
using VIZ.GimbalAI.Controller.Domain;
namespace VIZ.GimbalAI.Controller.UnitTest
{
/// <summary>
/// 二进制数据测试
/// </summary>
[TestClass]
public class BufferTest
{
/// <summary>
/// 下行数据测试
/// </summary>
[TestMethod]
public void DownBufferTest()
{
GimbalPackage_down down = new GimbalPackage_down();
down.SyncHead_1 = 0xA5;
down.SyncHead_2 = 0xE7;
down.Command_PN = 1;
down.Command = (byte)GimbalPackage_Commands.Home;
down.Vertical_PN = 1;
down.Vertical = 1000;
down.Horizontal_PN = 1;
down.Horizontal = 1000;
down.Track_Horizontal_PN = 1;
down.Track_Horizontal = 1000;
down.Track_Vertical_PN = 1;
down.Track_Vertical = 1000;
down.Zoom = 50;
down.Aperture = 50;
down.Focus = 50;
down.Roll = 1000;
down.Check = down.GetCheckValue();
byte[] buffer = down.ToBuffer();
GimbalPackage_down down2 = new GimbalPackage_down();
down2.FromBuffer(buffer);
}
/// <summary>
/// 上行数据测试
/// </summary>
[TestMethod]
public void UpBufferTest()
{
GimbalPackage_up up = new GimbalPackage_up();
up.SyncHead_1 = 0xA5;
up.SyncHead_2 = 0xE7;
up.Command = (byte)GimbalPackage_Commands.Home;
up.Vertical = 1000;
up.Horizontal = 1000;
up.Zoom = 50;
up.Aperture = 50;
up.Focus = 50;
up.Roll = 1000;
up.Real_Horizontal_Angle = -60;
up.Real_Vertical_Angle = 60;
up.Check = up.GetCheckValue();
byte[] buffer = up.ToBuffer();
GimbalPackage_up up2 = new GimbalPackage_up();
up2.FromBuffer(buffer);
}
}
}
......@@ -9,6 +9,12 @@ namespace VIZ.GimbalAI.Controller.UnitTest
[TestMethod]
public void TestMethod1()
{
byte[] buffer = BitConverter.GetBytes(1);
using (System.IO.FileStream fs = new System.IO.FileStream(@"e:\test.data", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
fs.Write(buffer, 0, buffer.Length);
}
}
}
}
......@@ -57,6 +57,9 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
......@@ -64,15 +67,36 @@
<HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="BufferTest.cs" />
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Connection\VIZ.Framework.Connection.csproj">
<Project>{e07528dd-9dee-47c2-b79d-235ecfa6b003}</Project>
<Name>VIZ.Framework.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Connection\VIZ.GimbalAI.Controller.Connection.csproj">
<Project>{4da87ec9-2bb4-4233-9e1b-495d9b6290c6}</Project>
<Name>VIZ.GimbalAI.Controller.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Domain\VIZ.GimbalAI.Controller.Domain.csproj">
<Project>{B41ABF07-77AB-4373-B43E-DF82FBFDA3CD}</Project>
<Name>VIZ.GimbalAI.Controller.Domain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
<package id="MSTest.TestAdapter" version="2.2.7" targetFramework="net48" />
<package id="MSTest.TestFramework" version="2.2.7" targetFramework="net48" />
</packages>
\ No newline at end of file
......@@ -7,6 +7,10 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Foreground="Red" FontSize="16" Text="{Binding Path=Test.Name}"></TextBlock>
<TextBlock Foreground="Red" FontSize="16" Text="{Binding Path=Test.Age}"></TextBlock>
<Button Width="120" Height="30" Click="Button_Click"></Button>
</StackPanel>
</Grid>
</Window>
......@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.GimbalAI.Controller.WpfTest
{
......@@ -23,6 +24,18 @@ namespace VIZ.GimbalAI.Controller.WpfTest
public MainWindow()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new MainWindowViewModel());
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MainWindowViewModel vm = this.DataContext as MainWindowViewModel;
vm.Test.Name = "zhangsan";
vm.Test.Age = 17;
vm.RaisePropertyChanged("Test");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
namespace VIZ.GimbalAI.Controller.WpfTest
{
public class Test
{
public string Name { get; set; }
public int Age { get; set; }
}
/// <summary>
/// 主窗口视图模型
/// </summary>
public class MainWindowViewModel : ViewModelBase
{
private Test test = new Test { Name = "lisi", Age = 20 };
public Test Test
{
get { return test; }
set { test = value; this.RaisePropertyChanged(nameof(Test)); }
}
}
}
......@@ -55,8 +55,13 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
......@@ -89,6 +94,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
......@@ -106,6 +112,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......@@ -114,5 +121,11 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
</packages>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
......@@ -5,6 +5,7 @@ using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Module;
namespace VIZ.GimbalAI.Controller
{
......@@ -13,5 +14,20 @@ namespace VIZ.GimbalAI.Controller
/// </summary>
public partial class App : Application
{
public App()
{
// 执行启动流程
AppSetupContext context = AppSetup.Setup();
if (context.Exception != null)
{
MessageBox.Show($"执行 {context.ProviderDetail} 失败\r\n{context.Exception.Message}");
}
if (!context.IsSuccess)
{
Environment.Exit(-1);
}
}
}
}
......@@ -4,9 +4,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VIZ.GimbalAI.Controller"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
xmlns:module="clr-namespace:VIZ.GimbalAI.Controller.Module;assembly=VIZ.GimbalAI.Controller.Module"
mc:Ignorable="d" WindowStartupLocation="CenterScreen"
Title="智能云台控制器" Height="900" Width="1200">
<Grid>
<module:MainView Margin="20"></module:MainView>
</Grid>
</Window>
......@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Module;
namespace VIZ.GimbalAI.Controller
{
......@@ -23,6 +24,40 @@ namespace VIZ.GimbalAI.Controller
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
this.Closed += MainWindow_Closed;
}
/// <summary>
/// 窗口加载
/// </summary>
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// 執行加载流程
AppSetupContext context = AppSetup.Load();
if (context.Exception != null)
{
MessageBox.Show($"执行 {context.ProviderDetail} 失败\r\n{context.Exception.Message}");
}
if (!context.IsSuccess)
{
Environment.Exit(-1);
}
}
/// <summary>
/// 窗口关闭
/// </summary>
private void MainWindow_Closed(object sender, EventArgs e)
{
// 卸载
AppSetup.UnLoad();
// 停止
AppSetup.ShutDown();
}
}
}
......@@ -55,8 +55,13 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
......@@ -106,6 +111,13 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="config\config.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config\log.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......@@ -114,5 +126,55 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Common.Resource\VIZ.Framework.Common.Resource.csproj">
<Project>{76ef480a-e486-41b7-b7a5-2a849fc8d5bf}</Project>
<Name>VIZ.Framework.Common.Resource</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Common\VIZ.Framework.Common.csproj">
<Project>{92834c05-703e-4f05-9224-f36220939d8f}</Project>
<Name>VIZ.Framework.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Connection\VIZ.Framework.Connection.csproj">
<Project>{e07528dd-9dee-47c2-b79d-235ecfa6b003}</Project>
<Name>VIZ.Framework.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661e82-c86a-4611-a028-c34f6ac85c97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Module\VIZ.Framework.Module.csproj">
<Project>{47cf6fb0-e37d-4ef1-afc7-03db2bca8892}</Project>
<Name>VIZ.Framework.Module</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Storage\VIZ.Framework.Storage.csproj">
<Project>{06b80c09-343d-4bb2-aeb1-61cfbfbf5cad}</Project>
<Name>VIZ.Framework.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Connection\VIZ.GimbalAI.Controller.Connection.csproj">
<Project>{4da87ec9-2bb4-4233-9e1b-495d9b6290c6}</Project>
<Name>VIZ.GimbalAI.Controller.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Core\VIZ.GimbalAI.Controller.Core.csproj">
<Project>{51de8c1e-e026-4e0b-b6b2-4922736866a6}</Project>
<Name>VIZ.GimbalAI.Controller.Core</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Domain\VIZ.GimbalAI.Controller.Domain.csproj">
<Project>{b41abf07-77ab-4373-b43e-df82fbfda3cd}</Project>
<Name>VIZ.GimbalAI.Controller.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Module\VIZ.GimbalAI.Controller.Module.csproj">
<Project>{9037e23d-4e0b-4083-aab8-65fbaae997a8}</Project>
<Name>VIZ.GimbalAI.Controller.Module</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.GimbalAI.Controller.Storage\VIZ.GimbalAI.Controller.Storage.csproj">
<Project>{aeb04581-0586-4388-b53f-95b6482c807e}</Project>
<Name>VIZ.GimbalAI.Controller.Storage</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
; ============================================================
; === Application ===
; ============================================================
[Application]
;是否是调试模式
APPLICATION_IS_DEBUG=true
; ============================================================
; === Video ===
; ============================================================
[Video]
;视频是否显示FPS
VIDEO_IS_SHOW_FPS=false
;视频渲染等待(单位:毫秒)
VIDEO_RENDER_WAIT=10
;视频背景颜色
VIDEO_BACKGROUND_COLOR=#FF172532
;视频框边框宽度(单位:像素)
VIDEO_RECTANGLE_BORDER_WIDTH=4
;视频框边框颜色(格式:#AARRGGBB)
VIDEO_RECTANGLE_BORDER_COLOR=#FFFF0000
;视频跟踪框边框宽度(单位:像素)
VIDEO_TRACKING_BOX_BORDER_WIDTH=2
;视频跟踪框边框颜色
VIDEO_TRACKING_BOX_BORDER_COLOR=#FFFF0000
;视频框选边框宽度(单位:像素)
VIDEO_FRAME_SELECTION_BORDER_WIDTH=4
;视频框选边框颜色(格式:#AARRGGBB)
VIDEO_FRAME_SELECTION_BORDER_COLOR=#FFFF6D87
;视频剪切宽度(单位:像素)
VIDEO_CLIP_BOX_WIDTH=810
;视频剪切边框宽度(单位:像素)
VIDEO_CLIP_BOX_BORDER_WIDTH=4
;视频剪切边框颜色
VIDEO_CLIP_BOX_BORDER_COLOR=#FFFF0000
;视频剪切掩码颜色
VIDEO_CLIP_BOX_MASK_COLOR=#88000000
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="errorAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\err.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="infoAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\info.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="debugAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="DEBUG" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\debug.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="perfAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\perf.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="errorAppender" />
<appender-ref ref="infoAppender" />
<appender-ref ref="debugAppender" />
</root>
<logger name="Performance" additivity="false">
<level value="ALL" />
<appender-ref ref="perfAppender" />
</logger>
</log4net>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
</packages>
\ No newline at end of file
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