fix: 跑通摄像头640x480配置
This commit is contained in:
@@ -69,7 +69,7 @@ public class I2c
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
readonly int timeout = 2000;
|
||||
|
||||
readonly int taskID;
|
||||
readonly int port;
|
||||
readonly string address;
|
||||
private IPEndPoint ep;
|
||||
@@ -79,13 +79,15 @@ public class I2c
|
||||
/// </summary>
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <param name="taskID">[TODO:parameter]</param>
|
||||
/// <param name="timeout">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public I2c(string address, int port, int timeout = 2000)
|
||||
public I2c(string address, int port, int taskID,int timeout = 2000)
|
||||
{
|
||||
if (timeout < 0)
|
||||
throw new ArgumentException("Timeout couldn't be negative", nameof(timeout));
|
||||
this.address = address;
|
||||
this.taskID = taskID;
|
||||
this.port = port;
|
||||
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
||||
this.timeout = timeout;
|
||||
@@ -107,7 +109,7 @@ public class I2c
|
||||
}
|
||||
|
||||
// 清除UDP服务器接收缓冲区
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address, 2);
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
|
||||
logger.Trace($"Clear up udp server {this.address} receive data");
|
||||
|
||||
@@ -123,7 +125,7 @@ public class I2c
|
||||
i2cData[i++] = item;
|
||||
}
|
||||
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 2, I2cAddr.Write, i2cData);
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, I2cAddr.Write, i2cData);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to write data to I2C FIFO: {ret.Error}");
|
||||
@@ -139,7 +141,7 @@ public class I2c
|
||||
|
||||
// 配置本次传输数据量
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 2, I2cAddr.TranConfig, ((uint)(data.Length - 1)));
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, I2cAddr.TranConfig, ((uint)(data.Length - 1)));
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to configure transfer length: {ret.Error}");
|
||||
@@ -156,7 +158,7 @@ public class I2c
|
||||
// 配置I2C地址、协议及启动传输
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, 2, I2cAddr.BaseConfig, (devAddr) | (((uint)proto) << 16) | (1 << 24));
|
||||
this.ep, this.taskID, I2cAddr.BaseConfig, (devAddr) | (((uint)proto) << 16) | (1 << 24));
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to configure I2C address/protocol/start: {ret.Error}");
|
||||
@@ -172,7 +174,7 @@ public class I2c
|
||||
|
||||
// 等待I2C命令完成
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 2, I2cAddr.Flag, 0x0000_0001, 0xFFFF_FFFF);
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, this.taskID, I2cAddr.Flag, 0x0000_0001, 0xFFFF_FFFF);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to wait for I2C command completion: {ret.Error}");
|
||||
@@ -205,13 +207,13 @@ public class I2c
|
||||
}
|
||||
|
||||
// 清除UDP服务器接收缓冲区
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address, 2);
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
|
||||
logger.Trace($"Clear up udp server {this.address} receive data");
|
||||
|
||||
// 配置本次传输数据量
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, 2, I2cAddr.TranConfig, ((uint)(length - 1)));
|
||||
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, I2cAddr.TranConfig, ((uint)(length - 1)));
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to configure transfer length: {ret.Error}");
|
||||
@@ -228,7 +230,7 @@ public class I2c
|
||||
// 配置I2C地址、协议及启动传输(读操作)
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, 2, I2cAddr.BaseConfig, (devAddr) | (1 << 8) | (((uint)proto) << 16) | (1 << 24));
|
||||
this.ep, this.taskID, I2cAddr.BaseConfig, (devAddr) | (1 << 8) | (((uint)proto) << 16) | (1 << 24));
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to configure I2C address/protocol/start: {ret.Error}");
|
||||
@@ -244,7 +246,7 @@ public class I2c
|
||||
|
||||
// 等待I2C命令完成
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 2, I2cAddr.Flag, 0x0000_0001, 0xFFFF_FFFF);
|
||||
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, this.taskID, I2cAddr.Flag, 0x0000_0001, 0xFFFF_FFFF);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to wait for I2C command completion: {ret.Error}");
|
||||
@@ -260,7 +262,7 @@ public class I2c
|
||||
|
||||
// 读取数据
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, 2, I2cAddr.Read, length);
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, this.taskID, I2cAddr.Read, length);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Failed to read data from I2C FIFO: {ret.Error}");
|
||||
|
||||
Reference in New Issue
Block a user