opensplice_dds_comm.cpp
Go to the documentation of this file.
00001 
00023 #include <iostream>
00024 
00025 #include "micros_swarm/comm_interface.h"
00026 #include "opensplice_dds_comm/opensplice_dds_comm.h"
00027 
00028 PLUGINLIB_EXPORT_CLASS(opensplice_dds_comm::OpenSpliceDDSComm, micros_swarm::CommInterface)
00029 
00030 namespace opensplice_dds_comm{
00031 
00032     OpenSpliceDDSComm::OpenSpliceDDSComm()
00033     {
00034         name_="OPENSPLICE_DDS";
00035         packet_publisher_.reset(new opensplice_dds_comm::Publisher("micros_swarm_framework_topic"));
00036         packet_subscriber_.reset(new opensplice_dds_comm::Subscriber("micros_swarm_framework_topic"));
00037     }
00038 
00039     void OpenSpliceDDSComm::init(std::string name, boost::function<void(const micros_swarm::CommPacket& packet)> func)
00040     {
00041         name_=name;
00042         parser_func_=func;
00043     }
00044 
00045     void OpenSpliceDDSComm::broadcast(const micros_swarm::CommPacket& packet)
00046     {
00047         opensplice_dds_comm::GSDFPacket dds_msg;
00048         dds_msg.packet_source=packet.packet_source;
00049         dds_msg.packet_version=packet.packet_version;
00050         dds_msg.packet_type=packet.packet_type;
00051         dds_msg.packet_data=packet.packet_data.data();
00052         dds_msg.package_check_sum=packet.package_check_sum;
00053 
00054         packet_publisher_->publish(dds_msg);
00055     }
00056 
00057     void OpenSpliceDDSComm::callback(const opensplice_dds_comm::GSDFPacket& dds_msg)
00058     {
00059         micros_swarm::CommPacket packet;
00060         packet.packet_source=dds_msg.packet_source;
00061         packet.packet_version=dds_msg.packet_version;
00062         packet.packet_type=dds_msg.packet_type;
00063         packet.packet_data=dds_msg.packet_data;
00064         packet.package_check_sum=dds_msg.package_check_sum;
00065 
00066         parser_func_(packet);
00067     }
00068             
00069     void OpenSpliceDDSComm::receive()
00070     {
00071         boost::function<void(const opensplice_dds_comm::GSDFPacket&)> func=boost::bind(&OpenSpliceDDSComm::callback,this,_1);
00072         packet_subscriber_->subscribe(func);
00073     }
00074 };


opensplice_dds_comm
Author(s):
autogenerated on Sat May 27 2017 02:42:59