From c6c3f1cc41f9863a27896a80a05cd68f1401fca3 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Thu, 10 Jul 2025 18:42:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Di2c=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8C=85=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/Peripherals/I2cClient.cs | 10 ++++++++++ server/src/UdpClientPool.cs | 6 ++---- server/src/WebProtocol.cs | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/Peripherals/I2cClient.cs b/server/src/Peripherals/I2cClient.cs index 50fd083..14e65a1 100644 --- a/server/src/Peripherals/I2cClient.cs +++ b/server/src/Peripherals/I2cClient.cs @@ -113,6 +113,16 @@ public class I2c // 写入数据到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); if (!ret.IsSuccessful) { diff --git a/server/src/UdpClientPool.cs b/server/src/UdpClientPool.cs index 5dbddb9..c8edc84 100644 --- a/server/src/UdpClientPool.cs +++ b/server/src/UdpClientPool.cs @@ -454,13 +454,11 @@ public class UDPClientPool { // Sperate Data Array var isLastData = i == writeTimes - 1; - var sendDataArray = - isLastData ? + var sendDataArray = isLastData ? dataArray[(i * (256 * (32 / 8)))..] : dataArray[(i * (256 * (32 / 8)))..((i + 1) * (256 * (32 / 8)))]; - // Write Jtag State Register - opts.BurstLength = ((byte)(sendDataArray.Length / 4 - 1)); + opts.BurstLength = ((byte)Math.Min(sendDataArray.Length / 4 - 1, 1)); ret = await UDPClientPool.SendAddrPackAsync(endPoint, new SendAddrPackage(opts)); if (!ret) return new(new Exception("Send 1st address package failed!")); diff --git a/server/src/WebProtocol.cs b/server/src/WebProtocol.cs index 67f542a..9b1012e 100644 --- a/server/src/WebProtocol.cs +++ b/server/src/WebProtocol.cs @@ -269,6 +269,9 @@ namespace WebProtocol if (bodyData.Length > 256 * (32 / 8)) 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; _ = _reserved;