feat: 添加示波器前后端

This commit is contained in:
2025-07-18 21:49:37 +08:00
parent ba79a2093b
commit e4a1c34a6c
10 changed files with 1743 additions and 91 deletions

View File

@@ -3170,6 +3170,61 @@ export class NetConfigClient {
return Promise.resolve<boolean>(null as any);
}
/**
* 设置板卡MAC地址
* @param boardMac (optional) 板卡MAC地址格式AA:BB:CC:DD:EE:FF
* @return 操作结果
*/
setBoardMAC(boardMac: string | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/NetConfig/SetBoardMAC?";
if (boardMac === null)
throw new Error("The parameter 'boardMac' cannot be null.");
else if (boardMac !== undefined)
url_ += "boardMac=" + encodeURIComponent("" + boardMac) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processSetBoardMAC(_response);
});
}
protected processSetBoardMAC(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 设置主机MAC地址
* @param hostMac (optional) 主机MAC地址格式AA:BB:CC:DD:EE:FF
@@ -3319,31 +3374,81 @@ export class NetConfigClient {
}
/**
* 设置板卡MAC地址
* @param boardMac (optional) 板卡MAC地址格式AA:BB:CC:DD:EE:FF
* @return 操作结果
* 获取本机网络信息
* @return 本机网络信息
*/
setBoardMAC(boardMac: string | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/NetConfig/SetBoardMAC?";
if (boardMac === null)
throw new Error("The parameter 'boardMac' cannot be null.");
else if (boardMac !== undefined)
url_ += "boardMac=" + encodeURIComponent("" + boardMac) + "&";
getLocalNetworkInfo(): Promise<any> {
let url_ = this.baseUrl + "/api/NetConfig/GetLocalNetworkInfo";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processSetBoardMAC(_response);
return this.processGetLocalNetworkInfo(_response);
});
}
protected processSetBoardMAC(response: Response): Promise<boolean> {
protected processGetLocalNetworkInfo(response: Response): Promise<any> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<any>(null as any);
}
}
export class OscilloscopeApiClient {
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
private baseUrl: string;
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
this.http = http ? http : window as any;
this.baseUrl = baseUrl ?? "http://localhost:5000";
}
/**
* 初始化示波器
* @param config 示波器配置
* @return 操作结果
*/
initialize(config: OscilloscopeFullConfig): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/Initialize";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(config);
let options_: RequestInit = {
body: content_,
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processInitialize(_response);
});
}
protected processInitialize(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
@@ -3365,6 +3470,374 @@ export class NetConfigClient {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 启动捕获
* @return 操作结果
*/
startCapture(): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/StartCapture";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processStartCapture(_response);
});
}
protected processStartCapture(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 停止捕获
* @return 操作结果
*/
stopCapture(): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/StopCapture";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processStopCapture(_response);
});
}
protected processStopCapture(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 获取示波器数据和状态
* @return 示波器数据和状态信息
*/
getData(): Promise<OscilloscopeDataResponse> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/GetData";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetData(_response);
});
}
protected processGetData(response: Response): Promise<OscilloscopeDataResponse> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = OscilloscopeDataResponse.fromJS(resultData200);
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<OscilloscopeDataResponse>(null as any);
}
/**
* 更新触发参数
* @param level (optional) 触发电平0-255
* @param risingEdge (optional) 触发边沿true为上升沿false为下降沿
* @return 操作结果
*/
updateTrigger(level: number | undefined, risingEdge: boolean | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/UpdateTrigger?";
if (level === null)
throw new Error("The parameter 'level' cannot be null.");
else if (level !== undefined)
url_ += "level=" + encodeURIComponent("" + level) + "&";
if (risingEdge === null)
throw new Error("The parameter 'risingEdge' cannot be null.");
else if (risingEdge !== undefined)
url_ += "risingEdge=" + encodeURIComponent("" + risingEdge) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processUpdateTrigger(_response);
});
}
protected processUpdateTrigger(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 更新采样参数
* @param horizontalShift (optional) 水平偏移量0-1023
* @param decimationRate (optional) 抽样率0-1023
* @return 操作结果
*/
updateSampling(horizontalShift: number | undefined, decimationRate: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/UpdateSampling?";
if (horizontalShift === null)
throw new Error("The parameter 'horizontalShift' cannot be null.");
else if (horizontalShift !== undefined)
url_ += "horizontalShift=" + encodeURIComponent("" + horizontalShift) + "&";
if (decimationRate === null)
throw new Error("The parameter 'decimationRate' cannot be null.");
else if (decimationRate !== undefined)
url_ += "decimationRate=" + encodeURIComponent("" + decimationRate) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processUpdateSampling(_response);
});
}
protected processUpdateSampling(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<boolean>(null as any);
}
/**
* 手动刷新RAM
* @return 操作结果
*/
refreshRAM(): Promise<boolean> {
let url_ = this.baseUrl + "/api/OscilloscopeApi/RefreshRAM";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processRefreshRAM(_response);
});
}
protected processRefreshRAM(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
@@ -4885,6 +5358,140 @@ export interface INetworkInterfaceDto {
macAddress: string;
}
/** 示波器完整配置 */
export class OscilloscopeFullConfig implements IOscilloscopeFullConfig {
/** 是否启动捕获 */
captureEnabled!: boolean;
/** 触发电平0-255 */
triggerLevel!: number;
/** 触发边沿true为上升沿false为下降沿 */
triggerRisingEdge!: boolean;
/** 水平偏移量0-1023 */
horizontalShift!: number;
/** 抽样率0-1023 */
decimationRate!: number;
/** 是否自动刷新RAM */
autoRefreshRAM!: boolean;
constructor(data?: IOscilloscopeFullConfig) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.captureEnabled = _data["captureEnabled"];
this.triggerLevel = _data["triggerLevel"];
this.triggerRisingEdge = _data["triggerRisingEdge"];
this.horizontalShift = _data["horizontalShift"];
this.decimationRate = _data["decimationRate"];
this.autoRefreshRAM = _data["autoRefreshRAM"];
}
}
static fromJS(data: any): OscilloscopeFullConfig {
data = typeof data === 'object' ? data : {};
let result = new OscilloscopeFullConfig();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["captureEnabled"] = this.captureEnabled;
data["triggerLevel"] = this.triggerLevel;
data["triggerRisingEdge"] = this.triggerRisingEdge;
data["horizontalShift"] = this.horizontalShift;
data["decimationRate"] = this.decimationRate;
data["autoRefreshRAM"] = this.autoRefreshRAM;
return data;
}
}
/** 示波器完整配置 */
export interface IOscilloscopeFullConfig {
/** 是否启动捕获 */
captureEnabled: boolean;
/** 触发电平0-255 */
triggerLevel: number;
/** 触发边沿true为上升沿false为下降沿 */
triggerRisingEdge: boolean;
/** 水平偏移量0-1023 */
horizontalShift: number;
/** 抽样率0-1023 */
decimationRate: number;
/** 是否自动刷新RAM */
autoRefreshRAM: boolean;
}
/** 示波器状态和数据 */
export class OscilloscopeDataResponse implements IOscilloscopeDataResponse {
/** AD采样频率 */
adFrequency!: number;
/** AD采样幅度 */
adVpp!: number;
/** AD采样最大值 */
adMax!: number;
/** AD采样最小值 */
adMin!: number;
/** 波形数据Base64编码 */
waveformData!: string;
constructor(data?: IOscilloscopeDataResponse) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.adFrequency = _data["adFrequency"];
this.adVpp = _data["adVpp"];
this.adMax = _data["adMax"];
this.adMin = _data["adMin"];
this.waveformData = _data["waveformData"];
}
}
static fromJS(data: any): OscilloscopeDataResponse {
data = typeof data === 'object' ? data : {};
let result = new OscilloscopeDataResponse();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["adFrequency"] = this.adFrequency;
data["adVpp"] = this.adVpp;
data["adMax"] = this.adMax;
data["adMin"] = this.adMin;
data["waveformData"] = this.waveformData;
return data;
}
}
/** 示波器状态和数据 */
export interface IOscilloscopeDataResponse {
/** AD采样频率 */
adFrequency: number;
/** AD采样幅度 */
adVpp: number;
/** AD采样最大值 */
adMax: number;
/** AD采样最小值 */
adMin: number;
/** 波形数据Base64编码 */
waveformData: string;
}
/** Package options which to send address to read or write */
export class SendAddrPackOptions implements ISendAddrPackOptions {
/** 突发类型 */