feat: add remote update function

This commit is contained in:
2025-05-14 21:22:20 +08:00
parent 48ae3b5975
commit 00ce79fa7b
6 changed files with 520 additions and 283 deletions

View File

@@ -8,47 +8,6 @@
/* eslint-disable */
// ReSharper disable InconsistentNaming
export class Client {
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";
}
get(): Promise<void> {
let url_ = this.baseUrl + "/";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGet(_response);
});
}
protected processGet(response: Response): Promise<void> {
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) => {
return;
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
}
}
export class UDPClient {
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
private baseUrl: string;
@@ -408,63 +367,6 @@ export class JtagClient {
return Promise.resolve<string>(null as any);
}
/**
* 执行一个Jtag命令
* @param address (optional) 设备地址
* @param port (optional) 设备端口
* @param hexDevAddr (optional) 16进制设备目的地址(Jtag)
* @param hexCmd (optional) 16进制命令
*/
runCommand(address: string | undefined, port: number | undefined, hexDevAddr: string | undefined, hexCmd: string | undefined): Promise<void> {
let url_ = this.baseUrl + "/api/Jtag/RunCommand?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
else if (address !== undefined)
url_ += "address=" + encodeURIComponent("" + address) + "&";
if (port === null)
throw new Error("The parameter 'port' cannot be null.");
else if (port !== undefined)
url_ += "port=" + encodeURIComponent("" + port) + "&";
if (hexDevAddr === null)
throw new Error("The parameter 'hexDevAddr' cannot be null.");
else if (hexDevAddr !== undefined)
url_ += "hexDevAddr=" + encodeURIComponent("" + hexDevAddr) + "&";
if (hexCmd === null)
throw new Error("The parameter 'hexCmd' cannot be null.");
else if (hexCmd !== undefined)
url_ += "hexCmd=" + encodeURIComponent("" + hexCmd) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processRunCommand(_response);
});
}
protected processRunCommand(response: Response): Promise<void> {
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) => {
return;
});
} 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<void>(null as any);
}
/**
* 获取Jtag ID Code
* @param address (optional) 设备地址
@@ -686,6 +588,75 @@ export class JtagClient {
}
return Promise.resolve<boolean>(null as any);
}
/**
* [TODO:description]
* @param address (optional) [TODO:parameter]
* @param port (optional) [TODO:parameter]
* @param portNum (optional) [TODO:parameter]
* @return [TODO:return]
*/
boundaryScan(address: string | undefined, port: number | undefined, portNum: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/BoundaryScan?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
else if (address !== undefined)
url_ += "address=" + encodeURIComponent("" + address) + "&";
if (port === null)
throw new Error("The parameter 'port' cannot be null.");
else if (port !== undefined)
url_ += "port=" + encodeURIComponent("" + port) + "&";
if (portNum === null)
throw new Error("The parameter 'portNum' cannot be null.");
else if (portNum !== undefined)
url_ += "portNum=" + encodeURIComponent("" + portNum) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processBoundaryScan(_response);
});
}
protected processBoundaryScan(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 = resultData400 !== undefined ? resultData400 : <any>null;
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
}
}
export class RemoteUpdaterClient {
@@ -707,7 +678,7 @@ export class RemoteUpdaterClient {
* @param bitstream3 (optional)
* @return 上传结果
*/
uploadBitstreams(address: string | undefined, goldenBitream: FileParameter | null | undefined, bitstream1: FileParameter | null | undefined, bitstream2: FileParameter | null | undefined, bitstream3: FileParameter | null | undefined): Promise<void> {
uploadBitstreams(address: string | undefined, goldenBitream: FileParameter | null | undefined, bitstream1: FileParameter | null | undefined, bitstream2: FileParameter | null | undefined, bitstream3: FileParameter | null | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/RemoteUpdater/UploadBitstream?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -729,6 +700,7 @@ export class RemoteUpdaterClient {
body: content_,
method: "POST",
headers: {
"Accept": "application/json"
}
};
@@ -737,18 +709,22 @@ export class RemoteUpdaterClient {
});
}
protected processUploadBitstreams(response: Response): Promise<void> {
protected processUploadBitstreams(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) => {
return;
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);
result400 = ArgumentException.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status !== 200 && status !== 204) {
@@ -756,7 +732,7 @@ export class RemoteUpdaterClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
return Promise.resolve<boolean>(null as any);
}
/**
@@ -765,7 +741,7 @@ export class RemoteUpdaterClient {
* @param port (optional) 设备端口
* @param bitstreamNum (optional) 比特流位号
*/
updateBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<void> {
updateBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/RemoteUpdater/DownloadBitstream?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -784,6 +760,7 @@ export class RemoteUpdaterClient {
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
@@ -792,30 +769,37 @@ export class RemoteUpdaterClient {
});
}
protected processUpdateBitstream(response: Response): Promise<void> {
protected processUpdateBitstream(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) => {
return;
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);
result400 = ArgumentException.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);
let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
return Promise.resolve<boolean>(null as any);
}
/**
@@ -825,7 +809,7 @@ export class RemoteUpdaterClient {
* @param bitstreamNum (optional) 比特流编号
* @return 总共上传比特流的数量
*/
downloadMultiBitstreams(address: string | undefined, port: number | undefined, bitstreamNum: number | null | undefined): Promise<void> {
downloadMultiBitstreams(address: string | undefined, port: number | undefined, bitstreamNum: number | null | undefined): Promise<number> {
let url_ = this.baseUrl + "/api/RemoteUpdater/DownloadMultiBitstreams?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -842,6 +826,7 @@ export class RemoteUpdaterClient {
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
@@ -850,30 +835,37 @@ export class RemoteUpdaterClient {
});
}
protected processDownloadMultiBitstreams(response: Response): Promise<void> {
protected processDownloadMultiBitstreams(response: Response): Promise<number> {
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) => {
return;
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);
result400 = ArgumentException.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);
let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
return Promise.resolve<number>(null as any);
}
/**
@@ -883,7 +875,7 @@ export class RemoteUpdaterClient {
* @param bitstreamNum (optional) 比特流编号
* @return 操作结果
*/
hotResetBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<void> {
hotResetBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/RemoteUpdater/HotResetBitstream?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -902,6 +894,7 @@ export class RemoteUpdaterClient {
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
@@ -910,30 +903,100 @@ export class RemoteUpdaterClient {
});
}
protected processHotResetBitstream(response: Response): Promise<void> {
protected processHotResetBitstream(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) => {
return;
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);
result400 = ArgumentException.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);
let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
return Promise.resolve<boolean>(null as any);
}
/**
* [TODO:description]
* @param address (optional) [TODO:parameter]
* @param port (optional) [TODO:parameter]
* @return [TODO:return]
*/
getFirmwareVersion(address: string | undefined, port: number | undefined): Promise<number> {
let url_ = this.baseUrl + "/api/RemoteUpdater/GetFirmwareVersion?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
else if (address !== undefined)
url_ += "address=" + encodeURIComponent("" + address) + "&";
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 = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetFirmwareVersion(_response);
});
}
protected processGetFirmwareVersion(response: Response): Promise<number> {
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 = ArgumentException.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<number>(null as any);
}
}
@@ -1303,84 +1366,68 @@ export interface IException {
stackTrace?: string | undefined;
}
export class ProblemDetails implements IProblemDetails {
type?: string | undefined;
title?: string | undefined;
status?: number | undefined;
detail?: string | undefined;
instance?: string | undefined;
extensions?: { [key: string]: any; };
export class SystemException extends Exception implements ISystemException {
[key: string]: any;
constructor(data?: IProblemDetails) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
constructor(data?: ISystemException) {
super(data);
}
init(_data?: any) {
if (_data) {
for (var property in _data) {
if (_data.hasOwnProperty(property))
this[property] = _data[property];
}
this.type = _data["type"];
this.title = _data["title"];
this.status = _data["status"];
this.detail = _data["detail"];
this.instance = _data["instance"];
if (_data["extensions"]) {
this.extensions = {} as any;
for (let key in _data["extensions"]) {
if (_data["extensions"].hasOwnProperty(key))
(<any>this.extensions)![key] = _data["extensions"][key];
}
}
}
super.init(_data);
}
static fromJS(data: any): ProblemDetails {
static fromJS(data: any): SystemException {
data = typeof data === 'object' ? data : {};
let result = new ProblemDetails();
let result = new SystemException();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
for (var property in this) {
if (this.hasOwnProperty(property))
data[property] = this[property];
}
data["type"] = this.type;
data["title"] = this.title;
data["status"] = this.status;
data["detail"] = this.detail;
data["instance"] = this.instance;
if (this.extensions) {
data["extensions"] = {};
for (let key in this.extensions) {
if (this.extensions.hasOwnProperty(key))
(<any>data["extensions"])[key] = (<any>this.extensions)[key];
}
}
super.toJSON(data);
return data;
}
}
export interface IProblemDetails {
type?: string | undefined;
title?: string | undefined;
status?: number | undefined;
detail?: string | undefined;
instance?: string | undefined;
extensions?: { [key: string]: any; };
export interface ISystemException extends IException {
}
[key: string]: any;
export class ArgumentException extends SystemException implements IArgumentException {
message?: string;
paramName?: string | undefined;
constructor(data?: IArgumentException) {
super(data);
}
init(_data?: any) {
super.init(_data);
if (_data) {
this.message = _data["Message"];
this.paramName = _data["ParamName"];
}
}
static fromJS(data: any): ArgumentException {
data = typeof data === 'object' ? data : {};
let result = new ArgumentException();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["Message"] = this.message;
data["ParamName"] = this.paramName;
super.toJSON(data);
return data;
}
}
export interface IArgumentException extends ISystemException {
message?: string;
paramName?: string | undefined;
}
export interface FileParameter {