skyeye-sdk-js 1.2.7 → 1.2.8
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/dist/src/SkyEyeClient.d.ts +3 -1
- package/dist/src/SkyEyeClient.js +35 -6
- package/dist/test.js +6 -0
- package/package.json +1 -1
- package/src/SkyEyeClient.ts +52 -18
- package/test.ts +6 -0
|
@@ -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<
|
|
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;
|
package/dist/src/SkyEyeClient.js
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
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
package/src/SkyEyeClient.ts
CHANGED
|
@@ -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) {
|
|
@@ -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
|
-
|
|
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: '
|
|
834
|
-
console.log('initSkyEyeAndRun 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
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
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
|
|