ros_broker.cpp
Go to the documentation of this file.
00001 
00023 #include <iostream>
00024 #include <ros/ros.h>
00025 
00026 #include "ros_broker/ros_broker.h"
00027 
00028 PLUGINLIB_EXPORT_CLASS(ros_broker::ROSBroker, micros_swarm::CommInterface)
00029 
00030 namespace ros_broker{
00031 
00032     ROSBroker::ROSBroker()
00033     {
00034         packet_publisher_ = node_handle_.advertise<ros_broker::GSDFPacket>("/micros_swarm_framework_topic", 2000, true);
00035     }
00036 
00037     void ROSBroker::init(std::string name, const micros_swarm::PacketParser& parser)
00038     {
00039         name_ = name;
00040         parser_ = parser;
00041     }
00042             
00043     void ROSBroker::broadcast(const std::vector<uint8_t>& msg_data)
00044     {
00045         static bool flag = false;
00046         if(!flag) {
00047             ros::Duration(1).sleep();
00048             if(!packet_publisher_) {
00049                 ROS_INFO("ROS communicator could not initialize!");
00050                 exit(-1);
00051             }
00052             flag=true;
00053         }
00054         
00055         if(ros::ok()) {
00056             ros_broker::GSDFPacket ros_msg;
00057             ros_msg.data = msg_data;
00058             packet_publisher_.publish(ros_msg);
00059         }
00060     }
00061             
00062     void ROSBroker::callback(const ros_broker::GSDFPacket& ros_msg)
00063     {
00064         parser_.parse(ros_msg.data);
00065     }
00066 
00067     void ROSBroker::receive()
00068     {
00069         packet_subscriber_ = node_handle_.subscribe("/micros_swarm_framework_topic", 1000, &ROSBroker::callback, this, ros::TransportHints().udp());
00070     }
00071 };


ros_broker
Author(s):
autogenerated on Thu Jun 6 2019 18:52:35