skyeye-sdk-js 1.4.3 → 1.4.5

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.
@@ -12,7 +12,7 @@ export declare class RequestFactory {
12
12
  stopCommand(): JSONRequest;
13
13
  quitCommand(): JSONRequest;
14
14
  getCpuList(): JSONRequest;
15
- getMemoryValue(cpuName: string, baseAddr: string, length: string): JSONRequest;
15
+ getMemoryValue(cpuName: string, baseAddr: string, length: string, addressWidth?: number): JSONRequest;
16
16
  setMemoryValue(cpuName: string, baseAddr: string, value: string, length: string): JSONRequest;
17
17
  enableDeviceWork(deviceName: string): JSONRequest;
18
18
  disableDeviceWork(deviceName: string): JSONRequest;
@@ -66,12 +66,13 @@ class RequestFactory {
66
66
  request.setRequest(baseRequest.toJSONString());
67
67
  return request;
68
68
  }
69
- getMemoryValue(cpuName, baseAddr, length) {
69
+ getMemoryValue(cpuName, baseAddr, length, addressWidth) {
70
70
  const baseRequest = new BaseRequest_1.BaseRequest("SE_get_memory_value");
71
71
  const args = {};
72
72
  args.cpuname = cpuName;
73
73
  args.baseaddr = "0x" + baseAddr;
74
74
  args.length = length;
75
+ args.address_width = addressWidth;
75
76
  baseRequest.setArgs(args);
76
77
  const request = new skyeye_rpc_pb_1.JSONRequest();
77
78
  request.setRequest(baseRequest.toJSONString());
@@ -24,6 +24,7 @@ export declare class SkyEyeClient extends JSONTransmissionClient {
24
24
  RunTestcase(json: string): Promise<any>;
25
25
  Monitor(json: string): Promise<any>;
26
26
  call(request: JSONRequest): Promise<any>;
27
+ callTimeout(request: JSONRequest, timeout: number): Promise<any>;
27
28
  private printRequestLog;
28
29
  private printResponseLog;
29
30
  runScriptRequest(filename: string): Promise<any>;
@@ -49,8 +50,8 @@ export declare class SkyEyeClient extends JSONTransmissionClient {
49
50
  getGlobalVarValueDefault(varName: string, valueType: GlobalVarType): Promise<any>;
50
51
  setGlobalVarValue(cpuName: string, varName: string, bytesNum: number, valueType: GlobalVarType, value: string): Promise<any>;
51
52
  setGlobalVarValueDefault(varName: string, valueType: GlobalVarType, value: string): Promise<any>;
52
- getAddressingSpace(cpuName: string, baseAddr: string, length: string): Promise<any>;
53
- getMemoryValue(cpuName: string, baseAddr: string, length: string): Promise<any>;
53
+ getAddressingSpace(cpuName: string, baseAddr: string, length: string, addressWidth?: number): Promise<any>;
54
+ getMemoryValue(cpuName: string, baseAddr: string, length: string, addressWidth?: number): Promise<any>;
54
55
  getMemoryValueDefault(baseAddr: string, length: string): Promise<any>;
55
56
  getAddressingSpaceDefault(baseAddr: string, length: string): Promise<any>;
56
57
  setMemoryValue(cpuName: string, baseAddr: string, value: string, length: string): Promise<any>;
@@ -155,6 +155,37 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
155
155
  }
156
156
  });
157
157
  }
158
+ callTimeout(request, timeout) {
159
+ const _super = Object.create(null, {
160
+ callSkyEye: { get: () => super.callSkyEye }
161
+ });
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ try {
164
+ // this.printRequestLog(request)
165
+ const deadline = new Date(Date.now() + timeout * 1000); // 设置5秒超时
166
+ const response = yield new Promise((resolve, reject) => {
167
+ _super.callSkyEye.call(this, request, (error, response) => {
168
+ if (error) {
169
+ reject(error);
170
+ }
171
+ else {
172
+ resolve(response);
173
+ }
174
+ }, { deadline });
175
+ });
176
+ // const res = JSON.parse(response.toString());
177
+ // console.log("res:",res)
178
+ const ackObj = JSON.parse(response.toString()).ack;
179
+ // this.printResponseLog(ackObj)
180
+ return ackObj;
181
+ }
182
+ catch (error) {
183
+ // console.error("Error during gRPC request:", JSON.stringify(request));
184
+ // console.error("Error during gRPC call:", error);
185
+ throw error;
186
+ }
187
+ });
188
+ }
158
189
  printRequestLog(request) {
159
190
  if (request.getRequest() != null) {
160
191
  const base = JSON.parse(request.getRequest());
@@ -209,9 +240,14 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
209
240
  quitCommand() {
210
241
  return __awaiter(this, void 0, void 0, function* () {
211
242
  try {
212
- return yield this.call(RequestFactory_1.RequestFactory.getInstance().quitCommand());
243
+ return yield this.callTimeout(RequestFactory_1.RequestFactory.getInstance().quitCommand(), 2);
213
244
  }
214
245
  catch (error) {
246
+ // 无法连接,杀死进程
247
+ if (this.childProcess) {
248
+ console.log('Terminating SkyEye child process...');
249
+ this.childProcess.kill();
250
+ }
215
251
  console.error("Error during quitCommand:", error);
216
252
  throw error;
217
253
  }
@@ -513,10 +549,10 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
513
549
  }
514
550
  });
515
551
  }
516
- getAddressingSpace(cpuName, baseAddr, length) {
552
+ getAddressingSpace(cpuName, baseAddr, length, addressWidth) {
517
553
  return __awaiter(this, void 0, void 0, function* () {
518
554
  try {
519
- return yield this.call(RequestFactory_1.RequestFactory.getInstance().getMemoryValue(cpuName, baseAddr, length));
555
+ return yield this.call(RequestFactory_1.RequestFactory.getInstance().getMemoryValue(cpuName, baseAddr, length, addressWidth));
520
556
  }
521
557
  catch (error) {
522
558
  console.error("Error during getAddressingSpace:", error);
@@ -524,10 +560,10 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
524
560
  }
525
561
  });
526
562
  }
527
- getMemoryValue(cpuName, baseAddr, length) {
563
+ getMemoryValue(cpuName, baseAddr, length, addressWidth) {
528
564
  return __awaiter(this, void 0, void 0, function* () {
529
565
  try {
530
- return this.getAddressingSpace(cpuName, baseAddr, length);
566
+ return this.getAddressingSpace(cpuName, baseAddr, length, addressWidth);
531
567
  }
532
568
  catch (error) {
533
569
  console.error("Error during getMemoryValue:", error);
@@ -1078,13 +1114,13 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
1078
1114
  checkModule() {
1079
1115
  return new Promise((resolve, reject) => {
1080
1116
  let flag = true;
1081
- const checkInterval = 500;
1082
- const timeout = 30000;
1117
+ const checkInterval = 100;
1118
+ const timeout = 300000;
1083
1119
  const startTime = Date.now();
1084
1120
  const check = () => {
1085
1121
  const elapsedTime = Date.now() - startTime;
1086
1122
  if (elapsedTime >= timeout) {
1087
- reject(new Error("Timeout: State check exceeded 30 seconds"));
1123
+ reject(new Error("Timeout: State check exceeded 300 seconds"));
1088
1124
  return;
1089
1125
  }
1090
1126
  if (!flag) {
@@ -1111,13 +1147,13 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
1111
1147
  checkState() {
1112
1148
  return new Promise((resolve, reject) => {
1113
1149
  let flag = true;
1114
- const checkInterval = 500;
1115
- const timeout = 30000;
1150
+ const checkInterval = 100;
1151
+ const timeout = 300000;
1116
1152
  const startTime = Date.now();
1117
1153
  const check = () => {
1118
1154
  const elapsedTime = Date.now() - startTime;
1119
1155
  if (elapsedTime >= timeout) {
1120
- reject(new Error("Timeout: State check exceeded 30 seconds"));
1156
+ reject(new Error("Timeout: State check exceeded 300 seconds"));
1121
1157
  return;
1122
1158
  }
1123
1159
  if (!flag) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skyeye-sdk-js",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "gRPC to SkyEye",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -81,12 +81,13 @@ export class RequestFactory {
81
81
  }
82
82
 
83
83
 
84
- public getMemoryValue(cpuName: string, baseAddr: string, length: string) {
84
+ public getMemoryValue(cpuName: string, baseAddr: string, length: string, addressWidth?: number) {
85
85
  const baseRequest = new BaseRequest("SE_get_memory_value");
86
- const args: { [key: string]: string } = {};
86
+ const args: { [key: string]: any } = {};
87
87
  args.cpuname = cpuName;
88
88
  args.baseaddr = "0x" + baseAddr;
89
89
  args.length = length;
90
+ args.address_width = addressWidth;
90
91
  baseRequest.setArgs(args)
91
92
  const request = new JSONRequest()
92
93
  request.setRequest(baseRequest.toJSONString());
@@ -119,6 +119,31 @@ export class SkyEyeClient extends JSONTransmissionClient {
119
119
  }
120
120
  }
121
121
 
122
+ public async callTimeout(request: JSONRequest, timeout:number) {
123
+ try {
124
+ // this.printRequestLog(request)
125
+ const deadline = new Date(Date.now() + timeout * 1000); // 设置5秒超时
126
+ const response = await new Promise<JSONResponse>((resolve, reject) => {
127
+ super.callSkyEye(request, (error: grpc.ServiceError | null, response: JSONResponse) => {
128
+ if (error) {
129
+ reject(error);
130
+ } else {
131
+ resolve(response);
132
+ }
133
+ },{deadline});
134
+ });
135
+ // const res = JSON.parse(response.toString());
136
+ // console.log("res:",res)
137
+ const ackObj = JSON.parse(response.toString()).ack;
138
+ // this.printResponseLog(ackObj)
139
+ return ackObj;
140
+ } catch (error) {
141
+ // console.error("Error during gRPC request:", JSON.stringify(request));
142
+ // console.error("Error during gRPC call:", error);
143
+ throw error;
144
+ }
145
+ }
146
+
122
147
  private printRequestLog(request: JSONRequest): void {
123
148
  if (request.getRequest() != null) {
124
149
  const base = JSON.parse(request.getRequest());
@@ -169,8 +194,13 @@ export class SkyEyeClient extends JSONTransmissionClient {
169
194
 
170
195
  public async quitCommand() {
171
196
  try {
172
- return await this.call(RequestFactory.getInstance().quitCommand());
197
+ return await this.callTimeout(RequestFactory.getInstance().quitCommand(),2);
173
198
  } catch (error) {
199
+ // 无法连接,杀死进程
200
+ if (this.childProcess) {
201
+ console.log('Terminating SkyEye child process...');
202
+ this.childProcess.kill();
203
+ }
174
204
  console.error("Error during quitCommand:", error);
175
205
  throw error;
176
206
  }
@@ -461,17 +491,17 @@ export class SkyEyeClient extends JSONTransmissionClient {
461
491
 
462
492
 
463
493
 
464
- public async getAddressingSpace(cpuName: string, baseAddr: string, length: string) {
494
+ public async getAddressingSpace(cpuName: string, baseAddr: string, length: string, addressWidth?: number) {
465
495
  try {
466
- return await this.call(RequestFactory.getInstance().getMemoryValue(cpuName, baseAddr, length));
496
+ return await this.call(RequestFactory.getInstance().getMemoryValue(cpuName, baseAddr, length, addressWidth));
467
497
  } catch (error) {
468
498
  console.error("Error during getAddressingSpace:", error);
469
499
  throw error;
470
500
  }
471
501
  }
472
- public async getMemoryValue(cpuName: string, baseAddr: string, length: string) {
502
+ public async getMemoryValue(cpuName: string, baseAddr: string, length: string, addressWidth?: number) {
473
503
  try {
474
- return this.getAddressingSpace(cpuName, baseAddr, length);
504
+ return this.getAddressingSpace(cpuName, baseAddr, length, addressWidth);
475
505
  } catch (error) {
476
506
  console.error("Error during getMemoryValue:", error);
477
507
  throw error;
@@ -1001,15 +1031,15 @@ export class SkyEyeClient extends JSONTransmissionClient {
1001
1031
  private checkModule() {
1002
1032
  return new Promise((resolve, reject) => {
1003
1033
  let flag = true;
1004
- const checkInterval = 500;
1005
- const timeout = 30000;
1034
+ const checkInterval = 100;
1035
+ const timeout = 300000;
1006
1036
  const startTime = Date.now();
1007
1037
 
1008
1038
 
1009
1039
  const check = () => {
1010
1040
  const elapsedTime = Date.now() - startTime;
1011
1041
  if (elapsedTime >= timeout) {
1012
- reject(new Error("Timeout: State check exceeded 30 seconds"));
1042
+ reject(new Error("Timeout: State check exceeded 300 seconds"));
1013
1043
  return;
1014
1044
  }
1015
1045
 
@@ -1039,15 +1069,15 @@ export class SkyEyeClient extends JSONTransmissionClient {
1039
1069
  private checkState() {
1040
1070
  return new Promise((resolve, reject) => {
1041
1071
  let flag = true;
1042
- const checkInterval = 500;
1043
- const timeout = 30000;
1072
+ const checkInterval = 100;
1073
+ const timeout = 300000;
1044
1074
  const startTime = Date.now();
1045
1075
 
1046
1076
 
1047
1077
  const check = () => {
1048
1078
  const elapsedTime = Date.now() - startTime;
1049
1079
  if (elapsedTime >= timeout) {
1050
- reject(new Error("Timeout: State check exceeded 30 seconds"));
1080
+ reject(new Error("Timeout: State check exceeded 300 seconds"));
1051
1081
  return;
1052
1082
  }
1053
1083