try to fix bug, and add schema to swagger

This commit is contained in:
2025-04-13 21:22:55 +08:00
parent c9660633f0
commit 5fa4860bfb
5 changed files with 239 additions and 144 deletions

View File

@@ -28,33 +28,44 @@ namespace WebProtocol
/// <summary> Package options which to send address to read or write </summary>
/// <example>
/// {
/// "burType":0,
/// "commandID":1,
/// }
/// </example>
public struct SendAddrPackOptions
public class SendAddrPackOptions
{
/// <summary> Package Burst Type </summary>
[JsonProperty("burstType")]
public BurstType burstType;
/// <example>1</example>
public byte commandID;
/// <summary> 标识写入还是读取 </summary>
/// <example> true </example>
public bool isWrite;
/// <summary> 突发长度0是32bits255是32bits x 256 </summary>
/// <example> 255 </example>
public byte burstLength;
/// <example> 0x10_00_00_00 </example>
public UInt32 address;
/// <summary>
/// 突发类型
/// </summary>
/// <example>0</example>
public BurstType BurstType { get; set; }
/// <summary>
/// Convert to Json String
/// 任务ID
/// </summary>
/// <returns> Json String </returns>
/// <example>1</example>
public byte CommandID { get; set; }
/// <summary>
/// 标识写入还是读取
/// </summary>
/// <example>true</example>
public bool IsWrite { get; set; }
/// <summary>
/// 突发长度0是32bits255是32bits x 256
/// </summary>
/// <example>255</example>
public byte BurstLength { get; set; }
/// <summary>
/// 目标地址
/// </summary>
/// <example>0</example>
public UInt32 Address { get; set; }
/// <summary>
/// 转换为Json格式字符串
/// </summary>
/// <returns>Json String</returns>
public override string ToString()
{
return JsonConvert.SerializeObject(this);
@@ -62,7 +73,7 @@ namespace WebProtocol
}
/// <summary> Package Options which to receive from boards </summary>
public struct RecvPackOptions
public class RecvPackOptions
{
/// <summary> 数据包类型 </summary>
public enum PackType
@@ -76,19 +87,26 @@ namespace WebProtocol
/// <summary>
/// 数据包类型
/// </summary>
public PackType type;
/// <example>0</example>
public PackType Type { get; set; }
/// <summary>
/// Task ID
/// </summary>
public byte commandID;
/// <example>0</example>
public byte CommandID { get; set; }
/// <summary>
/// Whether is succeed to finish command
/// </summary>
public bool isSuccess;
/// <example>true</example>
public bool IsSuccess { get; set; }
/// <summary>
/// Return Data
/// </summary>
public byte[]? data;
/// <example>[]</example>
public byte[]? Data { get; set; }
/// <summary>
/// Convert to Json String
@@ -101,7 +119,7 @@ namespace WebProtocol
}
/// <summary> Server->FPGA 地址包 </summary>
public struct SendAddrPackage
public class SendAddrPackage
{
readonly byte sign = (byte)PackSign.SendAddr;
readonly byte commandType;
@@ -115,12 +133,12 @@ namespace WebProtocol
/// <param name="opts"> 地址包选项 </param>
public SendAddrPackage(SendAddrPackOptions opts)
{
byte byteBurstType = Convert.ToByte((byte)opts.burstType << 6);
byte byteCommandID = Convert.ToByte((opts.commandID & 0x03) << 4);
byte byteIsWrite = (opts.isWrite ? (byte)0x01 : (byte)0x00);
byte byteBurstType = Convert.ToByte((byte)opts.BurstType << 6);
byte byteCommandID = Convert.ToByte((opts.CommandID & 0x03) << 4);
byte byteIsWrite = (opts.IsWrite ? (byte)0x01 : (byte)0x00);
this.commandType = Convert.ToByte(byteBurstType | byteCommandID | byteIsWrite);
this.burstLength = opts.burstLength;
this.address = opts.address;
this.burstLength = opts.BurstLength;
this.address = opts.Address;
}
/// <summary>
@@ -178,12 +196,12 @@ namespace WebProtocol
/// <returns> 字符串 </returns>
public override string ToString()
{
SendAddrPackOptions opts;
opts.burstType = (BurstType)(commandType >> 6);
opts.commandID = Convert.ToByte((commandType >> 4) & 0b0011);
opts.isWrite = Convert.ToBoolean(commandType & 0x01);
opts.burstLength = burstLength;
opts.address = address;
var opts = new SendAddrPackOptions();
opts.BurstType = (BurstType)(commandType >> 6);
opts.CommandID = Convert.ToByte((commandType >> 4) & 0b0011);
opts.IsWrite = Convert.ToBoolean(commandType & 0x01);
opts.BurstLength = burstLength;
opts.Address = address;
return JsonConvert.SerializeObject(opts);
}
@@ -287,16 +305,24 @@ namespace WebProtocol
{
get
{
RecvPackOptions opts;
opts.type = RecvPackOptions.PackType.ReadResp;
opts.commandID = commandID;
opts.isSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? false : true);
opts.data = bodyData;
var opts = new RecvPackOptions();
opts.Type = RecvPackOptions.PackType.ReadResp;
opts.CommandID = commandID;
opts.IsSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? false : true);
opts.Data = bodyData;
return opts;
}
}
/// <summary>
/// 读取是否成功
/// </summary>
public bool IsSuccessful
{
get { return Convert.ToBoolean((resp >> 1) == 0b01 ? false : true); }
}
/// <summary>
/// 从字节数组构建读响应包
/// </summary>
@@ -342,16 +368,24 @@ namespace WebProtocol
{
get
{
RecvPackOptions opts;
opts.type = RecvPackOptions.PackType.WriteResp;
opts.commandID = commandID;
opts.isSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? false : true);
opts.data = null;
var opts = new RecvPackOptions();
opts.Type = RecvPackOptions.PackType.WriteResp;
opts.CommandID = commandID;
opts.IsSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? false : true);
opts.Data = null;
return opts;
}
}
/// <summary>
/// 写入是否成功
/// </summary>
public bool IsSuccessful
{
get { return Convert.ToBoolean((resp >> 1) == 0b01 ? false : true); }
}
/// <summary>
/// 从字节数组构建写响应包
/// </summary>