diff --git a/server/src/Controllers/NetConfigController.cs b/server/src/Controllers/NetConfigController.cs index 078bd2a..ec9b2fc 100644 --- a/server/src/Controllers/NetConfigController.cs +++ b/server/src/Controllers/NetConfigController.cs @@ -15,12 +15,14 @@ namespace server.Controllers; public class NetConfigController : ControllerBase { private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + + // 固定的实验板IP和端口 + private const string BOARD_IP = "169.254.109.0"; + private const int BOARD_PORT = 1234; /// /// 设置主机IP地址 /// - /// 板卡IP地址 - /// 板卡端口 /// 主机IP地址 /// 操作结果 [HttpPost("SetHostIP")] @@ -28,27 +30,18 @@ public class NetConfigController : ControllerBase [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task SetHostIP(string boardIp, int boardPort, string hostIp) + public async Task SetHostIP(string hostIp) { - if (string.IsNullOrWhiteSpace(boardIp)) - return BadRequest("板卡IP地址不能为空"); - - if (boardPort <= 0 || boardPort > 65535) - return BadRequest("板卡端口号无效"); - if (string.IsNullOrWhiteSpace(hostIp)) return BadRequest("主机IP地址不能为空"); - if (!IPAddress.TryParse(boardIp, out _)) - return BadRequest("板卡IP地址格式不正确"); - if (!IPAddress.TryParse(hostIp, out var hostIpAddress)) return BadRequest("主机IP地址格式不正确"); try { // 创建网络配置客户端 - var netConfig = new NetConfig(boardIp, boardPort, 0); + var netConfig = new NetConfig(BOARD_IP, BOARD_PORT, 0); var result = await netConfig.SetHostIP(hostIpAddress); if (!result.IsSuccessful) @@ -69,8 +62,6 @@ public class NetConfigController : ControllerBase /// /// 设置板卡IP地址 /// - /// 当前板卡IP地址 - /// 板卡端口 /// 新的板卡IP地址 /// 操作结果 [HttpPost("SetBoardIP")] @@ -78,27 +69,18 @@ public class NetConfigController : ControllerBase [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task SetBoardIP(string currentBoardIp, int boardPort, string newBoardIp) + public async Task SetBoardIP(string newBoardIp) { - if (string.IsNullOrWhiteSpace(currentBoardIp)) - return BadRequest("当前板卡IP地址不能为空"); - - if (boardPort <= 0 || boardPort > 65535) - return BadRequest("板卡端口号无效"); - if (string.IsNullOrWhiteSpace(newBoardIp)) return BadRequest("新的板卡IP地址不能为空"); - if (!IPAddress.TryParse(currentBoardIp, out _)) - return BadRequest("当前板卡IP地址格式不正确"); - if (!IPAddress.TryParse(newBoardIp, out var newIpAddress)) return BadRequest("新的板卡IP地址格式不正确"); try { // 创建网络配置客户端 - var netConfig = new NetConfig(currentBoardIp, boardPort, 0); + var netConfig = new NetConfig(BOARD_IP, BOARD_PORT, 0); var result = await netConfig.SetBoardIP(newIpAddress); if (!result.IsSuccessful) @@ -119,8 +101,6 @@ public class NetConfigController : ControllerBase /// /// 设置主机MAC地址 /// - /// 板卡IP地址 - /// 板卡端口 /// 主机MAC地址(格式:AA:BB:CC:DD:EE:FF) /// 操作结果 [HttpPost("SetHostMAC")] @@ -128,20 +108,11 @@ public class NetConfigController : ControllerBase [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task SetHostMAC(string boardIp, int boardPort, string hostMac) + public async Task SetHostMAC(string hostMac) { - if (string.IsNullOrWhiteSpace(boardIp)) - return BadRequest("板卡IP地址不能为空"); - - if (boardPort <= 0 || boardPort > 65535) - return BadRequest("板卡端口号无效"); - if (string.IsNullOrWhiteSpace(hostMac)) return BadRequest("主机MAC地址不能为空"); - if (!IPAddress.TryParse(boardIp, out _)) - return BadRequest("板卡IP地址格式不正确"); - // 解析MAC地址 if (!TryParseMacAddress(hostMac, out var macBytes)) return BadRequest("MAC地址格式不正确,请使用格式:AA:BB:CC:DD:EE:FF"); @@ -149,7 +120,7 @@ public class NetConfigController : ControllerBase try { // 创建网络配置客户端 - var netConfig = new NetConfig(boardIp, boardPort, 0); + var netConfig = new NetConfig(BOARD_IP, BOARD_PORT, 0); var result = await netConfig.SetHostMAC(macBytes); if (!result.IsSuccessful) @@ -170,25 +141,14 @@ public class NetConfigController : ControllerBase /// /// 更新主机MAC地址 /// - /// 板卡IP地址 - /// 板卡端口 /// 操作结果 [HttpPost("UpdateHostMAC")] [EnableCors("Users")] [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task UpdateHostMAC(string boardIp, int boardPort) + public async Task UpdateHostMAC() { - if (string.IsNullOrWhiteSpace(boardIp)) - return BadRequest("板卡IP地址不能为空"); - - if (boardPort <= 0 || boardPort > 65535) - return BadRequest("板卡端口号无效"); - - if (!IPAddress.TryParse(boardIp, out _)) - return BadRequest("板卡IP地址格式不正确"); - byte[]? macBytes = null; try { @@ -204,7 +164,7 @@ public class NetConfigController : ControllerBase return StatusCode(StatusCodes.Status500InternalServerError, "无法获取本机MAC地址"); // 创建网络配置客户端 - var netConfig = new NetConfig(boardIp, boardPort, 0); + var netConfig = new NetConfig(BOARD_IP, BOARD_PORT, 0); var result = await netConfig.SetHostMAC(macBytes); if (!result.IsSuccessful) @@ -225,8 +185,6 @@ public class NetConfigController : ControllerBase /// /// 设置板卡MAC地址 /// - /// 板卡IP地址 - /// 板卡端口 /// 板卡MAC地址(格式:AA:BB:CC:DD:EE:FF) /// 操作结果 [HttpPost("SetBoardMAC")] @@ -234,20 +192,11 @@ public class NetConfigController : ControllerBase [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task SetBoardMAC(string boardIp, int boardPort, string boardMac) + public async Task SetBoardMAC(string boardMac) { - if (string.IsNullOrWhiteSpace(boardIp)) - return BadRequest("板卡IP地址不能为空"); - - if (boardPort <= 0 || boardPort > 65535) - return BadRequest("板卡端口号无效"); - if (string.IsNullOrWhiteSpace(boardMac)) return BadRequest("板卡MAC地址不能为空"); - if (!IPAddress.TryParse(boardIp, out _)) - return BadRequest("板卡IP地址格式不正确"); - // 解析MAC地址 if (!TryParseMacAddress(boardMac, out var macBytes)) return BadRequest("MAC地址格式不正确,请使用格式:AA:BB:CC:DD:EE:FF"); @@ -255,7 +204,7 @@ public class NetConfigController : ControllerBase try { // 创建网络配置客户端 - var netConfig = new NetConfig(boardIp, boardPort, 0); + var netConfig = new NetConfig(BOARD_IP, BOARD_PORT, 0); var result = await netConfig.SetBoardMAC(macBytes); if (!result.IsSuccessful) diff --git a/src/APIClient.ts b/src/APIClient.ts index 52339fe..d8f25c1 100644 --- a/src/APIClient.ts +++ b/src/APIClient.ts @@ -2691,16 +2691,11 @@ export class NetConfigClient { /** * 设置主机IP地址 - * @param boardId (optional) 板卡ID * @param hostIp (optional) 主机IP地址 * @return 操作结果 */ - setHostIP(boardId: string | undefined, hostIp: string | undefined): Promise { + setHostIP(hostIp: string | undefined): Promise { let url_ = this.baseUrl + "/api/NetConfig/SetHostIP?"; - if (boardId === null) - throw new Error("The parameter 'boardId' cannot be null."); - else if (boardId !== undefined) - url_ += "boardId=" + encodeURIComponent("" + boardId) + "&"; if (hostIp === null) throw new Error("The parameter 'hostIp' cannot be null."); else if (hostIp !== undefined) @@ -2737,13 +2732,6 @@ export class NetConfigClient { result400 = ProblemDetails.fromJS(resultData400); return throwException("A server side error occurred.", status, _responseText, _headers, result400); }); - } else if (status === 404) { - return response.text().then((_responseText) => { - let result404: any = null; - let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); - result404 = ProblemDetails.fromJS(resultData404); - return throwException("A server side error occurred.", status, _responseText, _headers, result404); - }); } else if (status === 500) { return response.text().then((_responseText) => { return throwException("A server side error occurred.", status, _responseText, _headers); @@ -2758,20 +2746,15 @@ export class NetConfigClient { /** * 设置板卡IP地址 - * @param boardId (optional) 板卡ID - * @param boardIp (optional) 板卡IP地址 + * @param newBoardIp (optional) 新的板卡IP地址 * @return 操作结果 */ - setBoardIP(boardId: string | undefined, boardIp: string | undefined): Promise { + setBoardIP(newBoardIp: string | undefined): Promise { let url_ = this.baseUrl + "/api/NetConfig/SetBoardIP?"; - if (boardId === null) - throw new Error("The parameter 'boardId' cannot be null."); - else if (boardId !== undefined) - url_ += "boardId=" + encodeURIComponent("" + boardId) + "&"; - if (boardIp === null) - throw new Error("The parameter 'boardIp' cannot be null."); - else if (boardIp !== undefined) - url_ += "boardIp=" + encodeURIComponent("" + boardIp) + "&"; + if (newBoardIp === null) + throw new Error("The parameter 'newBoardIp' cannot be null."); + else if (newBoardIp !== undefined) + url_ += "newBoardIp=" + encodeURIComponent("" + newBoardIp) + "&"; url_ = url_.replace(/[?&]$/, ""); let options_: RequestInit = { @@ -2804,13 +2787,6 @@ export class NetConfigClient { result400 = ProblemDetails.fromJS(resultData400); return throwException("A server side error occurred.", status, _responseText, _headers, result400); }); - } else if (status === 404) { - return response.text().then((_responseText) => { - let result404: any = null; - let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); - result404 = ProblemDetails.fromJS(resultData404); - return throwException("A server side error occurred.", status, _responseText, _headers, result404); - }); } else if (status === 500) { return response.text().then((_responseText) => { return throwException("A server side error occurred.", status, _responseText, _headers); @@ -2825,16 +2801,11 @@ export class NetConfigClient { /** * 设置主机MAC地址 - * @param boardId (optional) 板卡ID * @param hostMac (optional) 主机MAC地址(格式:AA:BB:CC:DD:EE:FF) * @return 操作结果 */ - setHostMAC(boardId: string | undefined, hostMac: string | undefined): Promise { + setHostMAC(hostMac: string | undefined): Promise { let url_ = this.baseUrl + "/api/NetConfig/SetHostMAC?"; - if (boardId === null) - throw new Error("The parameter 'boardId' cannot be null."); - else if (boardId !== undefined) - url_ += "boardId=" + encodeURIComponent("" + boardId) + "&"; if (hostMac === null) throw new Error("The parameter 'hostMac' cannot be null."); else if (hostMac !== undefined) @@ -2871,13 +2842,6 @@ export class NetConfigClient { result400 = ProblemDetails.fromJS(resultData400); return throwException("A server side error occurred.", status, _responseText, _headers, result400); }); - } else if (status === 404) { - return response.text().then((_responseText) => { - let result404: any = null; - let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); - result404 = ProblemDetails.fromJS(resultData404); - return throwException("A server side error occurred.", status, _responseText, _headers, result404); - }); } else if (status === 500) { return response.text().then((_responseText) => { return throwException("A server side error occurred.", status, _responseText, _headers); @@ -2892,15 +2856,10 @@ export class NetConfigClient { /** * 更新主机MAC地址 - * @param boardId (optional) 板卡ID * @return 操作结果 */ - updateHostMAC(boardId: string | undefined): Promise { - let url_ = this.baseUrl + "/api/NetConfig/UpdateHostMAC?"; - if (boardId === null) - throw new Error("The parameter 'boardId' cannot be null."); - else if (boardId !== undefined) - url_ += "boardId=" + encodeURIComponent("" + boardId) + "&"; + updateHostMAC(): Promise { + let url_ = this.baseUrl + "/api/NetConfig/UpdateHostMAC"; url_ = url_.replace(/[?&]$/, ""); let options_: RequestInit = { @@ -2933,13 +2892,6 @@ export class NetConfigClient { result400 = ProblemDetails.fromJS(resultData400); return throwException("A server side error occurred.", status, _responseText, _headers, result400); }); - } else if (status === 404) { - return response.text().then((_responseText) => { - let result404: any = null; - let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); - result404 = ProblemDetails.fromJS(resultData404); - return throwException("A server side error occurred.", status, _responseText, _headers, result404); - }); } else if (status === 500) { return response.text().then((_responseText) => { return throwException("A server side error occurred.", status, _responseText, _headers); @@ -2954,16 +2906,11 @@ export class NetConfigClient { /** * 设置板卡MAC地址 - * @param boardId (optional) 板卡ID * @param boardMac (optional) 板卡MAC地址(格式:AA:BB:CC:DD:EE:FF) * @return 操作结果 */ - setBoardMAC(boardId: string | undefined, boardMac: string | undefined): Promise { + setBoardMAC(boardMac: string | undefined): Promise { let url_ = this.baseUrl + "/api/NetConfig/SetBoardMAC?"; - if (boardId === null) - throw new Error("The parameter 'boardId' cannot be null."); - else if (boardId !== undefined) - url_ += "boardId=" + encodeURIComponent("" + boardId) + "&"; if (boardMac === null) throw new Error("The parameter 'boardMac' cannot be null."); else if (boardMac !== undefined) @@ -3000,13 +2947,6 @@ export class NetConfigClient { result400 = ProblemDetails.fromJS(resultData400); return throwException("A server side error occurred.", status, _responseText, _headers, result400); }); - } else if (status === 404) { - return response.text().then((_responseText) => { - let result404: any = null; - let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); - result404 = ProblemDetails.fromJS(resultData404); - return throwException("A server side error occurred.", status, _responseText, _headers, result404); - }); } else if (status === 500) { return response.text().then((_responseText) => { return throwException("A server side error occurred.", status, _responseText, _headers); @@ -3799,7 +3739,7 @@ export class UDPClient { } export class Exception implements IException { - message!: string; + declare message: string; innerException?: Exception | undefined; source?: string | undefined; stackTrace?: string | undefined;