skyeye-sdk-js 1.2.0 → 1.2.2
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 +5 -0
- package/dist/src/SkyEyeClient.js +83 -3
- package/dist/test.js +2 -1
- package/package.json +1 -1
- package/src/SkyEyeClient.ts +39 -31
- package/test.ts +3 -1
|
@@ -70,4 +70,9 @@ export declare class SkyEyeClient extends JSONTransmissionClient {
|
|
|
70
70
|
getHost(): string;
|
|
71
71
|
getPort(): string;
|
|
72
72
|
initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): void;
|
|
73
|
+
private childProcess;
|
|
74
|
+
initSkyEyeAndRun2(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string): Promise<string>;
|
|
75
|
+
private startSkyEye;
|
|
76
|
+
private setWorkingDirectory;
|
|
77
|
+
private runScript;
|
|
73
78
|
}
|
package/dist/src/SkyEyeClient.js
CHANGED
|
@@ -61,6 +61,7 @@ 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
|
+
this.childProcess = null;
|
|
64
65
|
this.host = host;
|
|
65
66
|
this.port = port;
|
|
66
67
|
}
|
|
@@ -877,12 +878,17 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
877
878
|
initSkyEyeAndRun(pathSkyEye, fileName, port, skyeyeDir) {
|
|
878
879
|
console.log('runExample');
|
|
879
880
|
cp.exec(skyeyeDir + " -q " + port + "\n", (err, stdout, stderr) => {
|
|
880
|
-
|
|
881
|
-
|
|
881
|
+
if (err) {
|
|
882
|
+
console.log("initSkyEyeAndRun error:", err);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
console.log('initSkyEyeAndRun stdout: ', stdout);
|
|
886
|
+
console.log('initSkyEyeAndRun stderr: ', stderr);
|
|
882
887
|
});
|
|
888
|
+
console.log('wait');
|
|
883
889
|
setTimeout(() => {
|
|
884
890
|
client = new skyeye_rpc_grpc_pb_1.JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
885
|
-
|
|
891
|
+
console.log('client:' + client);
|
|
886
892
|
const Jr = new skyeye_rpc_pb_1.JSONRequest();
|
|
887
893
|
Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
888
894
|
client.callSkyEye(Jr, (error, response) => {
|
|
@@ -896,5 +902,79 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
896
902
|
});
|
|
897
903
|
}, 2000);
|
|
898
904
|
}
|
|
905
|
+
initSkyEyeAndRun2(pathSkyEye, fileName, port, skyeyeDir) {
|
|
906
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
907
|
+
try {
|
|
908
|
+
console.log('runExample');
|
|
909
|
+
this.childProcess = yield this.startSkyEye(port, skyeyeDir);
|
|
910
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
911
|
+
yield this.setWorkingDirectory(pathSkyEye, port);
|
|
912
|
+
yield this.runScript(fileName, port);
|
|
913
|
+
}), 1000);
|
|
914
|
+
return "1";
|
|
915
|
+
}
|
|
916
|
+
catch (error) {
|
|
917
|
+
console.error("initSkyEyeAndRun error:", error);
|
|
918
|
+
if (this.childProcess) {
|
|
919
|
+
console.log('Terminating SkyEye child process...');
|
|
920
|
+
this.childProcess.kill();
|
|
921
|
+
}
|
|
922
|
+
throw error;
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
startSkyEye(port, skyeyeDir) {
|
|
927
|
+
console.log('startSkyEye');
|
|
928
|
+
return new Promise((resolve, reject) => {
|
|
929
|
+
const childProcess = cp.exec(`${skyeyeDir} -q ${port}`, (err, stdout, stderr) => {
|
|
930
|
+
if (err) {
|
|
931
|
+
console.log('startSkyEye', err);
|
|
932
|
+
reject(err);
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
console.log('initSkyEyeAndRun stdout: ', stdout);
|
|
936
|
+
console.log('initSkyEyeAndRun stderr: ', stderr);
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
childProcess.on('exit', (code, signal) => {
|
|
940
|
+
console.log('SkyEye child process exited with code', code, 'and signal', signal);
|
|
941
|
+
});
|
|
942
|
+
resolve(childProcess);
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
setWorkingDirectory(pathSkyEye, port) {
|
|
946
|
+
const client = new skyeye_rpc_grpc_pb_1.JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
|
|
947
|
+
const Jr = new skyeye_rpc_pb_1.JSONRequest();
|
|
948
|
+
Jr.setRequest(`{"request": {"name": "chdir", "args": {"path":"${pathSkyEye}"}}}`);
|
|
949
|
+
return new Promise((resolve, reject) => {
|
|
950
|
+
client.callSkyEye(Jr, (error, response) => {
|
|
951
|
+
if (error) {
|
|
952
|
+
console.log("chdir res error :", error);
|
|
953
|
+
reject(error);
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
console.log("chdir res:", response);
|
|
957
|
+
resolve();
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
runScript(fileName, port) {
|
|
963
|
+
const client = new skyeye_rpc_grpc_pb_1.JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
|
|
964
|
+
const Jr = new skyeye_rpc_pb_1.JSONRequest();
|
|
965
|
+
Jr.setRequest(`{"request": {"name": "run_script", "args": {"filename":"${fileName}"}}}`);
|
|
966
|
+
return new Promise((resolve, reject) => {
|
|
967
|
+
client.callSkyEye(Jr, (error, response) => {
|
|
968
|
+
if (error) {
|
|
969
|
+
console.log("run_script error res:", error);
|
|
970
|
+
reject(error);
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
console.log("run_script res:", response);
|
|
974
|
+
resolve();
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
}
|
|
899
979
|
}
|
|
900
980
|
exports.SkyEyeClient = SkyEyeClient;
|
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
|
+
}, 1000);
|
|
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
|
|