server finish nlog

This commit is contained in:
2025-04-10 21:53:21 +08:00
parent 143d6c634b
commit c9660633f0
8 changed files with 247 additions and 45 deletions

View File

@@ -141,6 +141,12 @@ namespace WebProtocol
this.address = address;
}
/// <summary>
/// 使用二进制参数构建地址包
/// </summary>
/// <param name="commandType">二进制命令类型</param>
/// <param name="burstLength">突发长度</param>
/// <param name="address">写入或读取的地址</param>
public SendAddrPackage(byte commandType, byte burstLength, UInt32 address)
{
this.commandType = commandType;
@@ -182,6 +188,12 @@ namespace WebProtocol
return JsonConvert.SerializeObject(opts);
}
/// <summary>
/// 根据字节数组构建地址包
/// </summary>
/// <param name="bytes">字节数组</param>
/// <param name="checkSign">是否校验地址包包头</param>
/// <returns>地址包</returns>
public static Result<SendAddrPackage> FromBytes(byte[] bytes, bool checkSign = true)
{
if (bytes.Length != 8)
@@ -205,17 +217,28 @@ namespace WebProtocol
}
}
/// <summary> 数据包 </summary>
public struct SendDataPackage
{
readonly byte sign = (byte)PackSign.SendData;
readonly byte[] _reserved = new byte[3];
readonly byte[] bodyData;
/// <summary>
/// 根据数据内容构建数据包
/// </summary>
/// <param name="bodyData">数据</param>
public SendDataPackage(byte[] bodyData)
{
this.bodyData = bodyData;
_ = _reserved;
}
/// <summary>
/// 将数据包转化为字节数组
/// </summary>
/// <returns>字节数组</returns>
public byte[] ToBytes()
{
var bodyDataLen = bodyData.Length;
@@ -231,7 +254,7 @@ namespace WebProtocol
}
/// <summary> FPGA->Server 读数据包 </summary>
/// <summary> FPGA->Server 读响应包 </summary>
public struct RecvDataPackage
{
readonly byte sign = (byte)PackSign.RecvData;
@@ -241,21 +264,24 @@ namespace WebProtocol
readonly byte[] bodyData;
/// <summary>
/// FPGA->Server 读数据
/// FPGA->Server 读响应
/// 构造函数
/// </summary>
/// <param name="commandID"> 任务ID号 </param>
/// <param name="resp"> 读数据包响应 </param>
/// <param name="resp"> 读响应包响应 </param>
/// <param name="bodyData"> 数据 </param>
public RecvDataPackage(byte commandID, byte resp, byte[] bodyData)
{
this.commandID = commandID;
this.resp = resp;
this.bodyData = bodyData;
_ = this.sign;
_ = this._reserved;
}
/// <summary>
/// 获取读数据包选项
/// 获取读响应包选项
/// </summary>
public RecvPackOptions Options
{
@@ -271,6 +297,11 @@ namespace WebProtocol
}
}
/// <summary>
/// 从字节数组构建读响应包
/// </summary>
/// <param name="bytes">字节数组</param>
/// <returns>读响应包</returns>
public static Result<RecvDataPackage> FromBytes(byte[] bytes)
{
if (bytes[0] != (byte)PackSign.RecvData)
@@ -282,6 +313,7 @@ namespace WebProtocol
}
}
/// <summary> 写响应包 </summary>
public struct RecvRespPackage
{
readonly byte sign = (byte)PackSign.RecvResp;
@@ -289,12 +321,23 @@ namespace WebProtocol
readonly byte resp;
readonly byte _reserved = 0;
/// <summary>
/// 构建写响应包
/// </summary>
/// <param name="commandID">任务ID</param>
/// <param name="resp">写响应</param>
public RecvRespPackage(byte commandID, byte resp)
{
this.commandID = commandID;
this.resp = resp;
_ = this.sign;
_ = this._reserved;
}
/// <summary>
/// 获取写响应包选项
/// </summary>
public RecvPackOptions Options
{
get
@@ -309,6 +352,11 @@ namespace WebProtocol
}
}
/// <summary>
/// 从字节数组构建写响应包
/// </summary>
/// <param name="bytes">字节数组</param>
/// <returns>写响应包</returns>
public static Result<RecvRespPackage> FromBytes(byte[] bytes)
{
if (bytes[0] != (byte)PackSign.RecvResp)