fix: 修复i2c发送数据包错误的问题
This commit is contained in:
parent
540f5c788d
commit
c6c3f1cc41
|
@ -113,6 +113,16 @@ public class I2c
|
||||||
|
|
||||||
// 写入数据到I2C FIFO写入口
|
// 写入数据到I2C FIFO写入口
|
||||||
{
|
{
|
||||||
|
var i2cData = new byte[data.Length * 4];
|
||||||
|
int i = 0;
|
||||||
|
foreach (var item in data)
|
||||||
|
{
|
||||||
|
i2cData[i++] = 0x00;
|
||||||
|
i2cData[i++] = 0x00;
|
||||||
|
i2cData[i++] = 0x00;
|
||||||
|
i2cData[i++] = item;
|
||||||
|
}
|
||||||
|
|
||||||
var ret = await UDPClientPool.WriteAddr(this.ep, 2, I2cAddr.Write, data);
|
var ret = await UDPClientPool.WriteAddr(this.ep, 2, I2cAddr.Write, data);
|
||||||
if (!ret.IsSuccessful)
|
if (!ret.IsSuccessful)
|
||||||
{
|
{
|
||||||
|
|
|
@ -454,13 +454,11 @@ public class UDPClientPool
|
||||||
{
|
{
|
||||||
// Sperate Data Array
|
// Sperate Data Array
|
||||||
var isLastData = i == writeTimes - 1;
|
var isLastData = i == writeTimes - 1;
|
||||||
var sendDataArray =
|
var sendDataArray = isLastData ?
|
||||||
isLastData ?
|
|
||||||
dataArray[(i * (256 * (32 / 8)))..] :
|
dataArray[(i * (256 * (32 / 8)))..] :
|
||||||
dataArray[(i * (256 * (32 / 8)))..((i + 1) * (256 * (32 / 8)))];
|
dataArray[(i * (256 * (32 / 8)))..((i + 1) * (256 * (32 / 8)))];
|
||||||
|
|
||||||
// Write Jtag State Register
|
opts.BurstLength = ((byte)Math.Min(sendDataArray.Length / 4 - 1, 1));
|
||||||
opts.BurstLength = ((byte)(sendDataArray.Length / 4 - 1));
|
|
||||||
ret = await UDPClientPool.SendAddrPackAsync(endPoint, new SendAddrPackage(opts));
|
ret = await UDPClientPool.SendAddrPackAsync(endPoint, new SendAddrPackage(opts));
|
||||||
if (!ret) return new(new Exception("Send 1st address package failed!"));
|
if (!ret) return new(new Exception("Send 1st address package failed!"));
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,9 @@ namespace WebProtocol
|
||||||
if (bodyData.Length > 256 * (32 / 8))
|
if (bodyData.Length > 256 * (32 / 8))
|
||||||
throw new Exception("The data of SendDataPackage can't over 256 * 32bits");
|
throw new Exception("The data of SendDataPackage can't over 256 * 32bits");
|
||||||
|
|
||||||
|
if (bodyData.Length % 4 != 0)
|
||||||
|
throw new Exception("The data of SendDataPackage should be divided by 4");
|
||||||
|
|
||||||
this.bodyData = bodyData;
|
this.bodyData = bodyData;
|
||||||
|
|
||||||
_ = _reserved;
|
_ = _reserved;
|
||||||
|
|
Loading…
Reference in New Issue