Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cdfe773

Browse files
committed
Fix issue BehaviorTree#140
1 parent 8b32ed7 commit cdfe773

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/behaviortree_cpp_v3/loggers/bt_zmq_publisher.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class PublisherZMQ : public StatusChangeLogger
1313
static std::atomic<bool> ref_count;
1414

1515
public:
16-
PublisherZMQ(const BT::Tree& tree, int max_msg_per_second = 25);
16+
PublisherZMQ(const BT::Tree& tree,
17+
unsigned max_msg_per_second = 25,
18+
unsigned publisher_port = 1666,
19+
unsigned server_port = 1667);
1720

1821
virtual ~PublisherZMQ();
1922

src/loggers/bt_zmq_publisher.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ struct PublisherZMQ::Pimpl
2121
};
2222

2323

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)
2528
: StatusChangeLogger(tree.root_node)
2629
, tree_(tree)
2730
, 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)
3336
{
3437
throw LogicError("Only one instance of PublisherZMQ shall be created");
3538
}
39+
if( publisher_port == server_port)
40+
{
41+
throw LogicError("The TCP ports of the publisher and the server must be different");
42+
}
3643

3744
flatbuffers::FlatBufferBuilder builder(1024);
3845
CreateFlatbuffersBehaviorTree(builder, tree);
3946

4047
tree_buffer_.resize(builder.GetSize());
4148
memcpy(tree_buffer_.data(), builder.GetBufferPointer(), builder.GetSize());
4249

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);
4556

4657
int timeout_ms = 100;
4758
zmq_->server.setsockopt(ZMQ_RCVTIMEO, &timeout_ms, sizeof(int));

0 commit comments

Comments
 (0)