fix: 修复前端显示问题与后端无法读取Debugger数据的问题

This commit is contained in:
SikongJueluo 2025-07-30 20:26:14 +08:00
parent 82bc03b9fb
commit 2f1be8b0b7
No known key found for this signature in database
3 changed files with 57 additions and 93 deletions

View File

@ -246,46 +246,6 @@ public class DebuggerController : ControllerBase
} }
} }
/// <summary>
/// 重新开始触发(刷新后再启动触发器)
/// </summary>
[HttpPost("RestartTrigger")]
[EnableCors("Users")]
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> RestartTrigger()
{
try
{
var debugger = GetDebugger();
if (debugger == null)
return BadRequest("用户未绑定有效的实验板");
var refreshResult = await debugger.Refresh();
if (!refreshResult.IsSuccessful)
{
logger.Error($"刷新调试器状态失败: {refreshResult.Error}");
return StatusCode(StatusCodes.Status500InternalServerError, "刷新调试器状态失败");
}
var startResult = await debugger.StartTrigger();
if (!startResult.IsSuccessful)
{
logger.Error($"启动触发器失败: {startResult.Error}");
return StatusCode(StatusCodes.Status500InternalServerError, "启动触发器失败");
}
return Ok(startResult.Value);
}
catch (Exception ex)
{
logger.Error(ex, "重新开始触发时发生异常");
return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
}
}
/// <summary> /// <summary>
/// 读取触发器状态标志 /// 读取触发器状态标志
/// </summary> /// </summary>
@ -412,7 +372,15 @@ public class DebuggerController : ControllerBase
return StatusCode(StatusCodes.Status500InternalServerError, "读取捕获数据失败"); return StatusCode(StatusCodes.Status500InternalServerError, "读取捕获数据失败");
} }
var freshResult = await debugger.Refresh();
if (!freshResult.IsSuccessful)
{
logger.Error($"刷新调试器状态失败: {freshResult.Error}");
return StatusCode(StatusCodes.Status500InternalServerError, "刷新调试器状态失败");
}
var rawData = dataResult.Value; var rawData = dataResult.Value;
logger.Debug($"rawData: {BitConverter.ToString(rawData)}");
int depth = (int)config.captureDepth; int depth = (int)config.captureDepth;
int portDataLen = 4 * depth; int portDataLen = 4 * depth;
int portNum = (int)config.totalPortNum; int portNum = (int)config.totalPortNum;
@ -442,6 +410,7 @@ public class DebuggerController : ControllerBase
UInt32 mask = (wireWidth == 32) ? 0xFFFFFFFF : ((1u << wireWidth) - 1u); UInt32 mask = (wireWidth == 32) ? 0xFFFFFFFF : ((1u << wireWidth) - 1u);
channelUintArr[i] = (sample >> wireStart) & mask; channelUintArr[i] = (sample >> wireStart) & mask;
} }
logger.Debug($"{channel.name} HexData: {BitConverter.ToString(channelUintArr.SelectMany(BitConverter.GetBytes).ToArray())}");
var base64 = Convert.ToBase64String(channelUintArr.SelectMany(BitConverter.GetBytes).ToArray()); var base64 = Convert.ToBase64String(channelUintArr.SelectMany(BitConverter.GetBytes).ToArray());
channelDataList.Add(new ChannelCaptureData { name = channel.name, data = base64 }); channelDataList.Add(new ChannelCaptureData { name = channel.name, data = base64 });
} }

View File

@ -213,7 +213,7 @@ public class DebuggerClient
{ {
var captureData = new byte[1024 * 4 * portNum]; var captureData = new byte[1024 * 4 * portNum];
{ {
var ret = await UDPClientPool.ReadAddr4BytesAsync(this.ep, this.taskID, this.captureDataAddr, captureData.Length, this.timeout); var ret = await UDPClientPool.ReadAddr4Bytes(this.ep, this.taskID, this.captureDataAddr, captureData.Length / 4, this.timeout);
if (!ret.IsSuccessful) if (!ret.IsSuccessful)
{ {
logger.Error($"Failed to read data: {ret.Error}"); logger.Error($"Failed to read data: {ret.Error}");

View File

@ -10,7 +10,12 @@
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<button <button
class="btn btn-sm btn-primary" class="btn btn-sm btn-primary"
@click="startCapture(true)" @click="
() => {
handleDeleteData();
startCapture();
}
"
:disabled="!captureData" :disabled="!captureData"
> >
重新捕获 重新捕获
@ -137,7 +142,7 @@
<span>显示</span> <span>显示</span>
<span>颜色</span> <span>颜色</span>
<span>触发模式</span> <span>触发模式</span>
<span>数据位宽(起始:宽度)</span> <span>数据位宽(起始:结尾)</span>
<span>父端口编号</span> <span>父端口编号</span>
<span>操作</span> <span>操作</span>
</div> </div>
@ -177,7 +182,7 @@
<input <input
v-model="ch.widthStr" v-model="ch.widthStr"
class="input input-bordered w-full" class="input input-bordered w-full"
placeholder="如0:8" placeholder="如0:7"
@change="parseWidthStr(idx)" @change="parseWidthStr(idx)"
/> />
<input <input
@ -280,7 +285,7 @@ interface DebugChannel {
color: string; color: string;
trigger: CaptureMode; trigger: CaptureMode;
width: number; width: number;
widthStr: string; // "start:" widthStr: string;
start: number; start: number;
parentPort: number; parentPort: number;
} }
@ -355,7 +360,7 @@ function addChannel() {
color: "#00bcd4", color: "#00bcd4",
trigger: CaptureMode.None, trigger: CaptureMode.None,
width: 1, width: 1,
widthStr: "0:1", widthStr: "0:0",
start: 0, start: 0,
parentPort: 0, parentPort: 0,
}); });
@ -377,7 +382,7 @@ function stopCapture() {
} }
} }
async function startCapture(isRestart = false) { async function startCapture() {
if (!configInited.value) { if (!configInited.value) {
alert.error("请先配置调试器基本参数"); alert.error("请先配置调试器基本参数");
return; return;
@ -386,34 +391,33 @@ async function startCapture(isRestart = false) {
alert.error("请至少添加一个通道"); alert.error("请至少添加一个通道");
return; return;
} }
// //
if (!isRestart) { let usedWires = 0;
let usedWires = 0; for (let i = 0; i < channels.value.length; i++) {
for (let i = 0; i < channels.value.length; i++) { const ch = channels.value[i];
const ch = channels.value[i]; if (!ch.visible) continue;
if (!ch.visible) continue; if (!ch.name) {
if (!ch.name) { alert.error(`通道 ${i + 1} 名称不能为空`);
alert.error(`通道 ${i + 1} 名称不能为空`);
return;
}
if (ch.width < 1 || ch.width > 32) {
alert.error(`通道 ${i + 1} 数据位宽必须在1到32之间`);
return;
}
if (ch.start < 0 || ch.start + ch.width > 32) {
alert.error(`通道 ${i + 1} 起始位+宽度不能超过32`);
return;
}
if (ch.parentPort < 0 || ch.parentPort >= config.totalPortNum) {
alert.error(`通道 ${i + 1} 父端口编号超出范围`);
return;
}
usedWires += ch.width;
}
if (usedWires > config.totalPortNum * 32) {
alert.error("所有通道线宽总和不能超过最大线宽数");
return; return;
} }
if (ch.width < 1 || ch.width > 32) {
alert.error(`通道 ${i + 1} 数据位宽必须在1到32之间`);
return;
}
if (ch.start < 0 || ch.start + ch.width > 32) {
alert.error(`通道 ${i + 1} 起始位+宽度不能超过32`);
return;
}
if (ch.parentPort < 0 || ch.parentPort >= config.totalPortNum) {
alert.error(`通道 ${i + 1} 父端口编号超出范围`);
return;
}
usedWires += ch.width;
}
if (usedWires > config.totalPortNum * 32) {
alert.error("所有通道线宽总和不能超过最大线宽数");
return;
} }
isCapturing.value = true; isCapturing.value = true;
@ -444,28 +448,19 @@ async function startCapture(isRestart = false) {
try { try {
// //
if (!isRestart) { let ret = await client.setChannelsMode(apiConfig);
let ret = await client.setChannelsMode(apiConfig); if (!ret) {
if (!ret) { alert.error("设置通道模式失败");
alert.error("设置通道模式失败"); isCapturing.value = false;
isCapturing.value = false; return;
return; }
}
// //
ret = await client.startTrigger(); ret = await client.startTrigger();
if (!ret) { if (!ret) {
alert.error("开始捕获失败,请检查连接"); alert.error("开始捕获失败,请检查连接");
isCapturing.value = false; isCapturing.value = false;
return; return;
}
} else {
let ret = await client.restartTrigger();
if (!ret) {
alert.error("重新开始捕获失败,请检查连接");
isCapturing.value = false;
return;
}
} }
// //