skyeye-sdk-js 1.2.1 → 1.2.3
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 +2 -1
- package/dist/src/SkyEyeClient.js +36 -29
- package/dist/test.js +2 -1
- package/package.json +1 -1
- package/src/SkyEyeClient.ts +39 -31
- package/test.ts +3 -1
|
@@ -69,8 +69,9 @@ export declare class SkyEyeClient extends JSONTransmissionClient {
|
|
|
69
69
|
close(): boolean;
|
|
70
70
|
getHost(): string;
|
|
71
71
|
getPort(): string;
|
|
72
|
+
initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): void;
|
|
72
73
|
private childProcess;
|
|
73
|
-
|
|
74
|
+
initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): Promise<string>;
|
|
74
75
|
private startSkyEye;
|
|
75
76
|
private setWorkingDirectory;
|
|
76
77
|
private runScript;
|
package/dist/src/SkyEyeClient.js
CHANGED
|
@@ -61,32 +61,6 @@ const boardMap = new Map();
|
|
|
61
61
|
class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
62
62
|
constructor(host, port) {
|
|
63
63
|
super(host + ":" + port, grpc.credentials.createInsecure(), null);
|
|
64
|
-
// public initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
|
|
65
|
-
// console.log('runExample');
|
|
66
|
-
// cp.exec(skyeyeDir + " -q " + port + "\n", (err: any, stdout: any, stderr: any) => {
|
|
67
|
-
// if(err){
|
|
68
|
-
// console.log("initSkyEyeAndRun error:",err)
|
|
69
|
-
// return
|
|
70
|
-
// }
|
|
71
|
-
// console.log('initSkyEyeAndRun stdout: ' ,stdout);
|
|
72
|
-
// console.log('initSkyEyeAndRun stderr: ' , stderr);
|
|
73
|
-
// });
|
|
74
|
-
// setTimeout(() => {
|
|
75
|
-
// client = new JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
76
|
-
// // console.log('client:' + client);
|
|
77
|
-
// const Jr = new JSONRequest();
|
|
78
|
-
// Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
79
|
-
// client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
80
|
-
// console.log("chdir res:" + response + error);
|
|
81
|
-
// Jr.setRequest("{\"request\": {\"name\": \"run_script\", \"args\": {\"filename\":\"" + fileName + "\"}}}");
|
|
82
|
-
// client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
83
|
-
// console.log("run_script res:" + response + error);
|
|
84
|
-
// // this.runCommand()
|
|
85
|
-
// return "1";
|
|
86
|
-
// });
|
|
87
|
-
// });
|
|
88
|
-
// }, 2000);
|
|
89
|
-
// }
|
|
90
64
|
this.childProcess = null;
|
|
91
65
|
this.host = host;
|
|
92
66
|
this.port = port;
|
|
@@ -902,28 +876,59 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
902
876
|
return this.port;
|
|
903
877
|
}
|
|
904
878
|
initSkyEyeAndRun(pathSkyEye, fileName, port, skyeyeDir) {
|
|
879
|
+
console.log('runExample');
|
|
880
|
+
cp.exec(skyeyeDir + " -q " + port + "\n", (err, stdout, stderr) => {
|
|
881
|
+
if (err) {
|
|
882
|
+
console.log("initSkyEyeAndRun error:", err);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
console.log('initSkyEyeAndRun stdout: ', stdout);
|
|
886
|
+
console.log('initSkyEyeAndRun stderr: ', stderr);
|
|
887
|
+
});
|
|
888
|
+
console.log('wait');
|
|
889
|
+
setTimeout(() => {
|
|
890
|
+
client = new skyeye_rpc_grpc_pb_1.JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
891
|
+
console.log('client:' + client);
|
|
892
|
+
const Jr = new skyeye_rpc_pb_1.JSONRequest();
|
|
893
|
+
Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
894
|
+
client.callSkyEye(Jr, (error, response) => {
|
|
895
|
+
console.log("chdir res:" + response + error);
|
|
896
|
+
Jr.setRequest("{\"request\": {\"name\": \"run_script\", \"args\": {\"filename\":\"" + fileName + "\"}}}");
|
|
897
|
+
client.callSkyEye(Jr, (error, response) => {
|
|
898
|
+
console.log("run_script res:" + response + error);
|
|
899
|
+
// this.runCommand()
|
|
900
|
+
return "1";
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
}, 2000);
|
|
904
|
+
}
|
|
905
|
+
initSkyEyeAndRun2(pathSkyEye, fileName, port, skyeyeDir) {
|
|
905
906
|
return __awaiter(this, void 0, void 0, function* () {
|
|
906
907
|
try {
|
|
907
908
|
console.log('runExample');
|
|
908
909
|
this.childProcess = yield this.startSkyEye(port, skyeyeDir);
|
|
909
|
-
|
|
910
|
-
|
|
910
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
911
|
+
yield this.setWorkingDirectory(pathSkyEye, port);
|
|
912
|
+
yield this.runScript(fileName, port);
|
|
913
|
+
}), 2000);
|
|
911
914
|
return "1";
|
|
912
915
|
}
|
|
913
916
|
catch (error) {
|
|
914
917
|
console.error("initSkyEyeAndRun error:", error);
|
|
915
918
|
if (this.childProcess) {
|
|
916
919
|
console.log('Terminating SkyEye child process...');
|
|
917
|
-
this.childProcess.kill();
|
|
920
|
+
this.childProcess.kill();
|
|
918
921
|
}
|
|
919
922
|
throw error;
|
|
920
923
|
}
|
|
921
924
|
});
|
|
922
925
|
}
|
|
923
926
|
startSkyEye(port, skyeyeDir) {
|
|
927
|
+
console.log('startSkyEye');
|
|
924
928
|
return new Promise((resolve, reject) => {
|
|
925
929
|
const childProcess = cp.exec(`${skyeyeDir} -q ${port}`, (err, stdout, stderr) => {
|
|
926
930
|
if (err) {
|
|
931
|
+
console.log('startSkyEye', err);
|
|
927
932
|
reject(err);
|
|
928
933
|
}
|
|
929
934
|
else {
|
|
@@ -944,6 +949,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
944
949
|
return new Promise((resolve, reject) => {
|
|
945
950
|
client.callSkyEye(Jr, (error, response) => {
|
|
946
951
|
if (error) {
|
|
952
|
+
console.log("chdir res error :", error);
|
|
947
953
|
reject(error);
|
|
948
954
|
}
|
|
949
955
|
else {
|
|
@@ -960,6 +966,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
960
966
|
return new Promise((resolve, reject) => {
|
|
961
967
|
client.callSkyEye(Jr, (error, response) => {
|
|
962
968
|
if (error) {
|
|
969
|
+
console.log("run_script error res:", error);
|
|
963
970
|
reject(error);
|
|
964
971
|
}
|
|
965
972
|
else {
|
package/dist/test.js
CHANGED
|
@@ -30,7 +30,8 @@ function test() {
|
|
|
30
30
|
const fileName = "c6713_demo.skyeye";
|
|
31
31
|
const skyeyeDir = "D:/install/skyeye/opt/skyeye/bin/skyeye.exe";
|
|
32
32
|
const port = "50051";
|
|
33
|
-
|
|
33
|
+
// await client.initSkyEyeAndRun(pathSkyEye,fileName,port,skyeyeDir);
|
|
34
|
+
yield client.initSkyEyeAndRun2(pathSkyEye, fileName, port, skyeyeDir);
|
|
34
35
|
// GrpcUtil.initAndRunExample();
|
|
35
36
|
// 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"}}}]}';
|
|
36
37
|
});
|
package/package.json
CHANGED
package/src/SkyEyeClient.ts
CHANGED
|
@@ -809,58 +809,64 @@ export class SkyEyeClient extends JSONTransmissionClient {
|
|
|
809
809
|
return this.port;
|
|
810
810
|
}
|
|
811
811
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
812
|
+
public initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
|
|
813
|
+
console.log('runExample');
|
|
814
|
+
cp.exec(skyeyeDir + " -q " + port + "\n", (err: any, stdout: any, stderr: any) => {
|
|
815
|
+
if(err){
|
|
816
|
+
console.log("initSkyEyeAndRun error:",err)
|
|
817
|
+
return
|
|
818
|
+
}
|
|
819
|
+
console.log('initSkyEyeAndRun stdout: ' ,stdout);
|
|
820
|
+
console.log('initSkyEyeAndRun stderr: ' , stderr);
|
|
821
|
+
});
|
|
822
|
+
console.log('wait');
|
|
823
|
+
setTimeout(() => {
|
|
824
|
+
client = new JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
825
|
+
console.log('client:' + client);
|
|
826
|
+
const Jr = new JSONRequest();
|
|
827
|
+
Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
828
|
+
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
829
|
+
console.log("chdir res:" + response + error);
|
|
830
|
+
|
|
831
|
+
Jr.setRequest("{\"request\": {\"name\": \"run_script\", \"args\": {\"filename\":\"" + fileName + "\"}}}");
|
|
832
|
+
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
833
|
+
console.log("run_script res:" + response + error);
|
|
834
|
+
// this.runCommand()
|
|
835
|
+
return "1";
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
}, 2000);
|
|
839
|
+
}
|
|
839
840
|
|
|
840
841
|
|
|
841
842
|
private childProcess: cp.ChildProcess | null = null;
|
|
842
843
|
|
|
843
|
-
public async
|
|
844
|
+
public async initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
|
|
844
845
|
try {
|
|
845
846
|
console.log('runExample');
|
|
846
847
|
this.childProcess = await this.startSkyEye(port, skyeyeDir);
|
|
847
|
-
|
|
848
|
-
|
|
848
|
+
setTimeout(async () => {
|
|
849
|
+
await this.setWorkingDirectory(pathSkyEye, port);
|
|
850
|
+
await this.runScript(fileName, port);
|
|
851
|
+
}, 2000);
|
|
852
|
+
|
|
849
853
|
return "1";
|
|
850
854
|
} catch (error) {
|
|
851
855
|
console.error("initSkyEyeAndRun error:", error);
|
|
852
856
|
if (this.childProcess) {
|
|
853
857
|
console.log('Terminating SkyEye child process...');
|
|
854
|
-
this.childProcess.kill();
|
|
858
|
+
this.childProcess.kill();
|
|
855
859
|
}
|
|
856
860
|
throw error;
|
|
857
861
|
}
|
|
858
862
|
}
|
|
859
863
|
|
|
860
864
|
private startSkyEye(port: string, skyeyeDir: string): Promise<cp.ChildProcess> {
|
|
865
|
+
console.log('startSkyEye');
|
|
861
866
|
return new Promise((resolve, reject) => {
|
|
862
867
|
const childProcess = cp.exec(`${skyeyeDir} -q ${port}`, (err: any, stdout: any, stderr: any) => {
|
|
863
868
|
if (err) {
|
|
869
|
+
console.log('startSkyEye',err);
|
|
864
870
|
reject(err);
|
|
865
871
|
} else {
|
|
866
872
|
console.log('initSkyEyeAndRun stdout: ', stdout);
|
|
@@ -885,6 +891,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
|
|
|
885
891
|
return new Promise((resolve, reject) => {
|
|
886
892
|
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
887
893
|
if (error) {
|
|
894
|
+
console.log("chdir res error :", error);
|
|
888
895
|
reject(error);
|
|
889
896
|
} else {
|
|
890
897
|
console.log("chdir res:", response);
|
|
@@ -902,6 +909,7 @@ export class SkyEyeClient extends JSONTransmissionClient {
|
|
|
902
909
|
return new Promise((resolve, reject) => {
|
|
903
910
|
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
904
911
|
if (error) {
|
|
912
|
+
console.log("run_script error res:", error);
|
|
905
913
|
reject(error);
|
|
906
914
|
} else {
|
|
907
915
|
console.log("run_script res:", response);
|
package/test.ts
CHANGED
|
@@ -28,7 +28,9 @@ async function test() {
|
|
|
28
28
|
const fileName = "c6713_demo.skyeye";
|
|
29
29
|
const skyeyeDir = "D:/install/skyeye/opt/skyeye/bin/skyeye.exe"
|
|
30
30
|
const port = "50051"
|
|
31
|
-
await client.initSkyEyeAndRun(pathSkyEye,fileName,port,skyeyeDir);
|
|
31
|
+
// await client.initSkyEyeAndRun(pathSkyEye,fileName,port,skyeyeDir);
|
|
32
|
+
|
|
33
|
+
await client.initSkyEyeAndRun2(pathSkyEye,fileName,port,skyeyeDir)
|
|
32
34
|
|
|
33
35
|
// GrpcUtil.initAndRunExample();
|
|
34
36
|
|