skyeye-sdk-js 1.1.8 → 1.2.0
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.js +6 -6
- package/dist/test.js +1 -2
- package/package.json +1 -1
- package/src/SkyEyeClient.ts +96 -31
- package/test.ts +1 -1
package/dist/src/SkyEyeClient.js
CHANGED
|
@@ -877,10 +877,12 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
877
877
|
initSkyEyeAndRun(pathSkyEye, fileName, port, skyeyeDir) {
|
|
878
878
|
console.log('runExample');
|
|
879
879
|
cp.exec(skyeyeDir + " -q " + port + "\n", (err, stdout, stderr) => {
|
|
880
|
-
console.log('stdout: ' + stdout);
|
|
881
|
-
console.log('stderr: ' + stderr);
|
|
880
|
+
// console.log('stdout: ' + stdout);
|
|
881
|
+
// console.log('stderr: ' + stderr);
|
|
882
|
+
});
|
|
883
|
+
setTimeout(() => {
|
|
882
884
|
client = new skyeye_rpc_grpc_pb_1.JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
883
|
-
console.log('client:' + client);
|
|
885
|
+
// console.log('client:' + client);
|
|
884
886
|
const Jr = new skyeye_rpc_pb_1.JSONRequest();
|
|
885
887
|
Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
886
888
|
client.callSkyEye(Jr, (error, response) => {
|
|
@@ -892,9 +894,7 @@ class SkyEyeClient extends skyeye_rpc_grpc_pb_1.JSONTransmissionClient {
|
|
|
892
894
|
return "1";
|
|
893
895
|
});
|
|
894
896
|
});
|
|
895
|
-
});
|
|
896
|
-
// setTimeout(() => {
|
|
897
|
-
// }, 2000);
|
|
897
|
+
}, 2000);
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
900
|
exports.SkyEyeClient = SkyEyeClient;
|
package/dist/test.js
CHANGED
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const GrpcUtil_1 = require("./src/GrpcUtil");
|
|
13
12
|
const { SkyEyeClientFactory } = require('./src/SkyEyeClientFactory');
|
|
14
13
|
const { SkyEyeClient } = require('./src/SkyEyeClient');
|
|
15
14
|
function test() {
|
|
@@ -32,7 +31,7 @@ function test() {
|
|
|
32
31
|
const skyeyeDir = "D:/install/skyeye/opt/skyeye/bin/skyeye.exe";
|
|
33
32
|
const port = "50051";
|
|
34
33
|
yield client.initSkyEyeAndRun(pathSkyEye, fileName, port, skyeyeDir);
|
|
35
|
-
|
|
34
|
+
// GrpcUtil.initAndRunExample();
|
|
36
35
|
// 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
36
|
});
|
|
38
37
|
}
|
package/package.json
CHANGED
package/src/SkyEyeClient.ts
CHANGED
|
@@ -809,40 +809,105 @@ export class SkyEyeClient extends JSONTransmissionClient {
|
|
|
809
809
|
return this.port;
|
|
810
810
|
}
|
|
811
811
|
|
|
812
|
-
public initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
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
|
+
// setTimeout(() => {
|
|
823
|
+
// client = new JSONTransmissionClient('127.0.0.1:' + port, grpc.credentials.createInsecure());
|
|
824
|
+
// // console.log('client:' + client);
|
|
825
|
+
// const Jr = new JSONRequest();
|
|
826
|
+
// Jr.setRequest("{\"request\": {\"name\": \"chdir\", \"args\": {\"path\":\"" + pathSkyEye + "\"}}}");
|
|
827
|
+
// client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
828
|
+
// console.log("chdir res:" + response + error);
|
|
829
|
+
|
|
830
|
+
// Jr.setRequest("{\"request\": {\"name\": \"run_script\", \"args\": {\"filename\":\"" + fileName + "\"}}}");
|
|
831
|
+
// client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
832
|
+
// console.log("run_script res:" + response + error);
|
|
833
|
+
// // this.runCommand()
|
|
834
|
+
// return "1";
|
|
835
|
+
// });
|
|
836
|
+
// });
|
|
837
|
+
// }, 2000);
|
|
838
|
+
// }
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
private childProcess: cp.ChildProcess | null = null;
|
|
842
|
+
|
|
843
|
+
public async initSkyEyeAndRun(pathSkyEye: string, fileName: string, port: string, skyeyeDir: string) {
|
|
844
|
+
try {
|
|
845
|
+
console.log('runExample');
|
|
846
|
+
this.childProcess = await this.startSkyEye(port, skyeyeDir);
|
|
847
|
+
await this.setWorkingDirectory(pathSkyEye, port);
|
|
848
|
+
await this.runScript(fileName, port);
|
|
849
|
+
return "1";
|
|
850
|
+
} catch (error) {
|
|
851
|
+
console.error("initSkyEyeAndRun error:", error);
|
|
852
|
+
if (this.childProcess) {
|
|
853
|
+
console.log('Terminating SkyEye child process...');
|
|
854
|
+
this.childProcess.kill(); // 手动终止子进程
|
|
855
|
+
}
|
|
856
|
+
throw error;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
824
859
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}
|
|
860
|
+
private startSkyEye(port: string, skyeyeDir: string): Promise<cp.ChildProcess> {
|
|
861
|
+
return new Promise((resolve, reject) => {
|
|
862
|
+
const childProcess = cp.exec(`${skyeyeDir} -q ${port}`, (err: any, stdout: any, stderr: any) => {
|
|
863
|
+
if (err) {
|
|
864
|
+
reject(err);
|
|
865
|
+
} else {
|
|
866
|
+
console.log('initSkyEyeAndRun stdout: ', stdout);
|
|
867
|
+
console.log('initSkyEyeAndRun stderr: ', stderr);
|
|
868
|
+
}
|
|
831
869
|
});
|
|
832
870
|
|
|
871
|
+
childProcess.on('exit', (code, signal) => {
|
|
872
|
+
console.log('SkyEye child process exited with code', code, 'and signal', signal);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
resolve(childProcess);
|
|
833
876
|
});
|
|
834
|
-
// setTimeout(() => {
|
|
835
|
-
|
|
836
|
-
// }, 2000);
|
|
837
877
|
}
|
|
838
878
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
879
|
+
|
|
880
|
+
private setWorkingDirectory(pathSkyEye: string, port: string): Promise<void> {
|
|
881
|
+
const client = new JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
|
|
882
|
+
const Jr = new JSONRequest();
|
|
883
|
+
Jr.setRequest(`{"request": {"name": "chdir", "args": {"path":"${pathSkyEye}"}}}`);
|
|
884
|
+
|
|
885
|
+
return new Promise((resolve, reject) => {
|
|
886
|
+
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
887
|
+
if (error) {
|
|
888
|
+
reject(error);
|
|
889
|
+
} else {
|
|
890
|
+
console.log("chdir res:", response);
|
|
891
|
+
resolve();
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
private runScript(fileName: string, port: string): Promise<void> {
|
|
898
|
+
const client = new JSONTransmissionClient(`127.0.0.1:${port}`, grpc.credentials.createInsecure());
|
|
899
|
+
const Jr = new JSONRequest();
|
|
900
|
+
Jr.setRequest(`{"request": {"name": "run_script", "args": {"filename":"${fileName}"}}}`);
|
|
901
|
+
|
|
902
|
+
return new Promise((resolve, reject) => {
|
|
903
|
+
client.callSkyEye(Jr, (error: ServiceError | null, response: JSONResponse) => {
|
|
904
|
+
if (error) {
|
|
905
|
+
reject(error);
|
|
906
|
+
} else {
|
|
907
|
+
console.log("run_script res:", response);
|
|
908
|
+
resolve();
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
}
|
package/test.ts
CHANGED
|
@@ -30,7 +30,7 @@ async function test() {
|
|
|
30
30
|
const port = "50051"
|
|
31
31
|
await client.initSkyEyeAndRun(pathSkyEye,fileName,port,skyeyeDir);
|
|
32
32
|
|
|
33
|
-
GrpcUtil.initAndRunExample();
|
|
33
|
+
// GrpcUtil.initAndRunExample();
|
|
34
34
|
|
|
35
35
|
// 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
36
|
|