ros_broker.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include <ros/ros.h>
25 
26 #include "ros_broker/ros_broker.h"
27 
29 
30 namespace ros_broker{
31 
32  ROSBroker::ROSBroker()
33  {
34  packet_publisher_ = node_handle_.advertise<ros_broker::GSDFPacket>("/micros_swarm_framework_topic", 2000, true);
35  }
36 
37  void ROSBroker::init(std::string name, const micros_swarm::PacketParser& parser)
38  {
39  name_ = name;
40  parser_ = parser;
41  }
42 
43  void ROSBroker::broadcast(const std::vector<uint8_t>& msg_data)
44  {
45  static bool flag = false;
46  if(!flag) {
47  ros::Duration(1).sleep();
48  if(!packet_publisher_) {
49  ROS_INFO("ROS communicator could not initialize!");
50  exit(-1);
51  }
52  flag=true;
53  }
54 
55  if(ros::ok()) {
56  ros_broker::GSDFPacket ros_msg;
57  ros_msg.data = msg_data;
58  packet_publisher_.publish(ros_msg);
59  }
60  }
61 
62  void ROSBroker::callback(const ros_broker::GSDFPacket& ros_msg)
63  {
64  parser_.parse(ros_msg.data);
65  }
66 
67  void ROSBroker::receive()
68  {
69  packet_subscriber_ = node_handle_.subscribe("/micros_swarm_framework_topic", 1000, &ROSBroker::callback, this, ros::TransportHints().udp());
70  }
71 };
bool sleep() const
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


ros_broker
Author(s):
autogenerated on Mon Jun 10 2019 14:02:28