pubo-node 1.0.156 → 1.0.158
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/pubo-node.js +1 -1
- package/es/child-process/index.js +129 -362
- package/es/file-system/index.d.ts +0 -4
- package/es/file-system/index.js +25 -32
- package/es/ftp-client/index.d.ts +0 -2
- package/es/ftp-client/index.js +120 -245
- package/es/grpc/index.d.ts +0 -1
- package/es/grpc/index.js +92 -158
- package/es/index.d.ts +1 -1
- package/es/index.js +3 -3
- package/es/ros/topic.js +70 -113
- package/es/storage/json.js +147 -296
- package/es/utils/index.js +13 -13
- package/es/utils/network.js +30 -53
- package/lib/child-process/index.js +7 -7
- package/lib/file-system/index.d.ts +0 -4
- package/lib/ftp-client/index.d.ts +0 -2
- package/lib/grpc/index.d.ts +0 -1
- package/lib/grpc/index.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/utils/network.js +2 -3
- package/package.json +3 -3
package/es/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { JsonStorage } from './storage/json';
|
|
2
2
|
export { FtpClient, FtpClientPool } from './ftp-client';
|
|
3
3
|
export { createRpcClient, GrpcList } from './grpc';
|
|
4
|
-
export {
|
|
5
|
-
export { SIGKILL, isProcessDied, getProcessName, getProcessTree, getProcessByPpid, getProcessCpuUseByPid, getProcessCommandByPid, heartbeat } from './child-process';
|
|
4
|
+
export { SIGKILL, isProcessDied, getProcessName, getProcessTree, getProcessByPpid, getProcessCpuUseByPid, getProcessCommandByPid, heartbeat, } from './child-process';
|
|
6
5
|
export { isPortAvailable } from './utils';
|
|
7
6
|
export { getWifiName, getNetworks } from './utils/network';
|
|
8
|
-
export { RosTopicManager, RosTopic } from './ros/topic';
|
|
7
|
+
export { RosTopicManager, RosTopic } from './ros/topic';
|
|
8
|
+
export { PuboFileSystem } from './file-system';
|
package/es/ros/topic.js
CHANGED
|
@@ -2,122 +2,79 @@ import { exec, spawn } from 'child_process';
|
|
|
2
2
|
import { Emitter, WatchDog, StringSplit, sleep } from 'pubo-utils';
|
|
3
3
|
import * as YAML from 'yaml';
|
|
4
4
|
import { SIGKILL } from '../child-process';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return then ? value.then(then) : value;
|
|
19
|
-
}
|
|
20
|
-
export var RosTopic = /*#__PURE__*/function () {
|
|
21
|
-
function RosTopic(topic, messageType) {
|
|
22
|
-
this.topic = void 0;
|
|
23
|
-
this.messageType = void 0;
|
|
24
|
-
this.emitter = new Emitter();
|
|
25
|
-
this.subscribed = false;
|
|
26
|
-
this.dog = new WatchDog({
|
|
27
|
-
limit: 10,
|
|
28
|
-
onTimeout: this.onTimeout.bind(this)
|
|
29
|
-
});
|
|
30
|
-
this.strSplit = new StringSplit('---');
|
|
31
|
-
this.subscribeChildProcess = void 0;
|
|
32
|
-
this.topic = topic;
|
|
33
|
-
this.messageType = messageType;
|
|
34
|
-
this.subscribed = false;
|
|
35
|
-
this.emitter = new Emitter();
|
|
36
|
-
}
|
|
37
|
-
var _proto = RosTopic.prototype;
|
|
38
|
-
_proto.onTimeout = function onTimeout() {
|
|
39
|
-
try {
|
|
40
|
-
var _this = this;
|
|
41
|
-
if (!_this.subscribed) {
|
|
42
|
-
return _await();
|
|
43
|
-
}
|
|
44
|
-
return _await(_this.unsubscribe(), function () {
|
|
45
|
-
return _await(sleep(1000), function () {
|
|
46
|
-
return _awaitIgnored(_this.subscribe());
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
} catch (e) {
|
|
50
|
-
return Promise.reject(e);
|
|
5
|
+
export class RosTopic {
|
|
6
|
+
topic;
|
|
7
|
+
messageType;
|
|
8
|
+
emitter = new Emitter();
|
|
9
|
+
subscribed = false;
|
|
10
|
+
dog = new WatchDog({ limit: 10, onTimeout: this.onTimeout.bind(this) });
|
|
11
|
+
strSplit = new StringSplit('---');
|
|
12
|
+
subscribeChildProcess;
|
|
13
|
+
constructor(topic, messageType) {
|
|
14
|
+
this.topic = topic;
|
|
15
|
+
this.messageType = messageType;
|
|
16
|
+
this.subscribed = false;
|
|
17
|
+
this.emitter = new Emitter();
|
|
51
18
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
19
|
+
async onTimeout() {
|
|
20
|
+
if (!this.subscribed) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await this.unsubscribe();
|
|
24
|
+
await sleep(1000);
|
|
25
|
+
await this.subscribe();
|
|
57
26
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return _await();
|
|
67
|
-
}
|
|
68
|
-
_this2.subscribed = true;
|
|
69
|
-
_this2.dog.init();
|
|
70
|
-
_this2.subscribeChildProcess = spawn("rostopic", ['echo', _this2.topic]);
|
|
71
|
-
_this2.subscribeChildProcess.stdout.on('data', _this2.onData.bind(_this2));
|
|
72
|
-
_this2.subscribeChildProcess.stderr.on('data', function (buf) {
|
|
73
|
-
return console.log(buf.toString());
|
|
74
|
-
});
|
|
75
|
-
return _await();
|
|
76
|
-
} catch (e) {
|
|
77
|
-
return Promise.reject(e);
|
|
27
|
+
onData(data) {
|
|
28
|
+
const tmp = this.strSplit.split(data.toString()).slice(-1)[0];
|
|
29
|
+
if (!tmp) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.dog.feed();
|
|
33
|
+
const res = YAML.parse(tmp);
|
|
34
|
+
this.emitter.emit('message', res);
|
|
78
35
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return _await(SIGKILL(_this3.subscribeChildProcess.pid), function () {
|
|
89
|
-
_this3.subscribeChildProcess = null;
|
|
90
|
-
});
|
|
91
|
-
} catch (e) {
|
|
92
|
-
return Promise.reject(e);
|
|
36
|
+
async subscribe() {
|
|
37
|
+
if (this.subscribeChildProcess) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.subscribed = true;
|
|
41
|
+
this.dog.init();
|
|
42
|
+
this.subscribeChildProcess = spawn(`rostopic`, ['echo', this.topic]);
|
|
43
|
+
this.subscribeChildProcess.stdout.on('data', this.onData.bind(this));
|
|
44
|
+
this.subscribeChildProcess.stderr.on('data', (buf) => console.log(buf.toString()));
|
|
93
45
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var data = YAML.stringify(payload);
|
|
98
|
-
return new Promise(function (resolve, reject) {
|
|
99
|
-
exec("rostopic pub -1 " + _this4.topic + " " + _this4.messageType + " \"" + data + "\"", function (err, stdout) {
|
|
100
|
-
if (err) {
|
|
101
|
-
reject(err);
|
|
102
|
-
} else {
|
|
103
|
-
resolve(stdout);
|
|
46
|
+
async unsubscribe() {
|
|
47
|
+
if (!this.subscribeChildProcess) {
|
|
48
|
+
return;
|
|
104
49
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
50
|
+
this.dog.stop();
|
|
51
|
+
this.subscribed = false;
|
|
52
|
+
await SIGKILL(this.subscribeChildProcess.pid);
|
|
53
|
+
this.subscribeChildProcess = null;
|
|
54
|
+
}
|
|
55
|
+
publish(payload) {
|
|
56
|
+
const data = YAML.stringify(payload);
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
exec(`rostopic pub -1 ${this.topic} ${this.messageType} "${data}"`, (err, stdout) => {
|
|
59
|
+
if (err) {
|
|
60
|
+
reject(err);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
resolve(stdout);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
118
67
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
68
|
+
}
|
|
69
|
+
export const RosTopicManager = {
|
|
70
|
+
cache: [],
|
|
71
|
+
getTopic: function (topic, messageType) {
|
|
72
|
+
const tmp = this.cache.find((item) => item.topic === topic);
|
|
73
|
+
if (tmp) {
|
|
74
|
+
return tmp;
|
|
75
|
+
}
|
|
76
|
+
const instance = new RosTopic(topic, messageType);
|
|
77
|
+
this.cache.push(instance);
|
|
78
|
+
return instance;
|
|
79
|
+
},
|
|
80
|
+
};
|