feat: 统一资源管理
This commit is contained in:
@@ -11,6 +11,7 @@ import { toFileParameterOrUndefined } from "@/utils/Common";
|
||||
import { AuthManager } from "@/utils/AuthManager";
|
||||
import { HubConnectionBuilder } from "@microsoft/signalr";
|
||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
|
||||
import type { ResourceInfo } from "@/APIClient";
|
||||
|
||||
export const useEquipments = defineStore("equipments", () => {
|
||||
// Global Stores
|
||||
@@ -23,6 +24,7 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
// Jtag
|
||||
const jtagBitstream = ref<File>();
|
||||
const jtagBoundaryScanFreq = ref(100);
|
||||
const jtagUserBitstreams = ref<ResourceInfo[]>([]);
|
||||
const jtagClientMutex = withTimeout(
|
||||
new Mutex(),
|
||||
1000,
|
||||
@@ -96,25 +98,38 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function jtagUploadBitstream(bitstream: File): Promise<boolean> {
|
||||
async function jtagUploadBitstream(bitstream: File, examId?: string): Promise<number | null> {
|
||||
try {
|
||||
// 自动开启电源
|
||||
await powerSetOnOff(true);
|
||||
|
||||
const jtagClient = AuthManager.createAuthenticatedJtagClient();
|
||||
const resp = await jtagClient.uploadBitstream(
|
||||
boardAddr.value,
|
||||
const resourceClient = AuthManager.createAuthenticatedResourceClient();
|
||||
const resp = await resourceClient.addResource(
|
||||
'bitstream',
|
||||
'user',
|
||||
examId || null,
|
||||
toFileParameterOrUndefined(bitstream),
|
||||
);
|
||||
return resp;
|
||||
|
||||
// 如果上传成功,设置为当前选中的比特流
|
||||
if (resp && resp.id !== undefined && resp.id !== null) {
|
||||
return resp.id;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
dialog.error("上传错误");
|
||||
console.error(e);
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function jtagDownloadBitstream(): Promise<boolean> {
|
||||
async function jtagDownloadBitstream(bitstreamId?: number): Promise<boolean> {
|
||||
if (bitstreamId === null || bitstreamId === undefined) {
|
||||
dialog.error("请先选择要下载的比特流");
|
||||
return false;
|
||||
}
|
||||
|
||||
const release = await jtagClientMutex.acquire();
|
||||
try {
|
||||
// 自动开启电源
|
||||
@@ -124,10 +139,11 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
const resp = await jtagClient.downloadBitstream(
|
||||
boardAddr.value,
|
||||
boardPort.value,
|
||||
bitstreamId,
|
||||
);
|
||||
return resp;
|
||||
} catch (e) {
|
||||
dialog.error("上传错误");
|
||||
dialog.error("下载错误");
|
||||
console.error(e);
|
||||
return false;
|
||||
} finally {
|
||||
@@ -256,6 +272,7 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
jtagBoundaryScanSetOnOff,
|
||||
jtagBitstream,
|
||||
jtagBoundaryScanFreq,
|
||||
jtagUserBitstreams,
|
||||
jtagUploadBitstream,
|
||||
jtagDownloadBitstream,
|
||||
jtagGetIDCode,
|
||||
|
||||
Reference in New Issue
Block a user