@@ -21,7 +21,10 @@ struct PublisherZMQ::Pimpl
21
21
};
22
22
23
23
24
- PublisherZMQ::PublisherZMQ (const BT::Tree& tree, int max_msg_per_second)
24
+ PublisherZMQ::PublisherZMQ (const BT::Tree& tree,
25
+ unsigned max_msg_per_second,
26
+ unsigned publisher_port,
27
+ unsigned server_port)
25
28
: StatusChangeLogger(tree.root_node)
26
29
, tree_(tree)
27
30
, min_time_between_msgs_(std::chrono::microseconds(1000 * 1000 ) / max_msg_per_second)
@@ -33,15 +36,23 @@ PublisherZMQ::PublisherZMQ(const BT::Tree& tree, int max_msg_per_second)
33
36
{
34
37
throw LogicError (" Only one instance of PublisherZMQ shall be created" );
35
38
}
39
+ if ( publisher_port == server_port)
40
+ {
41
+ throw LogicError (" The TCP ports of the publisher and the server must be different" );
42
+ }
36
43
37
44
flatbuffers::FlatBufferBuilder builder (1024 );
38
45
CreateFlatbuffersBehaviorTree (builder, tree);
39
46
40
47
tree_buffer_.resize (builder.GetSize ());
41
48
memcpy (tree_buffer_.data (), builder.GetBufferPointer (), builder.GetSize ());
42
49
43
- zmq_->publisher .bind (" tcp://*:1666" );
44
- zmq_->server .bind (" tcp://*:1667" );
50
+ char str[100 ];
51
+
52
+ sprintf (str, " tcp://*:%d" , publisher_port);
53
+ zmq_->publisher .bind (str);
54
+ sprintf (str, " tcp://*:%d" , server_port);
55
+ zmq_->server .bind (str);
45
56
46
57
int timeout_ms = 100 ;
47
58
zmq_->server .setsockopt (ZMQ_RCVTIMEO, &timeout_ms, sizeof (int ));
0 commit comments