skyeye-sdk-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmjgnore +2 -0
- package/dist/GrpcUtil.d.ts +9 -0
- package/dist/GrpcUtil.js +55 -0
- package/dist/JsonRequest.d.ts +10 -0
- package/dist/JsonRequest.js +29 -0
- package/dist/JsonResponse.d.ts +12 -0
- package/dist/JsonResponse.js +36 -0
- package/dist/RequestFactory.d.ts +35 -0
- package/dist/RequestFactory.js +257 -0
- package/dist/SkyEyeClient.d.ts +70 -0
- package/dist/SkyEyeClient.js +831 -0
- package/dist/SkyEyeClientFactory.d.ts +10 -0
- package/dist/SkyEyeClientFactory.js +53 -0
- package/dist/exception/SkyEyeSDKException.d.ts +3 -0
- package/dist/exception/SkyEyeSDKException.js +13 -0
- package/dist/models/Board.d.ts +9 -0
- package/dist/models/Board.js +15 -0
- package/dist/models/Cpu.d.ts +14 -0
- package/dist/models/Cpu.js +47 -0
- package/dist/models/CpuInterface.d.ts +13 -0
- package/dist/models/CpuInterface.js +2 -0
- package/dist/models/Device.d.ts +38 -0
- package/dist/models/Device.js +26 -0
- package/dist/models/DeviceInterface.d.ts +12 -0
- package/dist/models/DeviceInterface.js +2 -0
- package/dist/models/DeviceState.d.ts +4 -0
- package/dist/models/DeviceState.js +8 -0
- package/dist/models/FaultInjectItem.d.ts +11 -0
- package/dist/models/FaultInjectItem.js +16 -0
- package/dist/models/FaultInjectItemInterface.d.ts +9 -0
- package/dist/models/FaultInjectItemInterface.js +2 -0
- package/dist/models/FaultInjectType.d.ts +11 -0
- package/dist/models/FaultInjectType.js +25 -0
- package/dist/models/GlobalVarType.d.ts +5 -0
- package/dist/models/GlobalVarType.js +9 -0
- package/dist/models/InstructionItem.d.ts +5 -0
- package/dist/models/InstructionItem.js +6 -0
- package/dist/models/Node.d.ts +4 -0
- package/dist/models/Node.js +2 -0
- package/dist/models/Register.d.ts +38 -0
- package/dist/models/Register.js +32 -0
- package/dist/models/RegisterInterface.d.ts +10 -0
- package/dist/models/RegisterInterface.js +2 -0
- package/dist/requests/BaseRequest.d.ts +13 -0
- package/dist/requests/BaseRequest.js +18 -0
- package/dist/response/BaseResponse.d.ts +5 -0
- package/dist/response/BaseResponse.js +7 -0
- package/dist/response/GetAllDeviceInfoResponse.d.ts +5 -0
- package/dist/response/GetAllDeviceInfoResponse.js +11 -0
- package/dist/response/GetCpuListResponse.d.ts +8 -0
- package/dist/response/GetCpuListResponse.js +18 -0
- package/dist/response/GetCpuRegisterInfoResponse.d.ts +6 -0
- package/dist/response/GetCpuRegisterInfoResponse.js +11 -0
- package/dist/response/GetCurrentPCResponse.d.ts +4 -0
- package/dist/response/GetCurrentPCResponse.js +7 -0
- package/dist/response/GetDeviceListResponse.d.ts +6 -0
- package/dist/response/GetDeviceListResponse.js +11 -0
- package/dist/response/GetDeviceTreeResponse.d.ts +5 -0
- package/dist/response/GetDeviceTreeResponse.js +11 -0
- package/dist/response/GetDisassembleInfoResponse.d.ts +5 -0
- package/dist/response/GetDisassembleInfoResponse.js +7 -0
- package/dist/response/GetFaultInjectListResponse.d.ts +8 -0
- package/dist/response/GetFaultInjectListResponse.js +18 -0
- package/dist/response/GetRamAddrInfoResponse.d.ts +5 -0
- package/dist/response/GetRamAddrInfoResponse.js +7 -0
- package/dist/response/GetRunningStateResponse.d.ts +14 -0
- package/dist/response/GetRunningStateResponse.js +25 -0
- package/dist/utils/ParseBoardUtils.d.ts +6 -0
- package/dist/utils/ParseBoardUtils.js +108 -0
- package/index.js +9 -0
- package/package.json +35 -0
- package/src/GrpcUtil.js +55 -0
- package/src/GrpcUtil.ts +76 -0
- package/src/JsonRequest.js +29 -0
- package/src/JsonRequest.ts +36 -0
- package/src/JsonResponse.js +36 -0
- package/src/JsonResponse.ts +46 -0
- package/src/RequestFactory.js +257 -0
- package/src/RequestFactory.ts +324 -0
- package/src/SkyEyeClient.js +831 -0
- package/src/SkyEyeClient.ts +772 -0
- package/src/SkyEyeClientFactory.js +53 -0
- package/src/SkyEyeClientFactory.ts +46 -0
- package/src/exception/SkyEyeSDKException.js +13 -0
- package/src/exception/SkyEyeSDKException.ts +10 -0
- package/src/models/Board.js +15 -0
- package/src/models/Board.ts +18 -0
- package/src/models/Cpu.js +47 -0
- package/src/models/Cpu.ts +56 -0
- package/src/models/CpuInterface.js +2 -0
- package/src/models/CpuInterface.ts +15 -0
- package/src/models/Device.js +26 -0
- package/src/models/Device.ts +70 -0
- package/src/models/DeviceInterface.js +2 -0
- package/src/models/DeviceInterface.ts +14 -0
- package/src/models/DeviceState.js +8 -0
- package/src/models/DeviceState.ts +4 -0
- package/src/models/FaultInjectItem.js +16 -0
- package/src/models/FaultInjectItem.ts +33 -0
- package/src/models/FaultInjectItemInterface.js +2 -0
- package/src/models/FaultInjectItemInterface.ts +10 -0
- package/src/models/FaultInjectType.js +25 -0
- package/src/models/FaultInjectType.ts +22 -0
- package/src/models/GlobalVarType.js +9 -0
- package/src/models/GlobalVarType.ts +5 -0
- package/src/models/InstructionItem.js +6 -0
- package/src/models/InstructionItem.ts +6 -0
- package/src/models/Node.js +2 -0
- package/src/models/Node.ts +4 -0
- package/src/models/Register.js +32 -0
- package/src/models/Register.ts +73 -0
- package/src/models/RegisterInterface.js +2 -0
- package/src/models/RegisterInterface.ts +14 -0
- package/src/proto/skyeye_rpc.proto +11 -0
- package/src/proto/skyeye_rpc_grpc_pb.d.ts +40 -0
- package/src/proto/skyeye_rpc_grpc_pb.js +44 -0
- package/src/proto/skyeye_rpc_pb.d.ts +47 -0
- package/src/proto/skyeye_rpc_pb.js +322 -0
- package/src/requests/BaseRequest.js +18 -0
- package/src/requests/BaseRequest.ts +24 -0
- package/src/requests/GetRunningStatusRequest.js +10 -0
- package/src/response/BaseResponse.js +7 -0
- package/src/response/BaseResponse.ts +8 -0
- package/src/response/GetAllDeviceInfoResponse.js +11 -0
- package/src/response/GetAllDeviceInfoResponse.ts +6 -0
- package/src/response/GetCpuListResponse.js +18 -0
- package/src/response/GetCpuListResponse.ts +20 -0
- package/src/response/GetCpuRegisterInfoResponse.js +11 -0
- package/src/response/GetCpuRegisterInfoResponse.ts +10 -0
- package/src/response/GetCurrentPCResponse.js +7 -0
- package/src/response/GetCurrentPCResponse.ts +6 -0
- package/src/response/GetDeviceListResponse.js +11 -0
- package/src/response/GetDeviceListResponse.ts +11 -0
- package/src/response/GetDeviceTreeResponse.js +11 -0
- package/src/response/GetDeviceTreeResponse.ts +6 -0
- package/src/response/GetDisassembleInfoResponse.js +7 -0
- package/src/response/GetDisassembleInfoResponse.ts +6 -0
- package/src/response/GetFaultInjectListResponse.js +18 -0
- package/src/response/GetFaultInjectListResponse.ts +20 -0
- package/src/response/GetRamAddrInfoResponse.js +7 -0
- package/src/response/GetRamAddrInfoResponse.ts +6 -0
- package/src/response/GetRunningStateResponse.js +25 -0
- package/src/response/GetRunningStateResponse.ts +25 -0
- package/src/test.js +43 -0
- package/src/utils/ParseBoardUtils.js +108 -0
- package/src/utils/ParseBoardUtils.ts +107 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
import * as grpc from '@grpc/grpc-js';
|
|
2
|
+
import { JSONRequest, JSONResponse } from './proto/skyeye_rpc_pb';
|
|
3
|
+
import { JSONTransmissionService, JSONTransmissionClient } from './proto/skyeye_rpc_grpc_pb';
|
|
4
|
+
import { RequestFactory } from './RequestFactory';
|
|
5
|
+
import { GetCpuListResponse } from './response/GetCpuListResponse';
|
|
6
|
+
import { Cpu } from './models/Cpu';
|
|
7
|
+
import { GlobalVarType } from './models/GlobalVarType';
|
|
8
|
+
import { stringify } from 'querystring';
|
|
9
|
+
import { GetDeviceListResponse } from './response/GetDeviceListResponse';
|
|
10
|
+
import { GetRunningStateResponse, StateState } from './response/GetRunningStateResponse';
|
|
11
|
+
import { Register } from './models/Register';
|
|
12
|
+
import { GetDeviceTreeResponse } from './response/GetDeviceTreeResponse';
|
|
13
|
+
import { ParseBoardUtils } from './utils/ParseBoardUtils';
|
|
14
|
+
import { GetAllDeviceInfoResponse } from './response/GetAllDeviceInfoResponse';
|
|
15
|
+
import { GetRamAddrInfoResponse } from './response/GetRamAddrInfoResponse';
|
|
16
|
+
import { Device } from './models/Device';
|
|
17
|
+
import { FaultInjectType } from './models/FaultInjectType';
|
|
18
|
+
import { FaultInjectItem } from './models/FaultInjectItem';
|
|
19
|
+
import { GetFaultInjectListResponse } from './response/GetFaultInjectListResponse';
|
|
20
|
+
import { GetDisassembleInfoResponse } from './response/GetDisassembleInfoResponse';
|
|
21
|
+
import { InstructionItem } from './models/InstructionItem';
|
|
22
|
+
import { cp } from 'fs';
|
|
23
|
+
import { GetCpuRegisterInfoResponse } from './response/GetCpuRegisterInfoResponse';
|
|
24
|
+
import { SkyEyeSDKException } from './exception/SkyEyeSDKException';
|
|
25
|
+
let client: JSONTransmissionClient | any = null;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// ----------------------------当前运行程序的设备树----------------------------------------//
|
|
29
|
+
const boardMap = new Map();
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export class SkyEyeClient extends JSONTransmissionClient {
|
|
33
|
+
|
|
34
|
+
private host: string;
|
|
35
|
+
private port: string;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
constructor(host: string, port: string) {
|
|
39
|
+
super(host + ":" + port, grpc.credentials.createInsecure());
|
|
40
|
+
this.host = host;
|
|
41
|
+
this.port = port;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private printRequestLog(request: JSONRequest): void {
|
|
45
|
+
if (request.getRequest() != null) {
|
|
46
|
+
const base = JSON.parse(request.getRequest());
|
|
47
|
+
if (base.request.name === "SE_get_running_status" || base.request.name === "SE_get_all_class_info") {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.log("客户端请求-- ", JSON.stringify(base))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private printResponseLog(ackObj: any): void {
|
|
55
|
+
if (ackObj != null) {
|
|
56
|
+
const name = ackObj.name;
|
|
57
|
+
if (name === "SE_get_running_status" || name === "SE_get_all_class_info") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log(`客户端响应-- `, ackObj);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
public async call(request: JSONRequest) {
|
|
66
|
+
try {
|
|
67
|
+
this.printRequestLog(request)
|
|
68
|
+
const response = await new Promise<JSONResponse>((resolve, reject) => {
|
|
69
|
+
super.callSkyEye(request, (error: grpc.ServiceError | null, response: JSONResponse) => {
|
|
70
|
+
if (error) {
|
|
71
|
+
reject(error);
|
|
72
|
+
} else {
|
|
73
|
+
resolve(response);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
// const res = JSON.parse(response.toString());
|
|
78
|
+
// console.log("res:",res)
|
|
79
|
+
const ackObj = JSON.parse(response.toString()).ack;
|
|
80
|
+
this.printResponseLog(ackObj)
|
|
81
|
+
return ackObj;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error("Error during gRPC call:", error);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
public async runScriptRequest(filename: string) {
|
|
90
|
+
try {
|
|
91
|
+
return await this.call(RequestFactory.getInstance().runScriptRequest(filename));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("Error during runScriptRequest:", error);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async runCommand() {
|
|
99
|
+
try {
|
|
100
|
+
return await this.call(RequestFactory.getInstance().runCommand());
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Error during runCommand:", error);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public async stopCommand() {
|
|
108
|
+
try {
|
|
109
|
+
return await this.call(RequestFactory.getInstance().stopCommand());
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Error during stopCommand:", error);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public async quitCommand() {
|
|
117
|
+
try {
|
|
118
|
+
return await this.call(RequestFactory.getInstance().quitCommand());
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error during quitCommand:", error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async getCpuList() {
|
|
126
|
+
const response = new GetCpuListResponse();
|
|
127
|
+
try {
|
|
128
|
+
const call = await this.call(RequestFactory.getInstance().getCpuList());
|
|
129
|
+
if (call != null) {
|
|
130
|
+
response.isSuccess = true;
|
|
131
|
+
if (call.result != null) {
|
|
132
|
+
const cpuItems: Cpu[] = new Array();
|
|
133
|
+
call.result.forEach(element => {
|
|
134
|
+
const item = new Cpu(null);
|
|
135
|
+
if (element.classname) {
|
|
136
|
+
item.setClassName(element.classname);
|
|
137
|
+
}
|
|
138
|
+
if (element.objname) {
|
|
139
|
+
item.setName(element.objname);
|
|
140
|
+
}
|
|
141
|
+
if (element.mach) {
|
|
142
|
+
if (boardMap.has(String(element.mach))) {
|
|
143
|
+
item.setParent(boardMap.get(String(element.mach)))
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
cpuItems.push(item);
|
|
147
|
+
});
|
|
148
|
+
response.setCpuList(cpuItems)
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
return response;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error("Error during getCpuList:", error);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
public async enableDeviceWork(deviceName: string) {
|
|
165
|
+
try {
|
|
166
|
+
return await this.call(RequestFactory.getInstance().enableDeviceWork(deviceName));
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("Error during enableDeviceWork:", error);
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
public async disableDeviceWork(deviceName: string) {
|
|
175
|
+
try {
|
|
176
|
+
return await this.call(RequestFactory.getInstance().disableDeviceWork(deviceName));
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("Error during disableDeviceWork:", error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
public async changeDir(skyeyeProjectRootDir: string) {
|
|
185
|
+
try {
|
|
186
|
+
return await this.call(RequestFactory.getInstance().changeDir(skyeyeProjectRootDir));
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error("Error during changeDir:", error);
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public async getRunningDeviceInfo() {
|
|
194
|
+
try {
|
|
195
|
+
return await this.call(RequestFactory.getInstance().getRunningDeviceInfo());
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("Error during getRunningDeviceInfo:", error);
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
public async getSimulationTime(cpuName: string) {
|
|
204
|
+
try {
|
|
205
|
+
return await this.call(RequestFactory.getInstance().getSimulationTime(cpuName));
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error("Error during getCurrentSimulationTime:", error);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
public async getCurrentSimulationTime() {
|
|
214
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
215
|
+
if (cpuList.length > 0) {
|
|
216
|
+
return this.getSimulationTime(cpuList[0].getName());
|
|
217
|
+
} else {
|
|
218
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
219
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
public async getDeviceList() {
|
|
225
|
+
const response = new GetDeviceListResponse();
|
|
226
|
+
try {
|
|
227
|
+
const call = await this.call(RequestFactory.getInstance().getDeviceList());
|
|
228
|
+
console.log("getDeviceList:",call)
|
|
229
|
+
if (call != null) {
|
|
230
|
+
response.isSuccess = true;
|
|
231
|
+
const result = call.result;
|
|
232
|
+
if (typeof result === 'object' && result !== null) {
|
|
233
|
+
const objectNode: any = result;
|
|
234
|
+
const it = Object.entries(objectNode);
|
|
235
|
+
for (const machine of it) {
|
|
236
|
+
const machName: string = machine[0];
|
|
237
|
+
const devices: any = machine[1];
|
|
238
|
+
if (typeof devices === 'object' && devices !== null) {
|
|
239
|
+
const deviceNames = Object.keys(devices);
|
|
240
|
+
for (const deviceName of deviceNames) {
|
|
241
|
+
const device = new Device(null);
|
|
242
|
+
const items = devices[deviceName];
|
|
243
|
+
device.name = deviceName;
|
|
244
|
+
if (boardMap.has(machName)) {
|
|
245
|
+
device.parent = boardMap.get(machName);
|
|
246
|
+
}
|
|
247
|
+
if (items && items.hasOwnProperty("classname")) {
|
|
248
|
+
device.className = items["classname"];
|
|
249
|
+
}
|
|
250
|
+
response.deviceList.push(device);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error("Error during getPC:", error);
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
return response
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
public async getPC(cpuName: string) {
|
|
266
|
+
try {
|
|
267
|
+
return await this.call(RequestFactory.getInstance().getCurrentPC(cpuName));
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.error("Error during getPC:", error);
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
public async getCurrentPC() {
|
|
277
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
278
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
279
|
+
try {
|
|
280
|
+
return await this.call(RequestFactory.getInstance().getCurrentPC(cpuList[0].getName()));
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error("Error during getCurrentPC:", error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
287
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
public async getCpuMips(cpuName: string) {
|
|
297
|
+
try {
|
|
298
|
+
return await this.call(RequestFactory.getInstance().getCpuMips(cpuName))
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
public async getCurrentCpuMips() {
|
|
307
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
308
|
+
console.log("测试", cpuList[0].getName())
|
|
309
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
310
|
+
try {
|
|
311
|
+
|
|
312
|
+
return await this.call(RequestFactory.getInstance().getCpuMips(cpuList[0].getName()))
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
319
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
public async getGlobalVarValue(cpuName: string, varName: string, bytesNum: number, valueType: GlobalVarType) {
|
|
325
|
+
try {
|
|
326
|
+
return await this.call(RequestFactory.getInstance().getGlobalVarValue(cpuName, varName, bytesNum, valueType))
|
|
327
|
+
} catch (error) {
|
|
328
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
public async getGlobalVarValueDefault(varName: string, valueType: GlobalVarType) {
|
|
337
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
338
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
339
|
+
try {
|
|
340
|
+
return await this.call(RequestFactory.getInstance().getGlobalVarValue(cpuList[0].getName(), varName, 4, valueType));
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
347
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
public async setGlobalVarValue(cpuName: string, varName: string, bytesNum: number, valueType: GlobalVarType, value: string) {
|
|
356
|
+
try {
|
|
357
|
+
return await this.call(RequestFactory.getInstance().setGlobalVarValue(cpuName, varName, bytesNum, valueType, value))
|
|
358
|
+
} catch (error) {
|
|
359
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
public async setGlobalVarValueDefault(varName: string, valueType: GlobalVarType, value: string) {
|
|
365
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
366
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
367
|
+
try {
|
|
368
|
+
return await this.call(RequestFactory.getInstance().setGlobalVarValue(cpuList[0].getName(), varName, 4, valueType, value));
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
375
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
public async getMemoryValue(cpuName: string, baseAddr: number, length: number) {
|
|
381
|
+
try {
|
|
382
|
+
return this.getAddressingSpace(cpuName, baseAddr, length);
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error("Error during getMemoryValue:", error);
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
public async getAddressingSpace(cpuName: string, baseAddr: number, length: number) {
|
|
391
|
+
try {
|
|
392
|
+
return await this.call(RequestFactory.getInstance().getMemoryValue(cpuName, baseAddr, length));
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error("Error during getAddressingSpace:", error);
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
public async getMemoryValueDefault(baseAddr: number, length: number) {
|
|
402
|
+
try {
|
|
403
|
+
return this.getAddressingSpaceDefault(baseAddr, length);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error("Error during getMemoryValue:", error);
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
public async getAddressingSpaceDefault(baseAddr: number, length: number) {
|
|
412
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
413
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
414
|
+
try {
|
|
415
|
+
return await this.call(RequestFactory.getInstance().getMemoryValue(cpuList[0].getName(), baseAddr, length));
|
|
416
|
+
} catch (error) {
|
|
417
|
+
console.error("Error during getAddressingSpaceDefault:", error);
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
422
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
public async getCpuRegisters(cpuName: string) {
|
|
428
|
+
const response = new GetCpuRegisterInfoResponse();
|
|
429
|
+
try {
|
|
430
|
+
const call = await this.call(RequestFactory.getInstance().getcpuRegisterInfo(cpuName));
|
|
431
|
+
if (call != null) {
|
|
432
|
+
response.isSuccess = true;
|
|
433
|
+
const it = call.result;
|
|
434
|
+
it.forEach(item => {
|
|
435
|
+
const register = new Register(null);
|
|
436
|
+
register.name = item.name;
|
|
437
|
+
register.bits = item.size;
|
|
438
|
+
register.description = item.desc;
|
|
439
|
+
register.value = item.value;
|
|
440
|
+
register.offset = item.offset;
|
|
441
|
+
response.registers.push(register);
|
|
442
|
+
response.registers.sort((r1, r2) => {
|
|
443
|
+
if (r1.offset == null) {
|
|
444
|
+
return 1;
|
|
445
|
+
}
|
|
446
|
+
if (r2.offset== null) {
|
|
447
|
+
return -1;
|
|
448
|
+
}
|
|
449
|
+
if (r1.offset === r2.offset) {
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
return r1.offset! - r2.offset! > 0 ? 1 : -1;
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
} else {
|
|
456
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
457
|
+
}
|
|
458
|
+
} catch (error) {
|
|
459
|
+
console.error("Error during getCpuRegistersDefault:", error);
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
return response;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
public async getCpuRegistersDefault() {
|
|
467
|
+
const cpuList = (await this.getCpuList()).getCpuList();
|
|
468
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
469
|
+
try {
|
|
470
|
+
return await this.getCpuRegisters(cpuList[0].getName());
|
|
471
|
+
} catch (error) {
|
|
472
|
+
console.error("Error during getCpuRegistersDefault:", error);
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
477
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
public async setCpuRegisterValueDefault(register: Register, value: number) {
|
|
483
|
+
try {
|
|
484
|
+
return await this.setCpuRegisterValue(register.getParent().getParent().getName(), register.getParent().getName(), register.getName(), value);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
console.error("Error during getCpuRegistersDefault:", error);
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
public async setCpuRegisterValue(boardName: string, cpuName: string, registerName: string, value: number) {
|
|
493
|
+
const deviceTree = await this.getDeviceTree();
|
|
494
|
+
if (!deviceTree.boardMap.has(boardName)) {
|
|
495
|
+
throw new SkyEyeSDKException("未能找到该板卡");
|
|
496
|
+
}
|
|
497
|
+
const board = boardMap.get(boardName);
|
|
498
|
+
const deviceMap = board.getDeveceMap();
|
|
499
|
+
if (!deviceMap.has(cpuName) || !(deviceMap.get(cpuName) instanceof Cpu)) {
|
|
500
|
+
throw new SkyEyeSDKException("未能找到该设备");
|
|
501
|
+
}
|
|
502
|
+
const cpu = deviceMap.get(cpuName);
|
|
503
|
+
try {
|
|
504
|
+
return await this.call(RequestFactory.getInstance().setRegisterValue(cpu.getParent().getName(), cpuName, registerName, value));
|
|
505
|
+
} catch (error) {
|
|
506
|
+
console.error("Error during getAddressingSpace:", error);
|
|
507
|
+
throw error;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
public async getDeviceTree() {
|
|
513
|
+
const state = (await this.getCurrentRunningState()).getState();
|
|
514
|
+
if (StateState.UNLOADED === state || StateState.QUITED === state) {
|
|
515
|
+
throw new SkyEyeSDKException("当前SkyEye未加载配置,需要加载配置可以获取设备树信息,请检查当前配置")
|
|
516
|
+
}
|
|
517
|
+
const response = new GetDeviceTreeResponse();
|
|
518
|
+
try {
|
|
519
|
+
const call = await this.call(RequestFactory.getInstance().getDeviceTree());
|
|
520
|
+
console.log("call:", call)
|
|
521
|
+
if (call.result != null) {
|
|
522
|
+
const boardMap = ParseBoardUtils.parseBoard(call.result);
|
|
523
|
+
response.boardMap = boardMap;
|
|
524
|
+
response.isSuccess = true;
|
|
525
|
+
} else {
|
|
526
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
527
|
+
}
|
|
528
|
+
} catch (error) {
|
|
529
|
+
console.error("Error during getAddressingSpace:", error);
|
|
530
|
+
throw error;
|
|
531
|
+
}
|
|
532
|
+
return response;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
public async getCurrentRunningState() {
|
|
538
|
+
const response = new GetRunningStateResponse();
|
|
539
|
+
try {
|
|
540
|
+
const call = await this.call(RequestFactory.getInstance().getRunningStatus())
|
|
541
|
+
// { result: 2, error: null, name: 'SE_get_running_status' }
|
|
542
|
+
if (call != null) {
|
|
543
|
+
response.isSuccess = true;
|
|
544
|
+
switch (call.result) {
|
|
545
|
+
case 1:
|
|
546
|
+
response.setState(StateState.UNLOADED);
|
|
547
|
+
break;
|
|
548
|
+
case 2:
|
|
549
|
+
response.setState(StateState.RUNNING);
|
|
550
|
+
break;
|
|
551
|
+
case 3:
|
|
552
|
+
response.setState(StateState.STOPPED);
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
557
|
+
}
|
|
558
|
+
} catch (error) {
|
|
559
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
560
|
+
throw error;
|
|
561
|
+
}
|
|
562
|
+
return response;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
public async getAllDeviceInfo() {
|
|
568
|
+
const response = new GetAllDeviceInfoResponse();
|
|
569
|
+
try {
|
|
570
|
+
const call = await this.call(RequestFactory.getInstance().getAllDeviceInfo());
|
|
571
|
+
if (call != null) {
|
|
572
|
+
response.isSuccess = true;
|
|
573
|
+
const boardMap = ParseBoardUtils.parseBoard(call.result);
|
|
574
|
+
response.boardMap = boardMap;
|
|
575
|
+
} else {
|
|
576
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
577
|
+
}
|
|
578
|
+
} catch (error) {
|
|
579
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
582
|
+
return response;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
public async getRamAddrInfo(machName: string, addr: number) {
|
|
587
|
+
const response = new GetRamAddrInfoResponse();
|
|
588
|
+
try {
|
|
589
|
+
const call = await this.call(RequestFactory.getInstance().getRamAddrInfo(machName, addr))
|
|
590
|
+
if (call.result != null) {
|
|
591
|
+
response.isSuccess = true;
|
|
592
|
+
response.bits = call.result.bits;
|
|
593
|
+
response.value = call.result.value;
|
|
594
|
+
} else {
|
|
595
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
596
|
+
}
|
|
597
|
+
} catch (error) {
|
|
598
|
+
console.error("Error during getCurrentRunningState:", error);
|
|
599
|
+
throw error;
|
|
600
|
+
}
|
|
601
|
+
return response;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
public async setRamFaultInjectDefault(device: Device, addr: number, bit: number, mode: FaultInjectType) {
|
|
606
|
+
try {
|
|
607
|
+
return await this.setRamFaultInject(device.getParent().getName(), device.getName(), addr, bit, mode);
|
|
608
|
+
} catch (error) {
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
public async setRamFaultInject(boardName: string, deviceName: string, addr: number, bit: number, mode: FaultInjectType) {
|
|
616
|
+
try {
|
|
617
|
+
return await this.call(RequestFactory.getInstance().setFaultInject(boardName, deviceName, String(addr), String(bit), mode))
|
|
618
|
+
} catch (error) {
|
|
619
|
+
throw error;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
public async setRegisterFaultInjectDefault(register: Register, bit: number, mode: FaultInjectType) {
|
|
626
|
+
try {
|
|
627
|
+
return await this.setRegisterFaultInject(register.getParent().getParent().getName(), register.getParent().getName(), register.baseAddr, bit, mode)
|
|
628
|
+
} catch (error) {
|
|
629
|
+
throw error;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
public async setRegisterFaultInject(boardName: string, deviceName: string, addr: number, bit: number, mode: FaultInjectType) {
|
|
635
|
+
try {
|
|
636
|
+
return await this.call(RequestFactory.getInstance().setFaultInject(boardName, deviceName, "0x" + String(addr), String(bit), mode))
|
|
637
|
+
} catch (error) {
|
|
638
|
+
throw error;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
public async deleteFaultInjectDefault(faultInjectItem: FaultInjectItem) {
|
|
644
|
+
try {
|
|
645
|
+
return await this.deleteFaultInject(faultInjectItem.boardName, faultInjectItem.deviceName,
|
|
646
|
+
faultInjectItem.addr, String(faultInjectItem.bit),
|
|
647
|
+
faultInjectItem.type);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
throw error;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
public async deleteFaultInject(boardName: string, deviceName: string, addr: number, bit: string, mode: FaultInjectType) {
|
|
655
|
+
try {
|
|
656
|
+
return await this.call(RequestFactory.getInstance().deleteFaultInject(boardName, deviceName, "0x" + String(addr), String(bit), mode))
|
|
657
|
+
} catch (error) {
|
|
658
|
+
throw error;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
public async getFaultInjectList() {
|
|
664
|
+
const response = new GetFaultInjectListResponse();
|
|
665
|
+
try {
|
|
666
|
+
const call = await this.call(RequestFactory.getInstance().getFaultInjectList());
|
|
667
|
+
if (call.result != null) {
|
|
668
|
+
response.isSuccess = true;
|
|
669
|
+
const items = new Array();
|
|
670
|
+
call.result.forEach(item => {
|
|
671
|
+
const faultInjectItem = new FaultInjectItem(null);
|
|
672
|
+
if (item != null) {
|
|
673
|
+
faultInjectItem.deviceName = item.get(1);
|
|
674
|
+
faultInjectItem.registerName = item.get(2);
|
|
675
|
+
faultInjectItem.addr = item.get(3);
|
|
676
|
+
faultInjectItem.bit = item.get(4);
|
|
677
|
+
switch (String(item.get(5))) {
|
|
678
|
+
case "0":
|
|
679
|
+
faultInjectItem.type = FaultInjectType.SET_ZERO
|
|
680
|
+
break;
|
|
681
|
+
case "1":
|
|
682
|
+
faultInjectItem.type = FaultInjectType.SET_ONE
|
|
683
|
+
break;
|
|
684
|
+
case "2":
|
|
685
|
+
faultInjectItem.type = FaultInjectType.SET_REVE
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
items.push(faultInjectItem)
|
|
690
|
+
})
|
|
691
|
+
response.faultInjectItems = items;
|
|
692
|
+
}
|
|
693
|
+
} catch (error) {
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
696
|
+
return response;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
public async getDisassembleInfo(cpuName: string, startAddr: number, nums: number) {
|
|
701
|
+
const response = new GetDisassembleInfoResponse();
|
|
702
|
+
try {
|
|
703
|
+
const call = await this.call(RequestFactory.getInstance().getDisassembleInfo(cpuName, startAddr, nums))
|
|
704
|
+
if (call.result != null) {
|
|
705
|
+
response.isSuccess = true;
|
|
706
|
+
const instructionItems = new Array();
|
|
707
|
+
call.result.forEach(item => {
|
|
708
|
+
const instructionItem = new InstructionItem();
|
|
709
|
+
instructionItem.addr = item.get(0);
|
|
710
|
+
instructionItem.func = item.get(1);
|
|
711
|
+
instructionItem.content = item.get(2);
|
|
712
|
+
instructionItems.push(instructionItem)
|
|
713
|
+
})
|
|
714
|
+
response.instructions = instructionItems;
|
|
715
|
+
} else {
|
|
716
|
+
throw new SkyEyeSDKException(String(call.error));
|
|
717
|
+
}
|
|
718
|
+
} catch (error) {
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
return response;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
public async getDisassembleInfoDefault(startAddr: number, nums: number) {
|
|
726
|
+
const cpuList = (await this.getCpuList()).getCpuList;
|
|
727
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
728
|
+
return this.getDisassembleInfo(cpuList[0].name, startAddr, nums);
|
|
729
|
+
} else {
|
|
730
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
731
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
public async SingleStep(cpuName: string) {
|
|
738
|
+
try {
|
|
739
|
+
return await this.call(RequestFactory.getInstance().singleStep(cpuName))
|
|
740
|
+
} catch (error) {
|
|
741
|
+
throw error;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
public async SingleStepDefault() {
|
|
747
|
+
const cpuList = (await this.getCpuList()).getCpuList;
|
|
748
|
+
if (cpuList != null && cpuList.length > 0) {
|
|
749
|
+
return this.SingleStep(cpuList[0].name);
|
|
750
|
+
} else {
|
|
751
|
+
console.error("无法获取cpu,请确认cpu是否存在:");
|
|
752
|
+
throw new SkyEyeSDKException("无法获取cpu,请确认cpu是否存在:");
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
public close(): boolean {
|
|
758
|
+
super.close();
|
|
759
|
+
console.log('gRPC客户端已断开');
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
public getHost() {
|
|
765
|
+
return this.host;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
public getPort() {
|
|
769
|
+
return this.port;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
}
|