skyeye-sdk-js 1.2.7 → 1.2.9

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.
@@ -72,7 +72,9 @@ export declare class SkyEyeClient extends JSONTransmissionClient {
72
72
  getPort(): string;
73
73
  initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): void;
74
74
  private childProcess;
75
- initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): Promise<string>;
75
+ initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): Promise<boolean>;
76
+ private flag;
77
+ private checkState;
76
78
  private startSkyEye;
77
79
  private setWorkingDirectory;
78
80
  private runScript;
@@ -62,6 +62,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
62
62
  constructor(host, port) {
63
63
  super(host + ":" + port, grpc.credentials.createInsecure(), null);
64
64
  this.childProcess = null;
65
+ this.flag = true;
65
66
  this.host = host;
66
67
  this.port = port;
67
68
  }
@@ -73,7 +74,8 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
73
74
  return __awaiter(this, void 0, void 0, function* () {
74
75
  try {
75
76
  const request = new skyeye_rpc_pb_1.JSONRequest();
76
- request.setRequest(json);
77
+ // request.setRequest(json);
78
+ request.setRequest("{\"request\": {\"name\": \"chdir\"}");
77
79
  const stream = _super.stopRunTest.call(this, request);
78
80
  return stream;
79
81
  }
@@ -123,7 +125,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
123
125
  });
124
126
  return __awaiter(this, void 0, void 0, function* () {
125
127
  try {
126
- this.printRequestLog(request);
128
+ // this.printRequestLog(request)
127
129
  const response = yield new Promise((resolve, reject) => {
128
130
  _super.callSkyEye.call(this, request, (error, response) => {
129
131
  if (error) {
@@ -137,7 +139,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
137
139
  // const res = JSON.parse(response.toString());
138
140
  // console.log("res:",res)
139
141
  const ackObj = JSON.parse(response.toString()).ack;
140
- this.printResponseLog(ackObj);
142
+ // this.printResponseLog(ackObj)
141
143
  return ackObj;
142
144
  }
143
145
  catch (error) {
@@ -161,7 +163,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
161
163
  if (name === "SE_get_running_status" || name === "SE_get_all_class_info") {
162
164
  return;
163
165
  }
164
- console.log(`客户端响应-- `, ackObj);
166
+ console.log(`client response-- `, ackObj);
165
167
  }
166
168
  }
167
169
  runScriptRequest(filename) {
@@ -925,11 +927,10 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
925
927
  try {
926
928
  console.log('runExample');
927
929
  this.childProcess = yield this.startSkyEye(port, skyeyeDir);
928
- setTimeout(() => __awaiter(this, void 0, void 0, function* () {
929
- yield this.setWorkingDirectory(pathSkyEye, port);
930
- yield this.runScript(fileName, port);
931
- }), 2000);
932
- return "1";
930
+ yield this.checkState();
931
+ yield this.setWorkingDirectory(pathSkyEye, port);
932
+ yield this.runScript(fileName, port);
933
+ return true;
933
934
  }
934
935
  catch (error) {
935
936
  console.error("initSkyEyeAndRun error:", error);
@@ -941,6 +942,34 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
941
942
  }
942
943
  });
943
944
  }
945
+ checkState() {
946
+ return new Promise((resolve, reject) => {
947
+ const checkInterval = 500;
948
+ const check = () => {
949
+ if (!this.flag) {
950
+ resolve("");
951
+ return;
952
+ }
953
+ console.log("test4");
954
+ this.getCurrentRunningState()
955
+ .then((result) => {
956
+ const state = result.getState();
957
+ console.log("initSkyEyeAndRun2:", state);
958
+ if (state === GetRunningStateResponse_1.StateState.UNLOADED) {
959
+ this.flag = false;
960
+ resolve("");
961
+ }
962
+ else {
963
+ setTimeout(check, checkInterval);
964
+ }
965
+ })
966
+ .catch(() => {
967
+ setTimeout(check, checkInterval);
968
+ });
969
+ };
970
+ check();
971
+ });
972
+ }
944
973
  startSkyEye(port, skyeyeDir) {
945
974
  console.log('startSkyEye');
946
975
  return new Promise((resolve, reject) => {
package/dist/test.js CHANGED
@@ -32,6 +32,12 @@ function test() {
32
32
  const port = "50051";
33
33
  // await client.initSkyEyeAndRun(pathSkyEye,fileName,port,skyeyeDir);
34
34
  yield client.initSkyEyeAndRun2(pathSkyEye, fileName, port, skyeyeDir);
35
+ // setTimeout(async ()=>{
36
+ // const quitResponse = await client.quitCommand()
37
+ // console.log("quitResponse",quitResponse)
38
+ // const response = await client.stopGrpcService("")
39
+ // console.log("stopGrpcService",response)
40
+ // },6000)
35
41
  // GrpcUtil.initAndRunExample();
36
42
  // const bean:string = '{"id":"33d209da-2459-4e49-97c3-5b1509bc638c","steps":[{"condition":{"type":10,"value":"123"},"send":{"target":{"type":2,"addr":"1222"},"data":"0101011101"}},{"condition":{"type":0,"value":"0xff"},"send":{"target":{"type":2,"addr":"1222"},"data":"0101011101"}}],"expects":[{"condition":{"type":0,"value":"0xff"},"send":{"target":{"type":3,"addr":"2221"}}}]}';
37
43
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skyeye-sdk-js",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "gRPC to SkyEye",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,10 +44,11 @@ export class SkyEyeClient extends JSONTransmissionClient {
44
44
 
45
45
 
46
46
  //终止所有grpc通信
47
- public async stopGrpcService(json: string){
47
+ public async stopGrpcService(json: string) {
48
48
  try {
49
49
  const request = new JSONRequest();
50
- request.setRequest(json);
50
+ // request.setRequest(json);
51
+ request.setRequest("{\"request\": {\"name\": \"chdir\"}");
51
52
  const stream = super.stopRunTest(request);
52
53
  return stream;
53
54
  } catch (error) {
@@ -87,7 +88,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
87
88
 
88
89
  public async call(request: JSONRequest) {
89
90
  try {
90
- this.printRequestLog(request)
91
+ // this.printRequestLog(request)
91
92
  const response = await new Promise<JSONResponse>((resolve, reject) => {
92
93
  super.callSkyEye(request, (error: grpc.ServiceError | null, response: JSONResponse) => {
93
94
  if (error) {
@@ -100,7 +101,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
100
101
  // const res = JSON.parse(response.toString());
101
102
  // console.log("res:",res)
102
103
  const ackObj = JSON.parse(response.toString()).ack;
103
- this.printResponseLog(ackObj)
104
+ // this.printResponseLog(ackObj)
104
105
  return ackObj;
105
106
  } catch (error) {
106
107
  console.error("Error during gRPC call:", error);
@@ -124,7 +125,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
124
125
  if (name === "SE_get_running_status" || name === "SE_get_all_class_info") {
125
126
  return;
126
127
  }
127
- console.log(`客户端响应-- `, ackObj);
128
+ console.log(`client response-- `, ackObj);
128
129
  }
129
130
  }
130
131
 
@@ -497,7 +498,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
497
498
  let numOffset2: number = parseInt(r2.offset);
498
499
  let result: number = 0;
499
500
  if (!isNaN(numOffset1) && !isNaN(numOffset2)) {
500
- result = numOffset1 - numOffset2;
501
+ result = numOffset1 - numOffset2;
501
502
  console.log("Result:", result);
502
503
  } else {
503
504
  console.log("Invalid offset values.");
@@ -826,12 +827,12 @@ export class SkyEyeClient extends JSONTransmissionClient {
826
827
  public initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
827
828
  console.log('runExample');
828
829
  cp.exec(skyeyeDir + " -q " + port + "\n", (err: any, stdout: any, stderr: any) => {
829
- if(err){
830
- console.log("initSkyEyeAndRun error:",err)
830
+ if (err) {
831
+ console.log("initSkyEyeAndRun error:", err)
831
832
  return
832
833
  }
833
- console.log('initSkyEyeAndRun stdout: ' ,stdout);
834
- console.log('initSkyEyeAndRun stderr: ' , stderr);
834
+ console.log('initSkyEyeAndRun stdout: ', stdout);
835
+ console.log('initSkyEyeAndRun stderr: ', stderr);
835
836
  });
836
837
  console.log('wait');
837
838
  setTimeout(() => {
@@ -855,16 +856,15 @@ export class SkyEyeClient extends JSONTransmissionClient {
855
856
 
856
857
  private childProcess: cp.ChildProcess | null = null;
857
858
 
859
+
858
860
  public async initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
859
861
  try {
860
862
  console.log('runExample');
861
863
  this.childProcess = await this.startSkyEye(port, skyeyeDir);
862
- setTimeout(async () => {
863
- await this.setWorkingDirectory(pathSkyEye, port);
864
- await this.runScript(fileName, port);
865
- }, 2000);
866
-
867
- return "1";
864
+ await this.checkState();
865
+ await this.setWorkingDirectory(pathSkyEye, port);
866
+ await this.runScript(fileName, port);
867
+ return true;
868
868
  } catch (error) {
869
869
  console.error("initSkyEyeAndRun error:", error);
870
870
  if (this.childProcess) {
@@ -875,12 +875,46 @@ export class SkyEyeClient extends JSONTransmissionClient {
875
875
  }
876
876
  }
877
877
 
878
+
879
+
880
+
881
+
882
+ private flag = true;
883
+ private checkState() {
884
+ return new Promise((resolve, reject) => {
885
+ const checkInterval = 500;
886
+ const check = () => {
887
+ if (!this.flag) {
888
+ resolve("");
889
+ return;
890
+ }
891
+ console.log("test4")
892
+ this.getCurrentRunningState()
893
+ .then((result) => {
894
+ const state = result.getState();
895
+ console.log("initSkyEyeAndRun2:", state);
896
+ if (state === StateState.UNLOADED) {
897
+ this.flag = false;
898
+ resolve("");
899
+ } else {
900
+ setTimeout(check, checkInterval);
901
+ }
902
+ })
903
+ .catch(() => {
904
+ setTimeout(check, checkInterval);
905
+ });
906
+ };
907
+ check();
908
+ });
909
+ }
910
+
911
+
878
912
  private startSkyEye(port: string, skyeyeDir: string): Promise<cp.ChildProcess> {
879
913
  console.log('startSkyEye');
880
914
  return new Promise((resolve, reject) => {
881
915
  const childProcess = cp.exec(`${skyeyeDir} -q ${port}`, (err: any, stdout: any, stderr: any) => {
882
916
  if (err) {
883
- console.log('startSkyEye error',err);
917
+ console.log('startSkyEye error', err);
884
918
  reject(err);
885
919
  } else {
886
920
  console.log('startSkyEye stdout: ', stdout);
@@ -896,12 +930,12 @@ export class SkyEyeClient extends JSONTransmissionClient {
896
930
  });
897
931
  }
898
932
 
899
-
933
+
900
934
  private setWorkingDirectory(pathSkyEye: string, port: string): Promise<void> {
901
935
  const client = new JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
902
936
  const Jr = new JSONRequest();
903
937
  Jr.setRequest(`{"request": {"name": "chdir", "args": {"path":"${pathSkyEye}"}}}`);
904
-
938
+
905
939
  return new Promise((resolve, reject) => {
906
940
  client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
907
941
  if (error) {
@@ -914,12 +948,12 @@ export class SkyEyeClient extends JSONTransmissionClient {
914
948
  });
915
949
  });
916
950
  }
917
-
951
+
918
952
  private runScript(fileName: string, port: string): Promise<void> {
919
953
  const client = new JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
920
954
  const Jr = new JSONRequest();
921
955
  Jr.setRequest(`{"request": {"name": "run_script", "args": {"filename":"${fileName}"}}}`);
922
-
956
+
923
957
  return new Promise((resolve, reject) => {
924
958
  client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
925
959
  if (error) {
package/test.ts CHANGED
@@ -32,6 +32,12 @@ async function test() {
32
32
 
33
33
  await client.initSkyEyeAndRun2(pathSkyEye,fileName,port,skyeyeDir)
34
34
 
35
+ // setTimeout(async ()=>{
36
+ // const quitResponse = await client.quitCommand()
37
+ // console.log("quitResponse",quitResponse)
38
+ // const response = await client.stopGrpcService("")
39
+ // console.log("stopGrpcService",response)
40
+ // },6000)
35
41
 
36
42
  // GrpcUtil.initAndRunExample();
37
43