pub.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include <vector>
27 #include "gsdf_msgs/CommPacket.h"
28 #include "gsdf_msgs/JoinSwarm.h"
29 #include "micros_swarm/message.h"
30 
31 #define MAX_PACKET_LEN 1024
32 #define NUM_PACKET 1000000
33 
34 using namespace DDS;
35 
36 void dump_string(const std::string& s)
37 {
38  std::cout<<"length: "<<s.length()<<", data: ";
39  for(int i = 0; i < s.length(); i++) {
40  std::cout<<(int)s[i];
41  }
42  std::cout<<std::endl;
43 }
44 
45 void dump_char_seq(char* s, int len)
46 {
47  std::cout<<"length: "<<len<<", data: ";
48  for(int i = 0; i < len; i++) {
49  std::cout<<(int)(*(s+i));
50  }
51  std::cout<<std::endl;
52 }
53 
54 void dump_char_vec(std::vector<uint8_t> vec)
55 {
56  std::cout<<"length: "<<vec.size()<<", data: ";
57  for(int i = 0; i < vec.size(); i++) {
58  std::cout<<(int)(vec[i]);
59  }
60  std::cout<<std::endl;
61 }
62 
63 int main()
64 {
66  checkHandle(&packet, "new MSFPPacket");
67  char buf[MAX_PACKET_LEN];
68 
69  std::string test = "";
70  opensplice_dds_broker::Publisher publisher("micros_swarm_framework_topic");
71 
72  gsdf_msgs::JoinSwarm js;
73  js.robot_id = 1;
74  js.swarm_id = 2;
75  std::vector<uint8_t> msg_data = micros_swarm::serialize_ros(js);
76 
77  unsigned int bufsize = msg_data.size();
78  std::cout<<bufsize<<std::endl;
79  packet.data.replace(bufsize, bufsize, (char*)(&msg_data[0]), false);
80 
81  for (int i = 1; i <= NUM_PACKET; i++) {
82  dump_char_vec(msg_data);
83  publisher.publish(packet);
84  sleep (1);
85  }
86  return 0;
87 }
void dump_char_seq(char *s, int len)
Definition: pub.cpp:45
#define NUM_PACKET
Definition: pub.cpp:32
void dump_char_vec(std::vector< uint8_t > vec)
Definition: pub.cpp:54
int main()
Definition: pub.cpp:63
std::vector< uint8_t > serialize_ros(T t)
void publish(const GSDFPacket &packet)
Definition: publisher.cpp:109
void dump_string(const std::string &s)
Definition: pub.cpp:36
void checkHandle(void *handle, const char *info)
#define MAX_PACKET_LEN
Definition: pub.cpp:31


opensplice_dds_broker
Author(s):
autogenerated on Mon Jun 10 2019 14:02:23