feat: 使用SignalR实时发送示波器数据,并美化示波器界面

This commit is contained in:
2025-08-19 12:55:18 +08:00
parent 1b5b0e28e3
commit 7e53b805ae
13 changed files with 1664 additions and 347 deletions

View File

@@ -45,7 +45,12 @@ export class AuthManager {
// SignalR连接 - 简单明了
static createHubConnection(
hubPath: "ProgressHub" | "JtagHub" | "DigitalTubesHub" | "RotaryEncoderHub",
hubPath:
| "ProgressHub"
| "JtagHub"
| "DigitalTubesHub"
| "RotaryEncoderHub"
| "OscilloscopeHub",
) {
return new HubConnectionBuilder()
.withUrl(`http://127.0.0.1:5000/hubs/${hubPath}`, {

View File

@@ -3,8 +3,8 @@
/* tslint:disable */
// @ts-nocheck
import type { HubConnection, IStreamResult, Subject } from '@microsoft/signalr';
import type { IDigitalTubesHub, IJtagHub, IProgressHub, IRotaryEncoderHub, IDigitalTubesReceiver, IJtagReceiver, IProgressReceiver, IRotaryEncoderReceiver } from './server.Hubs';
import type { DigitalTubeTaskStatus, ProgressInfo } from '../server.Hubs';
import type { IDigitalTubesHub, IJtagHub, IOscilloscopeHub, IProgressHub, IRotaryEncoderHub, IDigitalTubesReceiver, IJtagReceiver, IOscilloscopeReceiver, IProgressReceiver, IRotaryEncoderReceiver } from './server.Hubs';
import type { DigitalTubeTaskStatus, OscilloscopeFullConfig, OscilloscopeDataResponse, ProgressInfo } from '../server.Hubs';
import type { RotaryEncoderDirection } from '../Peripherals.RotaryEncoderClient';
@@ -46,6 +46,7 @@ class ReceiverMethodSubscription implements Disposable {
export type HubProxyFactoryProvider = {
(hubType: "IDigitalTubesHub"): HubProxyFactory<IDigitalTubesHub>;
(hubType: "IJtagHub"): HubProxyFactory<IJtagHub>;
(hubType: "IOscilloscopeHub"): HubProxyFactory<IOscilloscopeHub>;
(hubType: "IProgressHub"): HubProxyFactory<IProgressHub>;
(hubType: "IRotaryEncoderHub"): HubProxyFactory<IRotaryEncoderHub>;
}
@@ -57,6 +58,9 @@ export const getHubProxyFactory = ((hubType: string) => {
if(hubType === "IJtagHub") {
return IJtagHub_HubProxyFactory.Instance;
}
if(hubType === "IOscilloscopeHub") {
return IOscilloscopeHub_HubProxyFactory.Instance;
}
if(hubType === "IProgressHub") {
return IProgressHub_HubProxyFactory.Instance;
}
@@ -68,6 +72,7 @@ export const getHubProxyFactory = ((hubType: string) => {
export type ReceiverRegisterProvider = {
(receiverType: "IDigitalTubesReceiver"): ReceiverRegister<IDigitalTubesReceiver>;
(receiverType: "IJtagReceiver"): ReceiverRegister<IJtagReceiver>;
(receiverType: "IOscilloscopeReceiver"): ReceiverRegister<IOscilloscopeReceiver>;
(receiverType: "IProgressReceiver"): ReceiverRegister<IProgressReceiver>;
(receiverType: "IRotaryEncoderReceiver"): ReceiverRegister<IRotaryEncoderReceiver>;
}
@@ -79,6 +84,9 @@ export const getReceiverRegister = ((receiverType: string) => {
if(receiverType === "IJtagReceiver") {
return IJtagReceiver_Binder.Instance;
}
if(receiverType === "IOscilloscopeReceiver") {
return IOscilloscopeReceiver_Binder.Instance;
}
if(receiverType === "IProgressReceiver") {
return IProgressReceiver_Binder.Instance;
}
@@ -151,6 +159,55 @@ class IJtagHub_HubProxy implements IJtagHub {
}
}
class IOscilloscopeHub_HubProxyFactory implements HubProxyFactory<IOscilloscopeHub> {
public static Instance = new IOscilloscopeHub_HubProxyFactory();
private constructor() {
}
public readonly createHubProxy = (connection: HubConnection): IOscilloscopeHub => {
return new IOscilloscopeHub_HubProxy(connection);
}
}
class IOscilloscopeHub_HubProxy implements IOscilloscopeHub {
public constructor(private connection: HubConnection) {
}
public readonly initialize = async (config: OscilloscopeFullConfig): Promise<boolean> => {
return await this.connection.invoke("Initialize", config);
}
public readonly startCapture = async (): Promise<boolean> => {
return await this.connection.invoke("StartCapture");
}
public readonly stopCapture = async (): Promise<boolean> => {
return await this.connection.invoke("StopCapture");
}
public readonly getData = async (): Promise<OscilloscopeDataResponse> => {
return await this.connection.invoke("GetData");
}
public readonly setTrigger = async (level: number): Promise<boolean> => {
return await this.connection.invoke("SetTrigger", level);
}
public readonly setRisingEdge = async (risingEdge: boolean): Promise<boolean> => {
return await this.connection.invoke("SetRisingEdge", risingEdge);
}
public readonly setSampling = async (decimationRate: number): Promise<boolean> => {
return await this.connection.invoke("SetSampling", decimationRate);
}
public readonly setFrequency = async (frequency: number): Promise<boolean> => {
return await this.connection.invoke("SetFrequency", frequency);
}
}
class IProgressHub_HubProxyFactory implements HubProxyFactory<IProgressHub> {
public static Instance = new IProgressHub_HubProxyFactory();
@@ -258,6 +315,27 @@ class IJtagReceiver_Binder implements ReceiverRegister<IJtagReceiver> {
}
}
class IOscilloscopeReceiver_Binder implements ReceiverRegister<IOscilloscopeReceiver> {
public static Instance = new IOscilloscopeReceiver_Binder();
private constructor() {
}
public readonly register = (connection: HubConnection, receiver: IOscilloscopeReceiver): Disposable => {
const __onDataReceived = (...args: [OscilloscopeDataResponse]) => receiver.onDataReceived(...args);
connection.on("OnDataReceived", __onDataReceived);
const methodList: ReceiverMethod[] = [
{ methodName: "OnDataReceived", method: __onDataReceived }
]
return new ReceiverMethodSubscription(connection, methodList);
}
}
class IProgressReceiver_Binder implements ReceiverRegister<IProgressReceiver> {
public static Instance = new IProgressReceiver_Binder();

View File

@@ -3,7 +3,7 @@
/* tslint:disable */
// @ts-nocheck
import type { IStreamResult, Subject } from '@microsoft/signalr';
import type { DigitalTubeTaskStatus, ProgressInfo } from '../server.Hubs';
import type { DigitalTubeTaskStatus, OscilloscopeFullConfig, OscilloscopeDataResponse, ProgressInfo } from '../server.Hubs';
import type { RotaryEncoderDirection } from '../Peripherals.RotaryEncoderClient';
export type IDigitalTubesHub = {
@@ -43,6 +43,46 @@ export type IJtagHub = {
stopBoundaryScan(): Promise<boolean>;
}
export type IOscilloscopeHub = {
/**
* @param config Transpiled from server.Hubs.OscilloscopeFullConfig
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
initialize(config: OscilloscopeFullConfig): Promise<boolean>;
/**
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
startCapture(): Promise<boolean>;
/**
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
stopCapture(): Promise<boolean>;
/**
* @returns Transpiled from System.Threading.Tasks.Task<server.Hubs.OscilloscopeDataResponse?>
*/
getData(): Promise<OscilloscopeDataResponse>;
/**
* @param level Transpiled from byte
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
setTrigger(level: number): Promise<boolean>;
/**
* @param risingEdge Transpiled from bool
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
setRisingEdge(risingEdge: boolean): Promise<boolean>;
/**
* @param decimationRate Transpiled from ushort
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
setSampling(decimationRate: number): Promise<boolean>;
/**
* @param frequency Transpiled from int
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
setFrequency(frequency: number): Promise<boolean>;
}
export type IProgressHub = {
/**
* @param taskId Transpiled from string
@@ -102,6 +142,14 @@ export type IJtagReceiver = {
onReceiveBoundaryScanData(msg: Partial<Record<string, boolean>>): Promise<void>;
}
export type IOscilloscopeReceiver = {
/**
* @param data Transpiled from server.Hubs.OscilloscopeDataResponse
* @returns Transpiled from System.Threading.Tasks.Task
*/
onDataReceived(data: OscilloscopeDataResponse): Promise<void>;
}
export type IProgressReceiver = {
/**
* @param message Transpiled from server.Hubs.ProgressInfo

View File

@@ -10,6 +10,36 @@ export type DigitalTubeTaskStatus = {
isRunning: boolean;
}
/** Transpiled from server.Hubs.OscilloscopeDataResponse */
export type OscilloscopeDataResponse = {
/** Transpiled from uint */
aDFrequency: number;
/** Transpiled from byte */
aDVpp: number;
/** Transpiled from byte */
aDMax: number;
/** Transpiled from byte */
aDMin: number;
/** Transpiled from string */
waveformData: string;
}
/** Transpiled from server.Hubs.OscilloscopeFullConfig */
export type OscilloscopeFullConfig = {
/** Transpiled from bool */
captureEnabled: boolean;
/** Transpiled from byte */
triggerLevel: number;
/** Transpiled from bool */
triggerRisingEdge: boolean;
/** Transpiled from ushort */
horizontalShift: number;
/** Transpiled from ushort */
decimationRate: number;
/** Transpiled from int */
captureFrequency: number;
}
/** Transpiled from server.Hubs.ProgressStatus */
export enum ProgressStatus {
Running = 0,