rewrite udp server handler, change router and protocol
This commit is contained in:
@@ -172,6 +172,24 @@ namespace WebProtocol
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取对应地址包选项
|
||||
/// </summary>
|
||||
public SendAddrPackOptions Options
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SendAddrPackOptions()
|
||||
{
|
||||
Address = this.address,
|
||||
BurstLength = this.burstLength,
|
||||
BurstType = (BurstType)(this.commandType >> 6),
|
||||
CommandID = Convert.ToByte((this.commandType >> 4) & 0b11),
|
||||
IsWrite = Convert.ToBoolean(this.commandType & 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将地址包转化为字节数组
|
||||
/// </summary>
|
||||
@@ -298,6 +316,31 @@ namespace WebProtocol
|
||||
_ = this._reserved;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FPGA->Server 读响应包
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="commandID"> 任务ID号 </param>
|
||||
/// <param name="isSuccess">是否读取成功</param>
|
||||
/// <param name="bodyData"> 数据 </param>
|
||||
public RecvDataPackage(byte commandID, bool isSuccess, byte[] bodyData)
|
||||
{
|
||||
this.commandID = commandID;
|
||||
this.resp = Convert.ToByte(isSuccess);
|
||||
this.bodyData = bodyData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过接受包选项构建读响应包
|
||||
/// </summary>
|
||||
/// <param name="opts">接收包(读响应包和写响应包)选项</param>
|
||||
public RecvDataPackage(RecvPackOptions opts)
|
||||
{
|
||||
this.commandID = opts.CommandID;
|
||||
this.resp = Convert.ToByte(opts.IsSuccess ? 0b10 : 0b00);
|
||||
this.bodyData = opts.Data ?? (byte[])[0, 0, 0, 0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取读响应包选项
|
||||
/// </summary>
|
||||
@@ -337,6 +380,25 @@ namespace WebProtocol
|
||||
);
|
||||
return new RecvDataPackage(bytes[1], bytes[2], bytes[4..]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据包转化为字节数组
|
||||
/// </summary>
|
||||
/// <returns>字节数组</returns>
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
var bodyDataLen = bodyData.Length;
|
||||
var arr = new byte[4 + bodyDataLen];
|
||||
|
||||
arr[0] = this.sign;
|
||||
arr[1] = this.commandID;
|
||||
arr[2] = this.resp;
|
||||
|
||||
Array.Copy(bodyData, 0, arr, 4, bodyDataLen);
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary> 写响应包 </summary>
|
||||
@@ -361,6 +423,27 @@ namespace WebProtocol
|
||||
_ = this._reserved;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建写响应包
|
||||
/// </summary>
|
||||
/// <param name="commandID">任务ID</param>
|
||||
/// <param name="isSuccess">是否写成功</param>
|
||||
public RecvRespPackage(byte commandID, bool isSuccess)
|
||||
{
|
||||
this.commandID = commandID;
|
||||
this.resp = Convert.ToByte(isSuccess);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过接受包选项构建写响应包
|
||||
/// </summary>
|
||||
/// <param name="opts">接收包(读响应包和写响应包)选项</param>
|
||||
public RecvRespPackage(RecvPackOptions opts)
|
||||
{
|
||||
this.commandID = opts.CommandID;
|
||||
this.resp = Convert.ToByte(opts.IsSuccess ? 0b10 : 0b00);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取写响应包选项
|
||||
/// </summary>
|
||||
@@ -400,5 +483,20 @@ namespace WebProtocol
|
||||
);
|
||||
return new RecvRespPackage(bytes[1], bytes[2]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据包转化为字节数组
|
||||
/// </summary>
|
||||
/// <returns>字节数组</returns>
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
var arr = new byte[4];
|
||||
|
||||
arr[0] = this.sign;
|
||||
arr[1] = this.commandID;
|
||||
arr[2] = this.resp;
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user