feat: 更新网络配置后端及其api

This commit is contained in:
2025-07-17 20:46:37 +08:00
parent 08a9be543e
commit 0f4386457d
6 changed files with 1158 additions and 108 deletions

View File

@@ -1126,23 +1126,13 @@ export class DataClient {
/**
* 新增板子(管理员权限)
* @param name (optional)
* @param ipAddr (optional)
* @param port (optional)
*/
addBoard(name: string | undefined, ipAddr: string | undefined, port: number | undefined): Promise<number> {
addBoard(name: string | undefined): Promise<string> {
let url_ = this.baseUrl + "/api/Data/AddBoard?";
if (name === null)
throw new Error("The parameter 'name' cannot be null.");
else if (name !== undefined)
url_ += "name=" + encodeURIComponent("" + name) + "&";
if (ipAddr === null)
throw new Error("The parameter 'ipAddr' cannot be null.");
else if (ipAddr !== undefined)
url_ += "ipAddr=" + encodeURIComponent("" + ipAddr) + "&";
if (port === null)
throw new Error("The parameter 'port' cannot be null.");
else if (port !== undefined)
url_ += "port=" + encodeURIComponent("" + port) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
@@ -1157,7 +1147,7 @@ export class DataClient {
});
}
protected processAddBoard(response: Response): Promise<number> {
protected processAddBoard(response: Response): Promise<string> {
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) {
@@ -1184,7 +1174,7 @@ export class DataClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<number>(null as any);
return Promise.resolve<string>(null as any);
}
/**
@@ -2689,6 +2679,269 @@ export class NetConfigClient {
this.baseUrl = baseUrl ?? "http://localhost:5000";
}
/**
* 获取主机IP地址
* @return 主机IP地址
*/
getHostIP(): Promise<string> {
let url_ = this.baseUrl + "/api/NetConfig/GetHostIP";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetHostIP(_response);
});
}
protected processGetHostIP(response: Response): Promise<string> {
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 === 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<string>(null as any);
}
/**
* 获取板卡IP地址
* @return 板卡IP地址
*/
getBoardIP(): Promise<string> {
let url_ = this.baseUrl + "/api/NetConfig/GetBoardIP";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetBoardIP(_response);
});
}
protected processGetBoardIP(response: Response): Promise<string> {
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 === 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<string>(null as any);
}
/**
* 获取主机MAC地址
* @return 主机MAC地址
*/
getHostMAC(): Promise<string> {
let url_ = this.baseUrl + "/api/NetConfig/GetHostMAC";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetHostMAC(_response);
});
}
protected processGetHostMAC(response: Response): Promise<string> {
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 === 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<string>(null as any);
}
/**
* 获取板卡MAC地址
* @return 板卡MAC地址
*/
getBoardMAC(): Promise<string> {
let url_ = this.baseUrl + "/api/NetConfig/GetBoardMAC";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetBoardMAC(_response);
});
}
protected processGetBoardMAC(response: Response): Promise<string> {
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 === 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<string>(null as any);
}
/**
* 获取所有网络配置信息
* @return 网络配置信息
*/
getNetworkConfig(): Promise<NetworkConfigDto> {
let url_ = this.baseUrl + "/api/NetConfig/GetNetworkConfig";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetNetworkConfig(_response);
});
}
protected processGetNetworkConfig(response: Response): Promise<NetworkConfigDto> {
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 = NetworkConfigDto.fromJS(resultData200);
return result200;
});
} 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<NetworkConfigDto>(null as any);
}
/**
* 获取本机所有网络接口信息
* @return 网络接口信息列表
*/
getLocalNetworkInterfaces(): Promise<NetworkInterfaceDto[]> {
let url_ = this.baseUrl + "/api/NetConfig/GetLocalNetworkInterfaces";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetLocalNetworkInterfaces(_response);
});
}
protected processGetLocalNetworkInterfaces(response: Response): Promise<NetworkInterfaceDto[]> {
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);
if (Array.isArray(resultData200)) {
result200 = [] as any;
for (let item of resultData200)
result200!.push(NetworkInterfaceDto.fromJS(item));
}
else {
result200 = <any>null;
}
return result200;
});
} 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<NetworkInterfaceDto[]>(null as any);
}
/**
* 设置主机IP地址
* @param hostIp (optional) 主机IP地址
@@ -2854,6 +3107,49 @@ export class NetConfigClient {
return Promise.resolve<boolean>(null as any);
}
/**
* 自动获取本机IP地址并设置为实验板主机IP
* @return 操作结果
*/
updateHostIP(): Promise<boolean> {
let url_ = this.baseUrl + "/api/NetConfig/UpdateHostIP";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processUpdateHostIP(_response);
});
}
protected processUpdateHostIP(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 === 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地址
* @return 操作结果
@@ -4033,6 +4329,8 @@ export class Board implements IBoard {
boardName!: string;
/** FPGA 板子的IP地址 */
ipAddr!: string;
/** FPGA 板子的MAC地址 */
macAddr!: string;
/** FPGA 板子的通信端口 */
port!: number;
/** FPGA 板子的当前状态 */
@@ -4058,6 +4356,7 @@ export class Board implements IBoard {
this.id = _data["id"];
this.boardName = _data["boardName"];
this.ipAddr = _data["ipAddr"];
this.macAddr = _data["macAddr"];
this.port = _data["port"];
this.status = _data["status"];
this.occupiedUserID = _data["occupiedUserID"];
@@ -4078,6 +4377,7 @@ export class Board implements IBoard {
data["id"] = this.id;
data["boardName"] = this.boardName;
data["ipAddr"] = this.ipAddr;
data["macAddr"] = this.macAddr;
data["port"] = this.port;
data["status"] = this.status;
data["occupiedUserID"] = this.occupiedUserID;
@@ -4095,6 +4395,8 @@ export interface IBoard {
boardName: string;
/** FPGA 板子的IP地址 */
ipAddr: string;
/** FPGA 板子的MAC地址 */
macAddr: string;
/** FPGA 板子的通信端口 */
port: number;
/** FPGA 板子的当前状态 */
@@ -4109,8 +4411,9 @@ export interface IBoard {
/** FPGA 板子状态枚举 */
export enum BoardStatus {
Busy = 0,
Available = 1,
Disabled = 0,
Busy = 1,
Available = 2,
}
export class SystemException extends Exception implements ISystemException {
@@ -4325,6 +4628,145 @@ export interface ISignalTriggerConfig {
value: SignalValue;
}
/** 网络配置数据传输对象 */
export class NetworkConfigDto implements INetworkConfigDto {
/** 主机IP地址 */
hostIP?: string | undefined;
/** 板卡IP地址 */
boardIP?: string | undefined;
/** 主机MAC地址 */
hostMAC?: string | undefined;
/** 板卡MAC地址 */
boardMAC?: string | undefined;
constructor(data?: INetworkConfigDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.hostIP = _data["hostIP"];
this.boardIP = _data["boardIP"];
this.hostMAC = _data["hostMAC"];
this.boardMAC = _data["boardMAC"];
}
}
static fromJS(data: any): NetworkConfigDto {
data = typeof data === 'object' ? data : {};
let result = new NetworkConfigDto();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["hostIP"] = this.hostIP;
data["boardIP"] = this.boardIP;
data["hostMAC"] = this.hostMAC;
data["boardMAC"] = this.boardMAC;
return data;
}
}
/** 网络配置数据传输对象 */
export interface INetworkConfigDto {
/** 主机IP地址 */
hostIP?: string | undefined;
/** 板卡IP地址 */
boardIP?: string | undefined;
/** 主机MAC地址 */
hostMAC?: string | undefined;
/** 板卡MAC地址 */
boardMAC?: string | undefined;
}
/** 网络接口信息数据传输对象 */
export class NetworkInterfaceDto implements INetworkInterfaceDto {
/** 网络接口名称 */
name!: string;
/** 网络接口描述 */
description!: string;
/** 网络接口类型 */
type!: string;
/** 网络接口状态 */
status!: string;
/** IP地址列表 */
ipAddresses!: string[];
/** MAC地址 */
macAddress!: string;
constructor(data?: INetworkInterfaceDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
if (!data) {
this.ipAddresses = [];
}
}
init(_data?: any) {
if (_data) {
this.name = _data["name"];
this.description = _data["description"];
this.type = _data["type"];
this.status = _data["status"];
if (Array.isArray(_data["ipAddresses"])) {
this.ipAddresses = [] as any;
for (let item of _data["ipAddresses"])
this.ipAddresses!.push(item);
}
this.macAddress = _data["macAddress"];
}
}
static fromJS(data: any): NetworkInterfaceDto {
data = typeof data === 'object' ? data : {};
let result = new NetworkInterfaceDto();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["name"] = this.name;
data["description"] = this.description;
data["type"] = this.type;
data["status"] = this.status;
if (Array.isArray(this.ipAddresses)) {
data["ipAddresses"] = [];
for (let item of this.ipAddresses)
data["ipAddresses"].push(item);
}
data["macAddress"] = this.macAddress;
return data;
}
}
/** 网络接口信息数据传输对象 */
export interface INetworkInterfaceDto {
/** 网络接口名称 */
name: string;
/** 网络接口描述 */
description: string;
/** 网络接口类型 */
type: string;
/** 网络接口状态 */
status: string;
/** IP地址列表 */
ipAddresses: string[];
/** MAC地址 */
macAddress: string;
}
/** Package options which to send address to read or write */
export class SendAddrPackOptions implements ISendAddrPackOptions {
/** 突发类型 */