Skip to content

Commit 44562cb

Browse files
author
Minggang Wang
authored
Merge pull request #213 from qiuzhong/api-change
Consistent message String type naming and timer for publisher
2 parents 239acea + 6d84d8a commit 44562cb

11 files changed

+114
-110
lines changed

test/client_setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const rclnodejs = require('../index.js');
1818

1919
rclnodejs.init().then(function() {
20-
var node = rclnodejs.createNode('service');
20+
var node = rclnodejs.createNode('client');
2121
const AddTwoInts = 'example_interfaces/srv/AddTwoInts';
2222
var client = node.createClient(AddTwoInts, 'add_two_ints');
2323
const request = {

test/publisher_msg.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ rclnodejs.init().then(() => {
2626
msg.data = rclValue;
2727

2828
var publisher = node.createPublisher(msgType, rclType + '_channel');
29-
var timer = setInterval(() => {
29+
var timer = node.createTimer(100, () => {
3030
publisher.publish(msg);
31-
}, 100);
31+
});
3232

3333
rclnodejs.spin(node);
3434
process.on('SIGINT', (m) => {
35-
clearInterval(timer);
35+
timer.cancel();
3636
node.destroy();
3737
rclnodejs.shutdown();
3838
process.exit(0);

test/publisher_msg_colorrgba.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ rclnodejs.init().then(() => {
2727
};
2828

2929
var publisher = node.createPublisher(ColorRGBA, 'ColorRGBA_channel');
30-
var timer = setInterval(() => {
30+
var timer = node.createTimer(100, () => {
3131
publisher.publish(msg);
32-
}, 100);
32+
});
3333

3434
rclnodejs.spin(node);
3535
process.on('SIGINT', (m) => {
36-
clearInterval(timer);
36+
timer.cancel();
3737
node.destroy();
3838
rclnodejs.shutdown();
3939
process.exit(0);

test/publisher_msg_header.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ rclnodejs.init().then(() => {
3131
};
3232

3333
var publisher = node.createPublisher(Header, 'Header_channel');
34-
var timer = setInterval(() => {
34+
var timer = node.createTimer(100, () => {
3535
publisher.publish(header);
36-
}, 100);
36+
});
3737

3838
rclnodejs.spin(node);
3939
process.on('SIGINT', (m) => {
40-
clearInterval(timer);
40+
timer.cancel();
4141
node.destroy();
4242
rclnodejs.shutdown();
4343
process.exit(0);

test/publisher_msg_jointstate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ rclnodejs.init().then(() => {
3737
};
3838

3939
var publisher = node.createPublisher(JointState, 'JointState_channel');
40-
var timer = setInterval(() => {
40+
var timer = node.createTimer(100, () => {
4141
publisher.publish(state);
42-
}, 100);
42+
});
4343

4444
rclnodejs.spin(node);
4545
process.on('SIGINT', (m) => {
46-
clearInterval(timer);
46+
timer.cancel();
4747
node.destroy();
4848
rclnodejs.shutdown();
4949
process.exit(0);

test/test-cross-lang.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ describe('Cross-language interaction', function() {
3434
describe('Node.js Subcription', function() {
3535
it('Node.js subscription should receive msg from C++ publisher', (done) => {
3636
var node = rclnodejs.createNode('cpp_pub_js_sub');
37-
const rclString = 'std_msgs/msg/String';
37+
const RclString = 'std_msgs/msg/String';
3838
var destroy = false;
3939
var cppTalkPath = path.join(process.env['AMENT_PREFIX_PATH'], 'lib', 'demo_nodes_cpp', 'talker');
4040
var cppTalker = childProcess.spawn(cppTalkPath, ['-t', 'cpp_js_chatter']);
41-
var subscription = node.createSubscription(rclString, 'cpp_js_chatter', (msg) => {
41+
var subscription = node.createSubscription(RclString, 'cpp_js_chatter', (msg) => {
4242
assert.ok(/Hello World:/.test(msg.data));
4343
if (!destroy) {
4444
node.destroy();
@@ -52,10 +52,10 @@ describe('Cross-language interaction', function() {
5252

5353
it('Node.js subscription should receive msg from Python publisher', (done) => {
5454
var node = rclnodejs.createNode('cpp_pub_py_sub');
55-
const rclString = 'std_msgs/msg/String';
55+
const RclString = 'std_msgs/msg/String';
5656
var destroy = false;
5757
var pyTalker = utils.launchPythonProcess([`${__dirname}/py/talker.py`]);
58-
var subscription = node.createSubscription(rclString, 'py_js_chatter', (msg) => {
58+
var subscription = node.createSubscription(RclString, 'py_js_chatter', (msg) => {
5959
assert.ok(/Hello World/.test(msg.data));
6060
if (!destroy) {
6161
node.destroy();
@@ -71,22 +71,22 @@ describe('Cross-language interaction', function() {
7171
describe('Node.js publisher', function() {
7272
it('Cpp subscription should receive msg from Node.js publisher', (done) => {
7373
var node = rclnodejs.createNode('js_pub_cpp_sub');
74-
const rclString = 'std_msgs/msg/String';
74+
const RclString = 'std_msgs/msg/String';
7575
var destroy = false;
7676

7777
let text = 'Greeting from Node.js publisher';
7878
let cppListenerPath = path.join(process.env['AMENT_PREFIX_PATH'], 'lib', 'demo_nodes_cpp', 'listener');
7979
var cppListener = childProcess.spawn(cppListenerPath, ['-t', 'js_cpp_chatter']);
80-
var publisher = node.createPublisher(rclString, 'js_cpp_chatter');
80+
var publisher = node.createPublisher(RclString, 'js_cpp_chatter');
8181
const msg = text;
82-
var timer = setInterval(() => {
82+
var timer = node.createTimer(100, () => {
8383
publisher.publish(msg);
84-
}, 100);
84+
});
8585

8686
cppListener.stdout.on('data', (data) => {
8787
if (!destroy) {
8888
assert.ok(new RegExp(text).test(data.toString()));
89-
clearInterval(timer);
89+
timer.cancel();
9090
node.destroy();
9191
cppListener.kill('SIGINT');
9292
destroy = true;
@@ -98,21 +98,21 @@ describe('Cross-language interaction', function() {
9898

9999
it('Python subscription should receive msg from Node.js publisher', function(done) {
100100
var node = rclnodejs.createNode('js_pub_py_sub');
101-
const rclString = 'std_msgs/msg/String';
101+
const RclString = 'std_msgs/msg/String';
102102
var destroy = false;
103103

104104
let text = 'Greeting from Node.js publisher to Python subscription';
105105
var pyListener = utils.launchPythonProcess([`${__dirname}/py/listener.py`]);
106-
var publisher = node.createPublisher(rclString, 'js_py_chatter');
106+
var publisher = node.createPublisher(RclString, 'js_py_chatter');
107107
var msg = text;
108108

109-
var timer = setInterval(() => {
109+
var timer = node.createTimer(100, () => {
110110
publisher.publish(msg);
111-
}, 100);
111+
});
112112
pyListener.stdout.on('data', (data) => {
113113
if (!destroy) {
114114
assert.ok(new RegExp(text).test(data.toString()));
115-
clearInterval(timer);
115+
timer.cancel();
116116
node.destroy();
117117
pyListener.kill('SIGINT');
118118
destroy = true;
@@ -133,18 +133,18 @@ describe('Cross-language interaction', function() {
133133
var client = node.createClient(AddTwoInts, 'js_py_add_two_ints');
134134
const request = {a: 1, b: 2};
135135

136-
var timer = setInterval(() => {
136+
var timer = node.createTimer(100, () => {
137137
client.sendRequest(request, (response) => {
138138
if (!destroy) {
139139
assert.deepStrictEqual(response.sum, 3);
140-
clearInterval(timer);
140+
timer.cancel();
141141
node.destroy();
142142
pyService.kill('SIGINT');
143143
destroy = true;
144144
done();
145145
}
146146
});
147-
}, 100);
147+
});
148148

149149
rclnodejs.spin(node);
150150
});

test/test-destruction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ describe('Node destroy testing', function() {
8181
var pub2 = node.createPublisher(float32, 'pub2_topic');
8282
assert.deepStrictEqual(2, node._publishers.length);
8383

84-
var rclString = 'std_msgs/msg/String';
85-
var sub1 = node.createSubscription(rclString, 'sub1_topic', function(msg) {
84+
var RclString = 'std_msgs/msg/String';
85+
var sub1 = node.createSubscription(RclString, 'sub1_topic', function(msg) {
8686
console.log(`Received ${msg}`);
8787
});
8888
assert.deepStrictEqual(1, node._subscriptions.length);

test/test-existance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ describe('rclnodejs class existance testing', function() {
146146
});
147147

148148
describe('Publisher class', function() {
149-
var node, rclString, publisher;
149+
var node, RclString, publisher;
150150

151151
before(function() {
152152
node = rclnodejs.createNode('Publisher');
153-
rclString = 'std_msgs/msg/String';
154-
publisher = node.createPublisher(rclString, 'chatter');
153+
RclString = 'std_msgs/msg/String';
154+
publisher = node.createPublisher(RclString, 'chatter');
155155
});
156156

157157
after(function() {

0 commit comments

Comments
 (0)