1899 lines
80 KiB
TypeScript
1899 lines
80 KiB
TypeScript
//----------------------
|
||
// <auto-generated>
|
||
// Generated using the NSwag toolchain v14.3.0.0 (NJsonSchema v11.2.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
|
||
// </auto-generated>
|
||
//----------------------
|
||
|
||
/* tslint:disable */
|
||
/* eslint-disable */
|
||
// ReSharper disable InconsistentNaming
|
||
|
||
export class UDPClient {
|
||
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";
|
||
}
|
||
|
||
/**
|
||
* 页面
|
||
*/
|
||
index(): Promise<string> {
|
||
let url_ = this.baseUrl + "/api/UDP";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "GET",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processIndex(_response);
|
||
});
|
||
}
|
||
|
||
protected processIndex(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 !== 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);
|
||
}
|
||
|
||
/**
|
||
* 发送字符串
|
||
* @param address (optional) IPV4 或者 IPV6 地址
|
||
* @param port (optional) 设备端口号
|
||
* @param text (optional) 发送的文本
|
||
* @return 发送成功
|
||
*/
|
||
sendString(address: string | undefined, port: number | undefined, text: string | undefined): Promise<void> {
|
||
let url_ = this.baseUrl + "/api/UDP/SendString?";
|
||
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 (text === null)
|
||
throw new Error("The parameter 'text' cannot be null.");
|
||
else if (text !== undefined)
|
||
url_ += "text=" + encodeURIComponent("" + text) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSendString(_response);
|
||
});
|
||
}
|
||
|
||
protected processSendString(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("\u53d1\u9001\u5931\u8d25", 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);
|
||
}
|
||
|
||
/**
|
||
* 发送二进制数据
|
||
* @param address (optional) IPV4 或者 IPV6 地址
|
||
* @param port (optional) 设备端口号
|
||
* @param bytes (optional) 16进制文本
|
||
*/
|
||
sendBytes(address: string | undefined, port: number | undefined, bytes: string | undefined): Promise<void> {
|
||
let url_ = this.baseUrl + "/api/UDP/SendBytes?";
|
||
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 (bytes === null)
|
||
throw new Error("The parameter 'bytes' cannot be null.");
|
||
else if (bytes !== undefined)
|
||
url_ += "bytes=" + encodeURIComponent("" + bytes) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSendBytes(_response);
|
||
});
|
||
}
|
||
|
||
protected processSendBytes(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);
|
||
}
|
||
|
||
/**
|
||
* 发送地址包
|
||
* @param address (optional) IP地址
|
||
* @param port (optional) UDP 端口号
|
||
* @param opts 地址包选项
|
||
*/
|
||
sendAddrPackage(address: string | undefined, port: number | undefined, opts: SendAddrPackOptions): Promise<void> {
|
||
let url_ = this.baseUrl + "/api/UDP/SendAddrPackage?";
|
||
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(/[?&]$/, "");
|
||
|
||
const content_ = JSON.stringify(opts);
|
||
|
||
let options_: RequestInit = {
|
||
body: content_,
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSendAddrPackage(_response);
|
||
});
|
||
}
|
||
|
||
protected processSendAddrPackage(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);
|
||
}
|
||
|
||
/**
|
||
* 发送数据包
|
||
* @param address (optional) IP地址
|
||
* @param port (optional) UDP 端口号
|
||
* @param data (optional) 16进制数据
|
||
*/
|
||
sendDataPackage(address: string | undefined, port: number | undefined, data: string | undefined): Promise<void> {
|
||
let url_ = this.baseUrl + "/api/UDP/SendDataPackage?";
|
||
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 (data === null)
|
||
throw new Error("The parameter 'data' cannot be null.");
|
||
else if (data !== undefined)
|
||
url_ += "data=" + encodeURIComponent("" + data) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSendDataPackage(_response);
|
||
});
|
||
}
|
||
|
||
protected processSendDataPackage(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);
|
||
}
|
||
|
||
/**
|
||
* 获取指定IP地址接受的数据列表
|
||
* @param address (optional) IP地址
|
||
*/
|
||
getRecvDataArray(address: string | undefined): Promise<UDPData[]> {
|
||
let url_ = this.baseUrl + "/api/UDP/GetRecvDataArray?";
|
||
if (address === null)
|
||
throw new Error("The parameter 'address' cannot be null.");
|
||
else if (address !== undefined)
|
||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "GET",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processGetRecvDataArray(_response);
|
||
});
|
||
}
|
||
|
||
protected processGetRecvDataArray(response: Response): Promise<UDPData[]> {
|
||
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(UDPData.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<UDPData[]>(null as any);
|
||
}
|
||
}
|
||
|
||
export class JtagClient {
|
||
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";
|
||
}
|
||
|
||
/**
|
||
* 页面
|
||
*/
|
||
index(): Promise<string> {
|
||
let url_ = this.baseUrl + "/api/Jtag";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "GET",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processIndex(_response);
|
||
});
|
||
}
|
||
|
||
protected processIndex(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 !== 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);
|
||
}
|
||
|
||
/**
|
||
* 获取Jtag ID Code
|
||
* @param address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
*/
|
||
getDeviceIDCode(address: string | undefined, port: number | undefined): Promise<number> {
|
||
let url_ = this.baseUrl + "/api/Jtag/GetDeviceIDCode?";
|
||
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: "GET",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processGetDeviceIDCode(_response);
|
||
});
|
||
}
|
||
|
||
protected processGetDeviceIDCode(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 === 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);
|
||
}
|
||
|
||
/**
|
||
* 获取状态寄存器
|
||
* @param address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
*/
|
||
readStatusReg(address: string | undefined, port: number | undefined): Promise<void> {
|
||
let url_ = this.baseUrl + "/api/Jtag/ReadStatusReg?";
|
||
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: "GET",
|
||
headers: {
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processReadStatusReg(_response);
|
||
});
|
||
}
|
||
|
||
protected processReadStatusReg(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);
|
||
}
|
||
|
||
/**
|
||
* 上传比特流文件
|
||
* @param address (optional) 设备地址
|
||
* @param file (optional)
|
||
*/
|
||
uploadBitstream(address: string | undefined, file: FileParameter | null | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/Jtag/UploadBitstream?";
|
||
if (address === null)
|
||
throw new Error("The parameter 'address' cannot be null.");
|
||
else if (address !== undefined)
|
||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
const content_ = new FormData();
|
||
if (file !== null && file !== undefined)
|
||
content_.append("file", file.data, file.fileName ? file.fileName : "file");
|
||
|
||
let options_: RequestInit = {
|
||
body: content_,
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processUploadBitstream(_response);
|
||
});
|
||
}
|
||
|
||
protected processUploadBitstream(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 !== 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);
|
||
}
|
||
|
||
/**
|
||
* 通过Jtag下载比特流文件
|
||
* @param address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
*/
|
||
downloadBitstream(address: string | undefined, port: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
|
||
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.processDownloadBitstream(_response);
|
||
});
|
||
}
|
||
|
||
protected processDownloadBitstream(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);
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
boundaryScanAllPorts(address: string | undefined, port: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/Jtag/BoundaryScanAllPorts?";
|
||
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.processBoundaryScanAllPorts(_response);
|
||
});
|
||
}
|
||
|
||
protected processBoundaryScanAllPorts(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);
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
boundaryScanLogicalPorts(address: string | undefined, port: number | undefined): Promise<{ [key: string]: boolean; }> {
|
||
let url_ = this.baseUrl + "/api/Jtag/BoundaryScanLogicalPorts?";
|
||
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.processBoundaryScanLogicalPorts(_response);
|
||
});
|
||
}
|
||
|
||
protected processBoundaryScanLogicalPorts(response: Response): Promise<{ [key: string]: 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);
|
||
if (resultData200) {
|
||
result200 = {} as any;
|
||
for (let key in resultData200) {
|
||
if (resultData200.hasOwnProperty(key))
|
||
(<any>result200)![key] = resultData200[key] !== undefined ? resultData200[key] : <any>null;
|
||
}
|
||
}
|
||
else {
|
||
result200 = <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<{ [key: string]: boolean; }>(null as any);
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @param speed (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
setSpeed(address: string | undefined, port: number | undefined, speed: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/Jtag/SetSpeed?";
|
||
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 (speed === null)
|
||
throw new Error("The parameter 'speed' cannot be null.");
|
||
else if (speed !== undefined)
|
||
url_ += "speed=" + encodeURIComponent("" + speed) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSetSpeed(_response);
|
||
});
|
||
}
|
||
|
||
protected processSetSpeed(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 RemoteUpdateClient {
|
||
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 address (optional) 设备地址
|
||
* @param goldenBitream (optional)
|
||
* @param bitstream1 (optional)
|
||
* @param bitstream2 (optional)
|
||
* @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<boolean> {
|
||
let url_ = this.baseUrl + "/api/RemoteUpdate/UploadBitstream?";
|
||
if (address === null)
|
||
throw new Error("The parameter 'address' cannot be null.");
|
||
else if (address !== undefined)
|
||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
const content_ = new FormData();
|
||
if (goldenBitream !== null && goldenBitream !== undefined)
|
||
content_.append("goldenBitream", goldenBitream.data, goldenBitream.fileName ? goldenBitream.fileName : "goldenBitream");
|
||
if (bitstream1 !== null && bitstream1 !== undefined)
|
||
content_.append("bitstream1", bitstream1.data, bitstream1.fileName ? bitstream1.fileName : "bitstream1");
|
||
if (bitstream2 !== null && bitstream2 !== undefined)
|
||
content_.append("bitstream2", bitstream2.data, bitstream2.fileName ? bitstream2.fileName : "bitstream2");
|
||
if (bitstream3 !== null && bitstream3 !== undefined)
|
||
content_.append("bitstream3", bitstream3.data, bitstream3.fileName ? bitstream3.fileName : "bitstream3");
|
||
|
||
let options_: RequestInit = {
|
||
body: content_,
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processUploadBitstreams(_response);
|
||
});
|
||
}
|
||
|
||
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) => {
|
||
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 !== 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 address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
* @param bitstreamNum (optional) 比特流位号
|
||
*/
|
||
updateBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/RemoteUpdate/DownloadBitstream?";
|
||
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 (bitstreamNum === null)
|
||
throw new Error("The parameter 'bitstreamNum' cannot be null.");
|
||
else if (bitstreamNum !== undefined)
|
||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processUpdateBitstream(_response);
|
||
});
|
||
}
|
||
|
||
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) => {
|
||
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<boolean>(null as any);
|
||
}
|
||
|
||
/**
|
||
* 下载多个比特流文件
|
||
* @param address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
* @param bitstreamNum (optional) 比特流编号
|
||
* @return 总共上传比特流的数量
|
||
*/
|
||
downloadMultiBitstreams(address: string | undefined, port: number | undefined, bitstreamNum: number | null | undefined): Promise<number> {
|
||
let url_ = this.baseUrl + "/api/RemoteUpdate/DownloadMultiBitstreams?";
|
||
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 (bitstreamNum !== undefined && bitstreamNum !== null)
|
||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processDownloadMultiBitstreams(_response);
|
||
});
|
||
}
|
||
|
||
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) => {
|
||
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);
|
||
}
|
||
|
||
/**
|
||
* 热复位比特流文件
|
||
* @param address (optional) 设备地址
|
||
* @param port (optional) 设备端口
|
||
* @param bitstreamNum (optional) 比特流编号
|
||
* @return 操作结果
|
||
*/
|
||
hotResetBitstream(address: string | undefined, port: number | undefined, bitstreamNum: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/RemoteUpdate/HotResetBitstream?";
|
||
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 (bitstreamNum === null)
|
||
throw new Error("The parameter 'bitstreamNum' cannot be null.");
|
||
else if (bitstreamNum !== undefined)
|
||
url_ += "bitstreamNum=" + encodeURIComponent("" + bitstreamNum) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processHotResetBitstream(_response);
|
||
});
|
||
}
|
||
|
||
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) => {
|
||
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<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/RemoteUpdate/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);
|
||
}
|
||
}
|
||
|
||
export class DDSClient {
|
||
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";
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @param channelNum (optional) [TODO:parameter]
|
||
* @param waveNum (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
setWaveNum(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/DDS/SetWaveNum?";
|
||
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 (channelNum === null)
|
||
throw new Error("The parameter 'channelNum' cannot be null.");
|
||
else if (channelNum !== undefined)
|
||
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||
if (waveNum === null)
|
||
throw new Error("The parameter 'waveNum' cannot be null.");
|
||
else if (waveNum !== undefined)
|
||
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSetWaveNum(_response);
|
||
});
|
||
}
|
||
|
||
protected processSetWaveNum(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 = 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<boolean>(null as any);
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @param channelNum (optional) [TODO:parameter]
|
||
* @param waveNum (optional) [TODO:parameter]
|
||
* @param step (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
setFreq(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined, step: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/DDS/SetFreq?";
|
||
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 (channelNum === null)
|
||
throw new Error("The parameter 'channelNum' cannot be null.");
|
||
else if (channelNum !== undefined)
|
||
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||
if (waveNum === null)
|
||
throw new Error("The parameter 'waveNum' cannot be null.");
|
||
else if (waveNum !== undefined)
|
||
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||
if (step === null)
|
||
throw new Error("The parameter 'step' cannot be null.");
|
||
else if (step !== undefined)
|
||
url_ += "step=" + encodeURIComponent("" + step) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSetFreq(_response);
|
||
});
|
||
}
|
||
|
||
protected processSetFreq(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 = 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<boolean>(null as any);
|
||
}
|
||
|
||
/**
|
||
* [TODO:description]
|
||
* @param address (optional) [TODO:parameter]
|
||
* @param port (optional) [TODO:parameter]
|
||
* @param channelNum (optional) [TODO:parameter]
|
||
* @param waveNum (optional) [TODO:parameter]
|
||
* @param phase (optional) [TODO:parameter]
|
||
* @return [TODO:return]
|
||
*/
|
||
setPhase(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined, phase: number | undefined): Promise<boolean> {
|
||
let url_ = this.baseUrl + "/api/DDS/SetPhase?";
|
||
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 (channelNum === null)
|
||
throw new Error("The parameter 'channelNum' cannot be null.");
|
||
else if (channelNum !== undefined)
|
||
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||
if (waveNum === null)
|
||
throw new Error("The parameter 'waveNum' cannot be null.");
|
||
else if (waveNum !== undefined)
|
||
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||
if (phase === null)
|
||
throw new Error("The parameter 'phase' cannot be null.");
|
||
else if (phase !== undefined)
|
||
url_ += "phase=" + encodeURIComponent("" + phase) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/json"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSetPhase(_response);
|
||
});
|
||
}
|
||
|
||
protected processSetPhase(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 = 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<boolean>(null as any);
|
||
}
|
||
}
|
||
|
||
export class BsdlParserClient {
|
||
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";
|
||
}
|
||
|
||
getBoundaryLogicalPorts(): Promise<FileResponse> {
|
||
let url_ = this.baseUrl + "/api/BsdlParser/GetBoundaryLogicalPorts";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "GET",
|
||
headers: {
|
||
"Accept": "application/octet-stream"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processGetBoundaryLogicalPorts(_response);
|
||
});
|
||
}
|
||
|
||
protected processGetBoundaryLogicalPorts(response: Response): Promise<FileResponse> {
|
||
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 || status === 206) {
|
||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||
if (fileName) {
|
||
fileName = decodeURIComponent(fileName);
|
||
} else {
|
||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||
}
|
||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _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<FileResponse>(null as any);
|
||
}
|
||
}
|
||
|
||
export class DataClient {
|
||
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";
|
||
}
|
||
|
||
/**
|
||
* 创建数据库表
|
||
* @return 插入的记录数
|
||
*/
|
||
createTables(): Promise<FileResponse> {
|
||
let url_ = this.baseUrl + "/api/Data/CreateTable";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/octet-stream"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processCreateTables(_response);
|
||
});
|
||
}
|
||
|
||
protected processCreateTables(response: Response): Promise<FileResponse> {
|
||
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 || status === 206) {
|
||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||
if (fileName) {
|
||
fileName = decodeURIComponent(fileName);
|
||
} else {
|
||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||
}
|
||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _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<FileResponse>(null as any);
|
||
}
|
||
|
||
/**
|
||
* 删除数据库表
|
||
* @return 插入的记录数
|
||
*/
|
||
dropTables(): Promise<FileResponse> {
|
||
let url_ = this.baseUrl + "/api/Data/DropTables";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "DELETE",
|
||
headers: {
|
||
"Accept": "application/octet-stream"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processDropTables(_response);
|
||
});
|
||
}
|
||
|
||
protected processDropTables(response: Response): Promise<FileResponse> {
|
||
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 || status === 206) {
|
||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||
if (fileName) {
|
||
fileName = decodeURIComponent(fileName);
|
||
} else {
|
||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||
}
|
||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _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<FileResponse>(null as any);
|
||
}
|
||
|
||
/**
|
||
* 获取所有用户
|
||
* @return 用户列表
|
||
*/
|
||
allUsers(): Promise<FileResponse> {
|
||
let url_ = this.baseUrl + "/api/Data/AllUsers";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "GET",
|
||
headers: {
|
||
"Accept": "application/octet-stream"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processAllUsers(_response);
|
||
});
|
||
}
|
||
|
||
protected processAllUsers(response: Response): Promise<FileResponse> {
|
||
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 || status === 206) {
|
||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||
if (fileName) {
|
||
fileName = decodeURIComponent(fileName);
|
||
} else {
|
||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||
}
|
||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _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<FileResponse>(null as any);
|
||
}
|
||
|
||
/**
|
||
* 注册新用户
|
||
* @param name (optional) 用户名
|
||
* @return 操作结果
|
||
*/
|
||
signUpUser(name: string | undefined): Promise<FileResponse> {
|
||
let url_ = this.baseUrl + "/api/Data/SignUpUser?";
|
||
if (name === null)
|
||
throw new Error("The parameter 'name' cannot be null.");
|
||
else if (name !== undefined)
|
||
url_ += "name=" + encodeURIComponent("" + name) + "&";
|
||
url_ = url_.replace(/[?&]$/, "");
|
||
|
||
let options_: RequestInit = {
|
||
method: "POST",
|
||
headers: {
|
||
"Accept": "application/octet-stream"
|
||
}
|
||
};
|
||
|
||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||
return this.processSignUpUser(_response);
|
||
});
|
||
}
|
||
|
||
protected processSignUpUser(response: Response): Promise<FileResponse> {
|
||
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 || status === 206) {
|
||
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
|
||
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
|
||
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
|
||
if (fileName) {
|
||
fileName = decodeURIComponent(fileName);
|
||
} else {
|
||
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
|
||
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
|
||
}
|
||
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _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<FileResponse>(null as any);
|
||
}
|
||
}
|
||
|
||
/** Package options which to send address to read or write */
|
||
export class SendAddrPackOptions implements ISendAddrPackOptions {
|
||
/** 突发类型 */
|
||
burstType?: BurstType;
|
||
/** 任务ID */
|
||
commandID?: number;
|
||
/** 标识写入还是读取 */
|
||
isWrite?: boolean;
|
||
/** 突发长度:0是32bits,255是32bits x 256 */
|
||
burstLength?: number;
|
||
/** 目标地址 */
|
||
address?: number;
|
||
|
||
constructor(data?: ISendAddrPackOptions) {
|
||
if (data) {
|
||
for (var property in data) {
|
||
if (data.hasOwnProperty(property))
|
||
(<any>this)[property] = (<any>data)[property];
|
||
}
|
||
}
|
||
}
|
||
|
||
init(_data?: any) {
|
||
if (_data) {
|
||
this.burstType = _data["burstType"];
|
||
this.commandID = _data["commandID"];
|
||
this.isWrite = _data["isWrite"];
|
||
this.burstLength = _data["burstLength"];
|
||
this.address = _data["address"];
|
||
}
|
||
}
|
||
|
||
static fromJS(data: any): SendAddrPackOptions {
|
||
data = typeof data === 'object' ? data : {};
|
||
let result = new SendAddrPackOptions();
|
||
result.init(data);
|
||
return result;
|
||
}
|
||
|
||
toJSON(data?: any) {
|
||
data = typeof data === 'object' ? data : {};
|
||
data["burstType"] = this.burstType;
|
||
data["commandID"] = this.commandID;
|
||
data["isWrite"] = this.isWrite;
|
||
data["burstLength"] = this.burstLength;
|
||
data["address"] = this.address;
|
||
return data;
|
||
}
|
||
}
|
||
|
||
/** Package options which to send address to read or write */
|
||
export interface ISendAddrPackOptions {
|
||
/** 突发类型 */
|
||
burstType?: BurstType;
|
||
/** 任务ID */
|
||
commandID?: number;
|
||
/** 标识写入还是读取 */
|
||
isWrite?: boolean;
|
||
/** 突发长度:0是32bits,255是32bits x 256 */
|
||
burstLength?: number;
|
||
/** 目标地址 */
|
||
address?: number;
|
||
}
|
||
|
||
/** Package Burst Type */
|
||
export enum BurstType {
|
||
FixedBurst = 0,
|
||
ExtendBurst = 1,
|
||
}
|
||
|
||
/** UDP接受数据包格式 */
|
||
export class UDPData implements IUDPData {
|
||
/** 接受到的时间 */
|
||
dateTime?: Date;
|
||
/** 发送来源的IP地址 */
|
||
address?: string;
|
||
/** 发送来源的端口号 */
|
||
port?: number;
|
||
/** 接受到的数据 */
|
||
data?: string;
|
||
/** 是否被读取过 */
|
||
hasRead?: boolean;
|
||
|
||
constructor(data?: IUDPData) {
|
||
if (data) {
|
||
for (var property in data) {
|
||
if (data.hasOwnProperty(property))
|
||
(<any>this)[property] = (<any>data)[property];
|
||
}
|
||
}
|
||
}
|
||
|
||
init(_data?: any) {
|
||
if (_data) {
|
||
this.dateTime = _data["dateTime"] ? new Date(_data["dateTime"].toString()) : <any>undefined;
|
||
this.address = _data["address"];
|
||
this.port = _data["port"];
|
||
this.data = _data["data"];
|
||
this.hasRead = _data["hasRead"];
|
||
}
|
||
}
|
||
|
||
static fromJS(data: any): UDPData {
|
||
data = typeof data === 'object' ? data : {};
|
||
let result = new UDPData();
|
||
result.init(data);
|
||
return result;
|
||
}
|
||
|
||
toJSON(data?: any) {
|
||
data = typeof data === 'object' ? data : {};
|
||
data["dateTime"] = this.dateTime ? this.dateTime.toISOString() : <any>undefined;
|
||
data["address"] = this.address;
|
||
data["port"] = this.port;
|
||
data["data"] = this.data;
|
||
data["hasRead"] = this.hasRead;
|
||
return data;
|
||
}
|
||
}
|
||
|
||
/** UDP接受数据包格式 */
|
||
export interface IUDPData {
|
||
/** 接受到的时间 */
|
||
dateTime?: Date;
|
||
/** 发送来源的IP地址 */
|
||
address?: string;
|
||
/** 发送来源的端口号 */
|
||
port?: number;
|
||
/** 接受到的数据 */
|
||
data?: string;
|
||
/** 是否被读取过 */
|
||
hasRead?: boolean;
|
||
}
|
||
|
||
export class Exception implements IException {
|
||
message?: string;
|
||
innerException?: Exception | undefined;
|
||
source?: string | undefined;
|
||
stackTrace?: string | undefined;
|
||
|
||
constructor(data?: IException) {
|
||
if (data) {
|
||
for (var property in data) {
|
||
if (data.hasOwnProperty(property))
|
||
(<any>this)[property] = (<any>data)[property];
|
||
}
|
||
}
|
||
}
|
||
|
||
init(_data?: any) {
|
||
if (_data) {
|
||
this.message = _data["Message"];
|
||
this.innerException = _data["InnerException"] ? Exception.fromJS(_data["InnerException"]) : <any>undefined;
|
||
this.source = _data["Source"];
|
||
this.stackTrace = _data["StackTrace"];
|
||
}
|
||
}
|
||
|
||
static fromJS(data: any): Exception {
|
||
data = typeof data === 'object' ? data : {};
|
||
let result = new Exception();
|
||
result.init(data);
|
||
return result;
|
||
}
|
||
|
||
toJSON(data?: any) {
|
||
data = typeof data === 'object' ? data : {};
|
||
data["Message"] = this.message;
|
||
data["InnerException"] = this.innerException ? this.innerException.toJSON() : <any>undefined;
|
||
data["Source"] = this.source;
|
||
data["StackTrace"] = this.stackTrace;
|
||
return data;
|
||
}
|
||
}
|
||
|
||
export interface IException {
|
||
message?: string;
|
||
innerException?: Exception | undefined;
|
||
source?: string | undefined;
|
||
stackTrace?: string | undefined;
|
||
}
|
||
|
||
export class SystemException extends Exception implements ISystemException {
|
||
|
||
constructor(data?: ISystemException) {
|
||
super(data);
|
||
}
|
||
|
||
init(_data?: any) {
|
||
super.init(_data);
|
||
}
|
||
|
||
static fromJS(data: any): SystemException {
|
||
data = typeof data === 'object' ? data : {};
|
||
let result = new SystemException();
|
||
result.init(data);
|
||
return result;
|
||
}
|
||
|
||
toJSON(data?: any) {
|
||
data = typeof data === 'object' ? data : {};
|
||
super.toJSON(data);
|
||
return data;
|
||
}
|
||
}
|
||
|
||
export interface ISystemException extends IException {
|
||
}
|
||
|
||
export class ArgumentException extends SystemException implements IArgumentException {
|
||
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 {
|
||
data: any;
|
||
fileName: string;
|
||
}
|
||
|
||
export interface FileResponse {
|
||
data: Blob;
|
||
status: number;
|
||
fileName?: string;
|
||
headers?: { [name: string]: any };
|
||
}
|
||
|
||
export class ApiException extends Error {
|
||
message: string;
|
||
status: number;
|
||
response: string;
|
||
headers: { [key: string]: any; };
|
||
result: any;
|
||
|
||
constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
|
||
super();
|
||
|
||
this.message = message;
|
||
this.status = status;
|
||
this.response = response;
|
||
this.headers = headers;
|
||
this.result = result;
|
||
}
|
||
|
||
protected isApiException = true;
|
||
|
||
static isApiException(obj: any): obj is ApiException {
|
||
return obj.isApiException === true;
|
||
}
|
||
}
|
||
|
||
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
|
||
if (result !== null && result !== undefined)
|
||
throw result;
|
||
else
|
||
throw new ApiException(message, status, response, headers, null);
|
||
}
|