sub.cpp
Go to the documentation of this file.
00001 
00023 #include <iostream>
00024 #include "opensplice_dds_broker/check_status.h"
00025 #include "opensplice_dds_broker/subscriber.h"
00026 #include "gsdf_msgs/CommPacket.h"
00027 #include "gsdf_msgs/JoinSwarm.h"
00028 #include "micros_swarm/message.h"
00029 
00030 using namespace DDS;
00031 
00032 void dump_string(const std::string& s)
00033 {
00034     std::cout<<"length: "<<s.length()<<", data: ";
00035     for(int i = 0; i < s.length(); i++) {
00036         std::cout<<(int)s[i];
00037     }
00038     std::cout<<std::endl;
00039 }
00040 
00041 void dump_char_seq(char* s, int len)
00042 {
00043     std::cout<<"length: "<<len<<", data: ";
00044     for(int i = 0; i < len; i++) {
00045         std::cout<<(int)(*(s+i));
00046     }
00047     std::cout<<std::endl;
00048 }
00049 
00050 void dump_char_vec(std::vector<uint8_t> vec)
00051 {
00052     std::cout<<"length: "<<vec.size()<<", data: ";
00053     for(int i = 0; i < vec.size(); i++) {
00054         std::cout<<(int)(vec[i]);
00055     }
00056     std::cout<<std::endl;
00057 }
00058 
00059 void callBack(const opensplice_dds_broker::GSDFPacket& packet)
00060 {
00061     int msgLen = packet.data.length();
00062     if (msgLen == 0) {
00063         std::cout<<"opensplice dds recv error."<<std::endl;
00064     }
00065     else {
00066         uint8_t* buf = (uint8_t*)malloc(sizeof(uint8_t)*msgLen);
00067         memcpy(buf, packet.data.get_buffer(), msgLen);
00068         std::vector<uint8_t> vec;
00069         vec.resize(msgLen);
00070         std::copy(buf, buf + msgLen, vec.begin());
00071         dump_char_vec(vec);
00072         gsdf_msgs::JoinSwarm js = micros_swarm::deserialize_ros<gsdf_msgs::JoinSwarm>(vec);
00073         std::cout<<"js: "<<js.robot_id<<", "<<js.swarm_id<<std::endl;
00074     }
00075 }
00076 
00077 int main()
00078 {
00079     opensplice_dds_broker::Subscriber subscriber("micros_swarm_framework_topic");
00080     subscriber.subscribe(callBack);
00081     
00082     while(true) {
00083         sleep(1);
00084     }
00085     return 0;
00086 }


opensplice_dds_broker
Author(s):
autogenerated on Thu Jun 6 2019 18:52:31