fix: 调整Camera的taskID,使其能够正常接受数据

This commit is contained in:
SikongJueluo 2025-07-03 19:30:17 +08:00
parent e84a784517
commit 287c416247
No known key found for this signature in database
2 changed files with 5 additions and 8 deletions

View File

@ -42,14 +42,14 @@ class Camera
public async ValueTask<Result<byte[]>> ReadFrame()
{
// 清除UDP服务器接收缓冲区
await MsgBus.UDPServer.ClearUDPData(this.address, 3);
await MsgBus.UDPServer.ClearUDPData(this.address, 2);
logger.Trace($"Clear up udp server {this.address} receive data");
// 使用UDPClientPool读取图像帧数据
var result = await UDPClientPool.ReadAddrBytes(
this.ep,
3, // taskID
2, // taskID
CameraAddr.Base,
(int)CameraAddr.FrameLength,
this.timeout);

View File

@ -323,7 +323,6 @@ public class UDPClientPool
opts.BurstType = BurstType.FixedBurst;
opts.CommandID = Convert.ToByte(taskID);
opts.Address = devAddr;
opts.IsWrite = false;
// Check Msg Bus
@ -332,8 +331,8 @@ public class UDPClientPool
// Calculate read times and segments
var maxBytesPerRead = 256 * (32 / 8); // 1024 bytes per read
var hasRest = dataLength % maxBytesPerRead != 0;
var readTimes = hasRest ?
var restBytes = dataLength % maxBytesPerRead;
var readTimes = restBytes != 0 ?
dataLength / maxBytesPerRead + 1 :
dataLength / maxBytesPerRead;
@ -341,9 +340,7 @@ public class UDPClientPool
{
// Calculate current segment size
var isLastSegment = i == readTimes - 1;
var currentSegmentSize = isLastSegment && hasRest ?
dataLength % maxBytesPerRead :
maxBytesPerRead;
var currentSegmentSize = isLastSegment ? restBytes : maxBytesPerRead;
// Set burst length (in 32-bit words)
opts.BurstLength = (byte)(currentSegmentSize / 4 - 1);