3 Commits

13 changed files with 116 additions and 98 deletions

View File

@@ -1,3 +1,5 @@
using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.FileProviders;
using Newtonsoft.Json;

View File

@@ -106,15 +106,15 @@ public class UDPController : ControllerBase
}
/// <summary>
/// 获取指定IP地址接的数据列表
/// 获取指定IP地址接的数据列表
/// </summary>
/// <param name="address">IP地址</param>
[HttpGet("GetRecvDataArray")]
[ProducesResponseType(typeof(List<UDPData>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async ValueTask<IResult> GetRecvDataArray(string address)
public async ValueTask<IResult> GetRecvDataArray(string address, int taskID)
{
var ret = await MsgBus.UDPServer.GetDataArrayAsync(address);
var ret = await MsgBus.UDPServer.GetDataArrayAsync(address, taskID);
if (ret.HasValue)
{

View File

@@ -441,7 +441,7 @@ public class Jtag
(UInt32 devAddr, UInt32 data, UInt32 result, UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0)
{
{
var ret = await UDPClientPool.WriteAddr(this.ep, devAddr, data, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception("Write FIFO failed"));
}
@@ -450,7 +450,7 @@ public class Jtag
await Task.Delay(TimeSpan.FromMilliseconds(delayMilliseconds));
{
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, JtagAddr.STATE, result, resultMask, this.timeout);
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 0, JtagAddr.STATE, result, resultMask, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}
@@ -460,7 +460,7 @@ public class Jtag
(UInt32 devAddr, byte[] data, UInt32 result, UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0)
{
{
var ret = await UDPClientPool.WriteAddr(this.ep, devAddr, data, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception("Write FIFO failed"));
}
@@ -469,7 +469,7 @@ public class Jtag
await Task.Delay(TimeSpan.FromMilliseconds(delayMilliseconds));
{
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, JtagAddr.STATE, result, resultMask, this.timeout);
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 0, JtagAddr.STATE, result, resultMask, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}
@@ -627,9 +627,9 @@ public class Jtag
public async ValueTask<Result<uint>> ReadIDCode()
{
// Clear Data
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace($"Clear up udp server {this.address} receive data");
logger.Trace($"Clear up udp server {this.address,0} receive data");
Result<bool> ret;
@@ -665,9 +665,9 @@ public class Jtag
public async ValueTask<Result<uint>> ReadStatusReg()
{
// Clear Data
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace($"Clear up udp server {this.address} receive data");
logger.Trace($"Clear up udp server {this.address,0} receive data");
Result<bool> ret;
@@ -702,9 +702,9 @@ public class Jtag
public async ValueTask<Result<bool>> DownloadBitstream(byte[] bitstream)
{
// Clear Data
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace($"Clear up udp server {this.address} receive data");
logger.Trace($"Clear up udp server {this.address,0} receive data");
Result<bool> ret;
@@ -786,9 +786,9 @@ public class Jtag
logger.Debug($"Get boundar scan registers number: {portNum}");
// Clear Data
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace($"Clear up udp server {this.address} receive data");
logger.Trace($"Clear up udp server {this.address,0} receive data");
Result<bool> ret;
@@ -853,9 +853,9 @@ public class Jtag
public async ValueTask<Result<bool>> SetSpeed(UInt32 speed)
{
// Clear Data
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace($"Clear up udp server {this.address} receive data");
logger.Trace($"Clear up udp server {this.address,0} receive data");
var ret = await WriteFIFO(
JtagAddr.SPEED_CTRL, (speed << 16) | speed,

View File

@@ -108,11 +108,11 @@ public class DDS
if (waveNum < 0 || waveNum > 3) return new(new ArgumentException(
$"Wave number should be 0 ~ 3 instead of {waveNum}", nameof(waveNum)));
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
logger.Trace("Clear udp data finished");
var ret = await UDPClientPool.WriteAddr(
this.ep, DDSAddr.Channel[channelNum].WaveSelect, (UInt32)waveNum, this.timeout);
this.ep, 1, DDSAddr.Channel[channelNum].WaveSelect, (UInt32)waveNum, this.timeout);
if (!ret.IsSuccessful)
return new(ret.Error);
return ret.Value;
@@ -132,11 +132,11 @@ public class DDS
if (waveNum < 0 || waveNum > 3) return new(new ArgumentException(
$"Wave number should be 0 ~ 3 instead of {waveNum}", nameof(waveNum)));
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
logger.Trace("Clear udp data finished");
var ret = await UDPClientPool.WriteAddr(
this.ep, DDSAddr.Channel[channelNum].FreqCtrl[waveNum], step, this.timeout);
this.ep, 1, DDSAddr.Channel[channelNum].FreqCtrl[waveNum], step, this.timeout);
if (!ret.IsSuccessful)
return new(ret.Error);
return ret.Value;
@@ -158,11 +158,11 @@ public class DDS
if (phase < 0 || phase > 4096) return new(new ArgumentException(
$"Phase should be 0 ~ 4096 instead of {phase}", nameof(phase)));
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
logger.Trace("Clear udp data finished");
var ret = await UDPClientPool.WriteAddr(
this.ep, DDSAddr.Channel[channelNum].PhaseCtrl[waveNum], (UInt32)phase, this.timeout);
this.ep, 1, DDSAddr.Channel[channelNum].PhaseCtrl[waveNum], (UInt32)phase, this.timeout);
if (!ret.IsSuccessful)
return new(ret.Error);
return ret.Value;

View File

@@ -44,10 +44,10 @@ public class MatrixKey
public async ValueTask<Result<bool>> EnableControl()
{
if (MsgBus.IsRunning)
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
else return new(new Exception("Message Bus not work!"));
var ret = await UDPClientPool.WriteAddr(this.ep, MatrixKeyAddr.KEY_ENABLE, 1, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 1, MatrixKeyAddr.KEY_ENABLE, 1, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}
@@ -59,10 +59,10 @@ public class MatrixKey
public async ValueTask<Result<bool>> DisableControl()
{
if (MsgBus.IsRunning)
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
else return new(new Exception("Message Bus not work!"));
var ret = await UDPClientPool.WriteAddr(this.ep, MatrixKeyAddr.KEY_ENABLE, 0, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 1, MatrixKeyAddr.KEY_ENABLE, 0, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}
@@ -75,14 +75,14 @@ public class MatrixKey
public async ValueTask<Result<bool>> ControlKey(BitArray keyStates)
{
if (MsgBus.IsRunning)
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
else return new(new Exception("Message Bus not work!"));
if (keyStates.Length != 16) return new(new ArgumentException(
$"The number of key should be 16 instead of {keyStates.Length}", nameof(keyStates)));
var ret = await UDPClientPool.WriteAddr(
this.ep, MatrixKeyAddr.KEY_CTRL, Common.Number.BitsToNumber(keyStates).Value, this.timeout);
this.ep, 1, MatrixKeyAddr.KEY_CTRL, Common.Number.BitsToNumber(keyStates).Value, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}

View File

@@ -45,10 +45,10 @@ public class Power
public async ValueTask<Result<bool>> SetPowerOnOff(bool enable)
{
if (MsgBus.IsRunning)
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 1);
else return new(new Exception("Message Bus not work!"));
var ret = await UDPClientPool.WriteAddr(this.ep, PowerAddr.PowerCtrl, Convert.ToUInt32(enable), this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 1, PowerAddr.PowerCtrl, Convert.ToUInt32(enable), this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}

View File

@@ -142,7 +142,7 @@ public class RemoteUpdater
{
var ret = await UDPClientPool.WriteAddr(
this.ep, RemoteUpdaterAddr.WriteCtrl,
this.ep, 0, RemoteUpdaterAddr.WriteCtrl,
Convert.ToUInt32((writeSectorNum << 16) | (1 << 15) | Convert.ToInt32(flashAddr / 4096)), this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception("Enable write flash failed"));
@@ -150,7 +150,7 @@ public class RemoteUpdater
{
var ret = await UDPClientPool.ReadAddrWithWait(
this.ep, RemoteUpdaterAddr.WriteSign,
this.ep, 0, RemoteUpdaterAddr.WriteSign,
0x00_00_00_01, 0x00_00_00_01, this.timeoutForWait);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception(
@@ -158,14 +158,14 @@ public class RemoteUpdater
}
{
var ret = await UDPClientPool.WriteAddr(this.ep, RemoteUpdaterAddr.WriteFIFO, bytesData, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 0, RemoteUpdaterAddr.WriteFIFO, bytesData, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception("Send data to flash failed"));
}
{
var ret = await UDPClientPool.ReadAddrWithWait(
this.ep, RemoteUpdaterAddr.WriteSign,
this.ep, 0, RemoteUpdaterAddr.WriteSign,
0x00_00_01_00, 0x00_00_01_00, this.timeoutForWait);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
@@ -314,14 +314,14 @@ public class RemoteUpdater
private async ValueTask<Result<bool>> CheckBitstreamCRC(int bitstreamNum, int bitstreamLen, UInt32 checkSum)
{
{
var ret = await UDPClientPool.WriteAddr(this.ep, RemoteUpdaterAddr.ReadCtrl2, 0x00_00_00_00, this.timeout);
var ret = await UDPClientPool.WriteAddr(this.ep, 0, RemoteUpdaterAddr.ReadCtrl2, 0x00_00_00_00, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception("Write read control 2 failed"));
}
{
var ret = await UDPClientPool.WriteAddr(
this.ep, RemoteUpdaterAddr.ReadCtrl1,
this.ep, 0, RemoteUpdaterAddr.ReadCtrl1,
Convert.ToUInt32((bitstreamLen << 16) | (1 << 15) | Convert.ToInt32(FlashAddr.Bitstream[bitstreamNum] / 4096)),
this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
@@ -330,7 +330,7 @@ public class RemoteUpdater
{
var ret = await UDPClientPool.ReadAddrWithWait(
this.ep, RemoteUpdaterAddr.ReadSign,
this.ep, 0, RemoteUpdaterAddr.ReadSign,
0x00_00_01_00, 0x00_00_01_00, this.timeoutForWait);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value) return new(new Exception(
@@ -338,7 +338,7 @@ public class RemoteUpdater
}
{
var ret = await UDPClientPool.ReadAddr(this.ep, RemoteUpdaterAddr.ReadCRC, this.timeout);
var ret = await UDPClientPool.ReadAddr(this.ep, 0, RemoteUpdaterAddr.ReadCRC, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
var bytes = ret.Value.Options.Data;
@@ -368,7 +368,7 @@ public class RemoteUpdater
$"Bitsteam num should be 0 ~ 3 for HotRest, but given {bitstreamNum}", nameof(bitstreamNum)));
var ret = await UDPClientPool.WriteAddr(
this.ep, RemoteUpdaterAddr.HotResetCtrl,
this.ep, 0, RemoteUpdaterAddr.HotResetCtrl,
((FlashAddr.Bitstream[bitstreamNum] << 8) | 1), this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
@@ -381,7 +381,7 @@ public class RemoteUpdater
/// <returns>[TODO:return]</returns>
public async ValueTask<Result<bool>> HotResetBitstream(int bitstreamNum)
{
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace("Clear udp data finished");
{
@@ -411,7 +411,7 @@ public class RemoteUpdater
byte[]? bitstream2,
byte[]? bitstream3)
{
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace("Clear udp data finished");
for (int bitstreamNum = 0; bitstreamNum < 4; bitstreamNum++)
@@ -462,7 +462,7 @@ public class RemoteUpdater
$"The length of data should be divided by 4096, bug given {bytesData.Length}", nameof(bytesData)));
var bitstreamBlockNum = bytesData.Length / (4 * 1024);
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace("Clear udp data finished");
{
@@ -538,11 +538,11 @@ public class RemoteUpdater
/// <returns>[TODO:return]</returns>
public async ValueTask<Result<UInt32>> GetVersion()
{
await MsgBus.UDPServer.ClearUDPData(this.address);
await MsgBus.UDPServer.ClearUDPData(this.address, 0);
logger.Trace("Clear udp data finished");
{
var ret = await UDPClientPool.ReadAddr(this.ep, RemoteUpdaterAddr.Version, this.timeout);
var ret = await UDPClientPool.ReadAddr(this.ep, 0, RemoteUpdaterAddr.Version, this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
var retData = ret.Value.Options.Data;

View File

@@ -184,14 +184,14 @@ public class UDPClientPool
/// <param name="timeout">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public static async ValueTask<Result<RecvDataPackage>> ReadAddr(
IPEndPoint endPoint, uint devAddr, int timeout = 1000)
IPEndPoint endPoint, int taskID, uint devAddr, int timeout = 1000)
{
var ret = false;
var opts = new SendAddrPackOptions();
opts.BurstType = BurstType.FixedBurst;
opts.BurstLength = 0;
opts.CommandID = 0;
opts.CommandID = Convert.ToByte(taskID);
opts.Address = devAddr;
// Read Jtag State Register
@@ -204,7 +204,7 @@ public class UDPClientPool
return new(new Exception("Message Bus not Working!"));
var retPack = await MsgBus.UDPServer.WaitForDataAsync(
endPoint.Address.ToString(), endPoint.Port, timeout);
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
if (!retPack.IsSuccessful) return new(retPack.Error);
else if (!retPack.Value.IsSuccessful)
return new(new Exception("Send address package failed"));
@@ -226,11 +226,11 @@ public class UDPClientPool
/// <param name="timeout">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public static async ValueTask<Result<bool>> ReadAddr(
IPEndPoint endPoint, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
IPEndPoint endPoint, int taskID, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
{
var address = endPoint.Address.ToString();
var ret = await ReadAddr(endPoint, devAddr, timeout);
var ret = await ReadAddr(endPoint, taskID, devAddr, timeout);
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value.IsSuccessful)
return new(new Exception($"Read device {address} address {devAddr} failed"));
@@ -264,7 +264,7 @@ public class UDPClientPool
/// <param name="timeout">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public static async ValueTask<Result<bool>> ReadAddrWithWait(
IPEndPoint endPoint, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
IPEndPoint endPoint, int taskID, uint devAddr, UInt32 result, UInt32 resultMask, int timeout = 1000)
{
var address = endPoint.Address.ToString();
@@ -277,7 +277,7 @@ public class UDPClientPool
try
{
var ret = await ReadAddr(endPoint, devAddr, Convert.ToInt32(timeleft.TotalMilliseconds));
var ret = await ReadAddr(endPoint, taskID, devAddr, Convert.ToInt32(timeleft.TotalMilliseconds));
if (!ret.IsSuccessful) return new(ret.Error);
if (!ret.Value.IsSuccessful)
return new(new Exception($"Read device {address} address {devAddr} failed"));
@@ -312,14 +312,14 @@ public class UDPClientPool
/// <param name="timeout">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public static async ValueTask<Result<bool>> WriteAddr(
IPEndPoint endPoint, UInt32 devAddr, UInt32 data, int timeout = 1000)
IPEndPoint endPoint, int taskID, UInt32 devAddr, UInt32 data, int timeout = 1000)
{
var ret = false;
var opts = new SendAddrPackOptions();
opts.BurstType = BurstType.FixedBurst;
opts.BurstLength = 0;
opts.CommandID = 0;
opts.CommandID = Convert.ToByte(taskID);
opts.Address = devAddr;
// Write Jtag State Register
@@ -337,7 +337,7 @@ public class UDPClientPool
// Wait for Write Ack
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(
endPoint.Address.ToString(), endPoint.Port, timeout);
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
if (!udpWriteAck.IsSuccessful) return new(udpWriteAck.Error);
return udpWriteAck.Value.IsSuccessful;
@@ -351,14 +351,15 @@ public class UDPClientPool
/// <param name="dataArray">[TODO:parameter]</param>
/// <param name="timeout">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public static async ValueTask<Result<bool>> WriteAddr(IPEndPoint endPoint, UInt32 devAddr, byte[] dataArray, int timeout = 1000)
public static async ValueTask<Result<bool>> WriteAddr(
IPEndPoint endPoint, int taskID, UInt32 devAddr, byte[] dataArray, int timeout = 1000)
{
var ret = false;
var opts = new SendAddrPackOptions();
opts.BurstType = BurstType.FixedBurst;
opts.CommandID = 0;
opts.CommandID = Convert.ToByte(taskID);
opts.Address = devAddr;
// Check Msg Bus
@@ -389,7 +390,7 @@ public class UDPClientPool
if (!ret) return new(new Exception("Send data package failed!"));
// Wait for Write Ack
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(endPoint.Address.ToString(), endPoint.Port, timeout);
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
if (!udpWriteAck.IsSuccessful) return new(udpWriteAck.Error);
if (!udpWriteAck.Value.IsSuccessful)

View File

@@ -22,6 +22,11 @@ public class UDPData
/// 发送来源的端口号
/// </summary>
public required int Port { get; set; }
/// <summary>
/// 任务ID
/// </summary>
public required int TaskID { get; set; }
/// <summary>
/// 接受到的数据
/// </summary>
@@ -44,6 +49,7 @@ public class UDPData
DateTime = this.DateTime,
Address = new string(this.Address),
Port = this.Port,
TaskID = this.TaskID,
Data = cloneData,
HasRead = this.HasRead
};
@@ -119,6 +125,7 @@ public class UDPServer
/// 异步寻找目标发送的内容
/// </summary>
/// <param name="ipAddr"> 目标IP地址 </param>
/// <param name="taskID">[TODO:parameter]</param>
/// <param name="timeout">超时时间</param>
/// <param name="cycle">延迟时间</param>
/// <param name="callerName">调用函数名称</param>
@@ -129,13 +136,14 @@ public class UDPServer
/// Optional 存在时,为最先收到的数据
/// </returns>
public async ValueTask<Optional<UDPData>> FindDataAsync(
string ipAddr, int timeout = 1000, int cycle = 0,
string ipAddr, int taskID, int timeout = 1000, int cycle = 0,
[CallerMemberName] string callerName = "",
[CallerLineNumber] int callerLineNum = 0)
[CallerLineNumber] int callerLineNum = 0
)
{
UDPData? data = null;
logger.Debug($"Caller \"{callerName}|{callerLineNum}\": Try to find {ipAddr} UDP Data");
logger.Debug($"Caller \"{callerName}|{callerLineNum}\": Try to find {ipAddr}-{taskID} UDP Data");
var startTime = DateTime.Now;
var isTimeout = false;
@@ -149,8 +157,8 @@ public class UDPServer
timeleft = TimeSpan.FromMilliseconds(timeout) - elapsed;
using (await udpData.AcquireWriteLockAsync(timeleft))
{
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
if (udpData.ContainsKey($"{ipAddr}-{taskID}") &&
udpData.TryGetValue($"{ipAddr}-{taskID}", out var dataQueue) &&
dataQueue.Count > 0)
{
data = dataQueue.Dequeue();
@@ -177,10 +185,11 @@ public class UDPServer
/// 获取还未被读取的数据列表
/// </summary>
/// <param name="ipAddr">IP地址</param>
/// <param name="taskID">[TODO:parameter]</param>
/// <param name="timeout">超时时间</param>
/// <param name="cycle">延迟时间</param>
/// <returns>数据列表</returns>
public async ValueTask<Optional<List<UDPData>>> GetDataArrayAsync(string ipAddr, int timeout = 1000, int cycle = 0)
public async ValueTask<Optional<List<UDPData>>> GetDataArrayAsync(string ipAddr, int taskID, int timeout = 1000, int cycle = 0)
{
List<UDPData>? data = null;
@@ -196,8 +205,8 @@ public class UDPServer
timeleft = TimeSpan.FromMilliseconds(timeout) - elapsed;
using (await udpData.AcquireReadLockAsync(timeleft))
{
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
if (udpData.ContainsKey($"{ipAddr}-{taskID}") &&
udpData.TryGetValue($"{ipAddr}-{taskID}", out var dataQueue) &&
dataQueue.Count > 0)
{
data = dataQueue.ToList();
@@ -226,9 +235,9 @@ public class UDPServer
/// <param name="timeout">超时时间范围</param>
/// <returns>接收响应包</returns>
public async ValueTask<Result<WebProtocol.RecvRespPackage>> WaitForAckAsync
(string address, int port = -1, int timeout = 1000)
(string address, int taskID, int port = -1, int timeout = 1000)
{
var data = await FindDataAsync(address, timeout);
var data = await FindDataAsync(address, taskID, timeout);
if (!data.HasValue)
return new(new Exception("Get None even after time out!"));
@@ -251,9 +260,9 @@ public class UDPServer
/// <param name="timeout">超时时间范围</param>
/// <returns>接收数据包</returns>
public async ValueTask<Result<RecvDataPackage>> WaitForDataAsync
(string address, int port = -1, int timeout = 1000)
(string address, int taskID, int port = -1, int timeout = 1000)
{
var data = await FindDataAsync(address, timeout);
var data = await FindDataAsync(address, taskID, timeout);
if (!data.HasValue)
return new(new Exception("Get None even after time out!"));
@@ -284,7 +293,7 @@ public class UDPServer
// Handle Package
var udpData = RecordUDPData(bytes, remoteEP);
var udpData = RecordUDPData(bytes, remoteEP, Convert.ToInt32(bytes[1]));
PrintData(udpData);
BEGIN_RECEIVE:
@@ -308,7 +317,7 @@ public class UDPServer
else { return false; }
}
private UDPData RecordUDPData(byte[] bytes, IPEndPoint remoteEP)
private UDPData RecordUDPData(byte[] bytes, IPEndPoint remoteEP, int taskID)
{
var remoteAddress = remoteEP.Address.ToString();
var remotePort = remoteEP.Port;
@@ -316,6 +325,7 @@ public class UDPServer
{
Address = remoteAddress,
Port = remotePort,
TaskID = taskID,
Data = bytes,
DateTime = DateTime.Now,
HasRead = false,
@@ -324,7 +334,8 @@ public class UDPServer
using (udpData.AcquireWriteLock())
{
// Record UDP Receive Data
if (udpData.ContainsKey(remoteAddress) && udpData.TryGetValue(remoteAddress, out var dataQueue))
if (udpData.ContainsKey($"{remoteAddress}-{taskID}") &&
udpData.TryGetValue($"{remoteAddress}-{taskID}", out var dataQueue))
{
dataQueue.Enqueue(data);
logger.Trace("Receive data from old client");
@@ -333,7 +344,7 @@ public class UDPServer
{
var queue = new Queue<UDPData>();
queue.Enqueue(data);
udpData.Add(remoteAddress, queue);
udpData.Add($"{remoteAddress}-{taskID}", queue);
logger.Trace("Receive data from new client");
}
}
@@ -410,12 +421,12 @@ public class UDPServer
/// </summary>
/// <param name="ipAddr">IP地址</param>
/// <returns>无</returns>
public async Task ClearUDPData(string ipAddr)
public async Task ClearUDPData(string ipAddr, int taskID)
{
using (await udpData.AcquireWriteLockAsync())
{
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
if (udpData.ContainsKey($"{ipAddr}-{taskID}") &&
udpData.TryGetValue($"{ipAddr}-{taskID}", out var dataQueue) &&
dataQueue.Count > 0)
{
dataQueue.Clear();

View File

@@ -615,7 +615,7 @@ function onComponentDrag(e: MouseEvent) {
function stopComponentDrag() {
// 如果有组件被拖拽,保存当前状态
if (draggingComponentId.value) {
console.log(`组件拖拽结束: ${draggingComponentId.value}`);
// console.log(`组件拖拽结束: ${draggingComponentId.value}`);
// 保存图表数据
saveDiagramData(diagramData.value);

View File

@@ -385,6 +385,7 @@ const currentWaveformPath = computed(() => {
function selectWaveform(index: number) {
currentWaveformIndex.value = index;
updateModelValue();
applyOutputWave();
}
async function applyOutputWave() {
@@ -408,7 +409,7 @@ async function applyOutputWave() {
eqps.boardPort,
0,
currentWaveformIndex.value,
toInteger(frequency.value * Math.pow(2, 32 - 20)),
toInteger((frequency.value * Math.pow(2, 32 - 20)) / 10),
);
if (!ret) {
dialog.error("应用失败");
@@ -424,7 +425,7 @@ async function applyOutputWave() {
toInteger((phase.value * 4096) / 360),
);
if (ret) {
dialog.info("应用成功");
// dialog.info("应用成功");
} else {
dialog.error("应用失败");
}
@@ -455,6 +456,7 @@ function increaseFrequency() {
frequency.value = parseFloat(frequency.value.toFixed(1)); // 修复浮点数精度问题
frequencyInput.value = formatFrequency(frequency.value);
updateModelValue();
applyOutputWave();
}
function decreaseFrequency() {
@@ -475,6 +477,7 @@ function decreaseFrequency() {
frequency.value = parseFloat(frequency.value.toFixed(1)); // 修复浮点数精度问题
frequencyInput.value = formatFrequency(frequency.value);
updateModelValue();
applyOutputWave();
}
function applyFrequencyInput() {
@@ -505,6 +508,7 @@ function increasePhase() {
}
phaseInput.value = phase.value.toString();
updateModelValue();
applyOutputWave();
}
function decreasePhase() {
@@ -514,6 +518,7 @@ function decreasePhase() {
}
phaseInput.value = phase.value.toString();
updateModelValue();
applyOutputWave();
}
function applyPhaseInput() {

View File

@@ -177,26 +177,26 @@ defineExpose({
getPinPosition: (pinId: string) => {
// 如果是自定义的引脚ID
if (props.pins && props.pins.length > 0) {
console.log('SMT_LED查找Pin ID:', pinId);
console.log('SMT_LED组件尺寸:', props.size, '宽高:', width.value, 'x', height.value);
// console.log('SMT_LED查找Pin ID:', pinId);
// console.log('SMT_LED组件尺寸:', props.size, '宽高:', width.value, 'x', height.value);
const customPin = props.pins.find(p => p.pinId === pinId);
console.log('找到的引脚配置:', customPin);
// console.log('找到的引脚配置:', customPin);
if (customPin) {
// 考虑组件尺寸的缩放
const scaledX = customPin.x * props.size;
const scaledY = customPin.y * props.size;
console.log('使用Pin缩放后的坐标:', scaledX, scaledY);
// console.log('使用Pin缩放后的坐标:', scaledX, scaledY);
return {
x: scaledX,
y: scaledY
};
}
console.log('未找到匹配的引脚');
// console.log('未找到匹配的引脚');
return null;
}
console.log('没有引脚配置');
// console.log('没有引脚配置');
return null;
}
});

View File

@@ -153,7 +153,7 @@ async function loadComponentModule(type: string) {
[type]: module,
};
console.log(`Loaded module for ${type}:`, module);
// console.log(`Loaded module for ${type}:`, module);
} catch (error) {
console.error(`Failed to load component module ${type}:`, error);
return null;
@@ -164,7 +164,7 @@ async function loadComponentModule(type: string) {
// 处理组件模块加载请求
async function handleLoadComponentModule(type: string) {
console.log("Handling load component module request for:", type);
// console.log("Handling load component module request for:", type);
await loadComponentModule(type);
}
@@ -267,9 +267,9 @@ async function handleAddComponent(componentData: {
) {
try {
capsPage = componentModule.default.getCapabilities();
console.log(`获取到${componentData.type}组件的能力页面`);
// console.log(`获取到${componentData.type}组件的能力页面`);
} catch (error) {
console.error(`获取${componentData.type}组件能力页面失败:`, error);
// console.error(`获取${componentData.type}组件能力页面失败:`, error);
}
}
@@ -349,16 +349,16 @@ async function handleAddTemplate(templateData: {
// 计算视口中心点的坐标 (与handleAddComponent函数中的方法相同)
viewportCenter.x = (viewportWidth / 2 - position.x) / scale;
viewportCenter.y = (viewportHeight / 2 - position.y) / scale;
console.log(
`=== 计算的视口中心: x=${viewportCenter.x}, y=${viewportCenter.y}, scale=${scale}`,
);
// console.log(
// `=== 计算的视口中心: x=${viewportCenter.x}, y=${viewportCenter.y}, scale=${scale}`,
// );
}
}
} catch (error) {
console.error("获取视口中心位置时出错:", error);
}
console.log("=== 使用视口中心添加模板组件:", viewportCenter);
// console.log("=== 使用视口中心添加模板组件:", viewportCenter);
// 找到模板中的主要组件(假设是第一个组件)
const mainPart = templateData.template.parts[0];
@@ -398,9 +398,9 @@ async function handleAddTemplate(templateData: {
newPart.x = viewportCenter.x + relativeX;
newPart.y = viewportCenter.y + relativeY;
console.log(
`=== 组件[${newPart.id}]位置调整: (${oldX},${oldY}) -> (${newPart.x},${newPart.y})`,
);
// console.log(
// `=== 组件[${newPart.id}]位置调整: (${oldX},${oldY}) -> (${newPart.x},${newPart.y})`,
// );
}
return newPart;
@@ -541,7 +541,6 @@ async function handleComponentSelected(componentData: DiagramPart | null) {
// 处理图表数据更新事件
function handleDiagramUpdated(data: DiagramData) {
diagramData.value = data;
console.log("Diagram data updated:", data);
}
// 处理组件移动事件