udp_bc_broker.cpp
Go to the documentation of this file.
00001 
00023 #include <iostream>
00024 #include <ros/ros.h>
00025 
00026 #include "udp_bc_broker/udp_bc_broker.h"
00027 
00028 PLUGINLIB_EXPORT_CLASS(udp_bc_broker::UDPBCBroker, micros_swarm::CommInterface)
00029 
00030 namespace udp_bc_broker{
00031 
00032     UDPBCBroker::UDPBCBroker()
00033     {
00034         rth_ = micros_swarm::Singleton<micros_swarm::RuntimeHandle>::getSingleton();
00035         int port = 12321;
00036         sender_.reset(new UdpSender(port));
00037         recver_.reset(new UdpRecver(port));
00038     }
00039 
00040     void UDPBCBroker::init(std::string name, const micros_swarm::PacketParser& parser)
00041     {
00042         name_ = name;
00043         parser_ = parser;
00044     }
00045             
00046     void UDPBCBroker::broadcast(const std::vector<uint8_t>& msg_data)
00047     {
00048         int len = msg_data.size();
00049         char *data = new char[len];
00050         for(int i = 0; i < len; i++) {
00051             *(data + i) = (char)(msg_data[i]);
00052         }
00053         sender_->send(data, len);
00054     }
00055             
00056     void UDPBCBroker::callback(const std::vector<uint8_t>& msg_vec)
00057     {
00058         parser_.parse(msg_vec);
00059     }
00060 
00061     void UDPBCBroker::receive()
00062     {
00063         boost::function<void(const std::vector<uint8_t>&)> func = boost::bind(&UDPBCBroker::callback, this, _1);
00064         recver_->receive(func);
00065     }
00066 };


udp_bc_broker
Author(s):
autogenerated on Thu Jun 6 2019 18:52:50