feat: 实现逻辑分析仪的捕获功能

This commit is contained in:
2025-07-15 20:37:25 +08:00
parent c70cc46aa9
commit 446da52515
2 changed files with 72 additions and 3 deletions

View File

@@ -262,6 +262,11 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
// 2. 轮询捕获状态
const pollCaptureStatus = async (): Promise<boolean> => {
// 如果不再处于捕获状态,说明被停止了
if (!isCapturing.value) {
return false;
}
const status = await client.getCaptureStatus();
// 检查是否捕获完成
@@ -285,7 +290,13 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
};
// 等待捕获完成
await pollCaptureStatus();
const captureCompleted = await pollCaptureStatus();
// 如果捕获被停止,不继续处理数据
if (!captureCompleted) {
alert?.info("捕获已停止", 2000);
return;
}
// 3. 获取捕获数据
const base64Data = await client.getCaptureData();
@@ -341,6 +352,35 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
}
};
const stopCapture = async () => {
// 检查是否正在捕获
if (!isCapturing.value) {
alert.warn("当前没有正在进行的捕获操作", 2000);
return;
}
try {
const client = AuthManager.createAuthenticatedLogicAnalyzerClient();
// 执行强制捕获来停止当前捕获
const forceSuccess = await client.setCaptureMode(false, true);
if (!forceSuccess) {
throw new Error("无法执行强制捕获");
}
// 设置捕获状态为false这会使轮询停止
isCapturing.value = false;
alert?.info("正在停止捕获...", 2000);
} catch (error) {
console.error("停止捕获失败:", error);
alert?.error(
`停止捕获失败: ${error instanceof Error ? error.message : "未知错误"}`,
3000,
);
}
};
// 添加检查操作状态的计算属性
const isOperationInProgress = computed(
() => isApplying.value || isCapturing.value || operationMutex.isLocked(),
@@ -446,6 +486,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
resetConfiguration,
setLogicData,
startCapture,
stopCapture, // 添加停止捕获方法
generateTestData,
};
},