udp_bc_broker.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include <ros/ros.h>
25 
27 
29 
30 namespace udp_bc_broker{
31 
32  UDPBCBroker::UDPBCBroker()
33  {
35  int port = 12321;
36  sender_.reset(new UdpSender(port));
37  recver_.reset(new UdpRecver(port));
38  }
39 
40  void UDPBCBroker::init(std::string name, const micros_swarm::PacketParser& parser)
41  {
42  name_ = name;
43  parser_ = parser;
44  }
45 
46  void UDPBCBroker::broadcast(const std::vector<uint8_t>& msg_data)
47  {
48  int len = msg_data.size();
49  char *data = new char[len];
50  for(int i = 0; i < len; i++) {
51  *(data + i) = (char)(msg_data[i]);
52  }
53  sender_->send(data, len);
54  }
55 
56  void UDPBCBroker::callback(const std::vector<uint8_t>& msg_vec)
57  {
58  parser_.parse(msg_vec);
59  }
60 
61  void UDPBCBroker::receive()
62  {
63  boost::function<void(const std::vector<uint8_t>&)> func = boost::bind(&UDPBCBroker::callback, this, _1);
64  recver_->receive(func);
65  }
66 };
void callback(const vector< uint8_t > &msg)
Definition: test_recv.cpp:27
static boost::shared_ptr< T > getSingleton()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


udp_bc_broker
Author(s):
autogenerated on Mon Jun 10 2019 14:02:40