Merge branch 'master' of ssh://git.swordlost.top:222/SikongJueluo/FPGA_WebLab into dpp
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref, reactive, watchPostEffect, onMounted, onUnmounted } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { isString, toNumber, type Dictionary } from "lodash";
|
||||
import { isString, toNumber, isUndefined, type Dictionary } from "lodash";
|
||||
import z from "zod";
|
||||
import { isNumber } from "mathjs";
|
||||
import { Mutex, withTimeout } from "async-mutex";
|
||||
@@ -9,9 +9,10 @@ import { useConstraintsStore } from "@/stores/constraints";
|
||||
import { useDialogStore } from "./dialog";
|
||||
import { toFileParameterOrUndefined } from "@/utils/Common";
|
||||
import { AuthManager } from "@/utils/AuthManager";
|
||||
import { HubConnectionBuilder } from "@microsoft/signalr";
|
||||
import { HubConnection, HubConnectionBuilder } from "@microsoft/signalr";
|
||||
import { getHubProxyFactory, getReceiverRegister } from "@/TypedSignalR.Client";
|
||||
import type { ResourceInfo } from "@/APIClient";
|
||||
import type { IJtagHub } from "@/TypedSignalR.Client/server.Hubs.JtagHub";
|
||||
|
||||
export const useEquipments = defineStore("equipments", () => {
|
||||
// Global Stores
|
||||
@@ -30,22 +31,32 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
1000,
|
||||
new Error("JtagClient Mutex Timeout!"),
|
||||
);
|
||||
const jtagHubConnection = new HubConnectionBuilder()
|
||||
.withUrl("http://localhost:5000/hubs/JtagHub")
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
const jtagHubProxy =
|
||||
getHubProxyFactory("IJtagHub").createHubProxy(jtagHubConnection);
|
||||
const jtagHubSubscription = getReceiverRegister("IJtagReceiver").register(
|
||||
jtagHubConnection,
|
||||
{
|
||||
const jtagHubConnection = ref<HubConnection>();
|
||||
const jtagHubProxy = ref<IJtagHub>();
|
||||
|
||||
onMounted(async () => {
|
||||
// 每次挂载都重新创建连接
|
||||
jtagHubConnection.value =
|
||||
AuthManager.createAuthenticatedJtagHubConnection();
|
||||
jtagHubProxy.value = getHubProxyFactory("IJtagHub").createHubProxy(
|
||||
jtagHubConnection.value,
|
||||
);
|
||||
|
||||
getReceiverRegister("IJtagReceiver").register(jtagHubConnection.value, {
|
||||
onReceiveBoundaryScanData: async (msg) => {
|
||||
constrainsts.batchSetConstraintStates(msg);
|
||||
},
|
||||
},
|
||||
);
|
||||
onMounted(() => {
|
||||
});
|
||||
await jtagHubConnection.value.start();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
// 断开连接,清理资源
|
||||
if (jtagHubConnection.value) {
|
||||
jtagHubConnection.value.stop();
|
||||
jtagHubConnection.value = undefined;
|
||||
jtagHubProxy.value = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
// Matrix Key
|
||||
@@ -89,13 +100,27 @@ export const useEquipments = defineStore("equipments", () => {
|
||||
}
|
||||
|
||||
async function jtagBoundaryScanSetOnOff(enable: boolean) {
|
||||
jtagHubConnection.start();
|
||||
enableJtagBoundaryScan.value = enable;
|
||||
if (enable) {
|
||||
jtagHubProxy.startBoundaryScan(jtagBoundaryScanFreq.value);
|
||||
} else {
|
||||
jtagHubProxy.stopBoundaryScan();
|
||||
if (isUndefined(jtagHubProxy.value)) {
|
||||
console.error("JtagHub Not Initialize...");
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
const ret = await jtagHubProxy.value.startBoundaryScan(
|
||||
jtagBoundaryScanFreq.value,
|
||||
);
|
||||
if (!ret) {
|
||||
console.error("Failed to start boundary scan");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
const ret = await jtagHubProxy.value.stopBoundaryScan();
|
||||
if (!ret) {
|
||||
console.error("Failed to stop boundary scan");
|
||||
return;
|
||||
}
|
||||
}
|
||||
enableJtagBoundaryScan.value = enable;
|
||||
}
|
||||
|
||||
async function jtagUploadBitstream(bitstream: File, examId?: string): Promise<number | null> {
|
||||
|
||||
@@ -16,7 +16,10 @@ import {
|
||||
ExamClient,
|
||||
ResourceClient,
|
||||
} from "@/APIClient";
|
||||
import router from "@/router";
|
||||
import { HubConnectionBuilder } from "@microsoft/signalr";
|
||||
import axios, { type AxiosInstance } from "axios";
|
||||
import { isNull } from "lodash";
|
||||
|
||||
// 支持的客户端类型联合类型
|
||||
type SupportedClient =
|
||||
@@ -119,7 +122,7 @@ export class AuthManager {
|
||||
if (!token) return null;
|
||||
|
||||
const instance = axios.create();
|
||||
instance.interceptors.request.use(config => {
|
||||
instance.interceptors.request.use((config) => {
|
||||
config.headers = config.headers || {};
|
||||
(config.headers as any)["Authorization"] = `Bearer ${token}`;
|
||||
return config;
|
||||
@@ -185,11 +188,11 @@ export class AuthManager {
|
||||
public static createAuthenticatedNetConfigClient(): NetConfigClient {
|
||||
return AuthManager.createAuthenticatedClient(NetConfigClient);
|
||||
}
|
||||
|
||||
|
||||
public static createAuthenticatedOscilloscopeApiClient(): OscilloscopeApiClient {
|
||||
return AuthManager.createAuthenticatedClient(OscilloscopeApiClient);
|
||||
}
|
||||
|
||||
|
||||
public static createAuthenticatedDebuggerClient(): DebuggerClient {
|
||||
return AuthManager.createAuthenticatedClient(DebuggerClient);
|
||||
}
|
||||
@@ -201,6 +204,21 @@ export class AuthManager {
|
||||
public static createAuthenticatedResourceClient(): ResourceClient {
|
||||
return AuthManager.createAuthenticatedClient(ResourceClient);
|
||||
}
|
||||
|
||||
public static createAuthenticatedJtagHubConnection() {
|
||||
const token = this.getToken();
|
||||
if (isNull(token)) {
|
||||
router.push("/login");
|
||||
throw Error("Token Null!");
|
||||
}
|
||||
|
||||
return new HubConnectionBuilder()
|
||||
.withUrl("http://127.0.0.1:5000/hubs/JtagHub", {
|
||||
accessTokenFactory: () => token,
|
||||
})
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
}
|
||||
|
||||
// 登录函数
|
||||
public static async login(
|
||||
|
||||
Reference in New Issue
Block a user