Skip to content

Commit 4aeb3c9

Browse files
author
Francesco Di Franco
authored
UDP bugfix (#181)
- clamp UDPROS msgID to uint8 - host sent to the publisher during udp handshake was wrong
1 parent 6bb0845 commit 4aeb3c9

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/lib/RosNode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,17 +596,17 @@ class RosNode extends EventEmitter {
596596
let dgramSize = params[2][0][4];
597597
let resp = [
598598
1,
599-
'',
599+
' ', // this string must not be empty, otherwise the subscriber will not understand the response
600600
[
601601
'UDPROS',
602-
NetworkUtils.getHost(), //maybe wrong
603-
port,
602+
NetworkUtils.getHost(),
603+
this._udprosPort,
604604
++this._connections, //connection Id
605605
dgramSize,
606606
UdprosUtils.createPubHeader(this.getNodeName(), typeClass.md5sum(), typeClass.messageDefinition(), topic, header.type)
607607
]
608608
]
609-
pub.addUdpSubscriber(resp[2])
609+
pub.addUdpSubscriber(resp[2],host,port)
610610
callback(null, resp)
611611
}
612612
}

src/lib/impl/PublisherImpl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class PublisherImpl extends EventEmitter {
241241
if (this.getLatching()) {
242242
this._lastSentMsg = serializedMsg;
243243
}
244-
msgCount++;
244+
msgCount = msgCount > 254 ? 0 : ++msgCount;
245245
});
246246
}
247247
catch (err) {
@@ -362,13 +362,13 @@ class PublisherImpl extends EventEmitter {
362362
this.emit('connection', header, socket.name);
363363
}
364364

365-
addUdpSubscriber(resp){
365+
addUdpSubscriber(resp,host,port){
366366
if(Object.keys(this._udpSubClients).length === 0){
367367
this.udpSocket = Udp.createSocket('udp4');
368368
}
369369
this._udpSubClients[resp[3]] = {
370-
port: resp[2],
371-
host: resp[1],
370+
port: port,
371+
host: host,
372372
dgramSize: resp[4],
373373
connId: resp[3]
374374
}

src/lib/impl/SubscriberImpl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class SubscriberImpl extends EventEmitter {
282282
}
283283
if(this._udp){
284284
let header = UdprosUtils.createSubHeader(this._nodeHandle.getNodeName(), this._messageHandler.md5sum(), this.getTopic(), this.getType())
285-
protocols.push(['UDPROS', header, info.host, this._port, this._dgramSize || 1500])
285+
protocols.push(['UDPROS', header, NetworkUtils.getHost(), this._port, this._dgramSize || 1500])
286286
}
287287
if(this._udpFirst){
288288
protocols.reverse();

src/utils/udpros_utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ let UdprosUtils = {
8181
* Creates a UDPROS connection header for a publisher to send.
8282
* @param callerId {string} node publishing this topic
8383
* @param md5sum {string} md5 of the message
84-
* @param type {string} type of the message
8584
* @param messageDefinition {string} trimmed message definition.
85+
* @param topic {string} topic name
86+
* @param type {string} type of the message
8687
* rosbag relies on this being sent although it is not mentioned in the spec.
8788
*/
88-
createPubHeader(callerId, md5sum, type, messageDefinition) {
89+
createPubHeader(callerId, md5sum, messageDefinition, topic, type) {
8990
const fields = [
9091
callerIdPrefix + callerId,
9192
md5Prefix + md5sum,
93+
messageDefinitionPrefix + messageDefinition,
94+
topicPrefix + topic,
9295
typePrefix + type,
93-
messageDefinitionPrefix + messageDefinition
9496
];
9597

9698

@@ -267,7 +269,6 @@ let UdprosUtils = {
267269
let opCode = buff.readUInt8(4)
268270
let msgId = buff.readUInt8(5)
269271
let blkN = buff.readUInt16LE(6)
270-
271272
return {
272273
connectionId,
273274
opCode,

0 commit comments

Comments
 (0)