mm_radio.cpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Includes
8 *****************************************************************************/
9 
14 #include <ecl/time.hpp>
16 #include <mm_core_msgs/string.hpp>
17 #include <string>
18 #include "../../include/mm_radio/publisher.hpp"
19 #include "../../include/mm_radio/radio.hpp"
20 #include "../../include/mm_radio/subscriber.hpp"
21 
22 /*****************************************************************************
23 ** Methods
24 *****************************************************************************/
25 
26 void oldtimer_foo(std::string data) {
27  std::cout << "oldtimer_foo : processing data: " << data << std::endl;
28 }
29 
30 void oldman_foo(std::string data) {
31  std::cout << "oldman_foo : processing data: " << data << std::endl;
32 }
33 
34 /*****************************************************************************
35 ** Main
36 *****************************************************************************/
37 
38 int main(int argc, char **argv)
39 {
40  /****************************************
41  ** Args
42  ****************************************/
43  ecl::CmdLine cmd("Radio multiplexing, by default tests both sides on inproc, use the options to choose otherwise.");
44  ecl::SwitchArg oldman("m", "oldman", "Run the publisher only", false);
45  ecl::SwitchArg oldtimer("t", "oldtimer", "Run the subscriber only", false);
46  ecl::SwitchArg both("b", "both", "Run both the oldman and oldtimer inproc (instead of iproc)", false);
47  std::vector<ecl::Arg*> xorlist;
48  xorlist.push_back(&oldman);
49  xorlist.push_back(&oldtimer);
50  xorlist.push_back(&both);
51  cmd.xorAdd(xorlist);
52  cmd.parse(argc, argv);
53 
54  const std::string inproc_address = "inproc://radio";
55  const std::string ipc_address = "ipc:///tmp/radio.ipc";
56  //bool result = mm_messages::MessageRegistry::add<mm_core_msgs::TestStrings, std::string>("mm_radio teststrings packet");
57  if ( oldman.isSet() ) {
60  mm_radio::Publisher oldman_publisher("oldman");
61  while(true) {
62  oldman_publisher.publish(mm_core_msgs::TestStrings, std::string("aye carumba"));
63  ecl::MilliSleep()(500);
64  }
65  } else if ( oldtimer.isSet() ) {
68  mm_radio::Publisher oldtimer_publisher("oldtimer");
69  while(true) {
70  oldtimer_publisher.publish(mm_core_msgs::TestStrings, std::string("hello old man"));
71  ecl::MilliSleep()(500);
72  }
73  mm_radio::Radio::shutdown(); // shutdown all named radios
74  } else if ( both.isSet() ) {
75  mm_radio::Radio::startServer("oldman", inproc_address);
76  mm_radio::Radio::startClient("oldtimer", inproc_address);
79  mm_radio::Publisher oldtimer_publisher("oldtimer");
80  mm_radio::Publisher oldman_publisher("oldman");
81  ecl::MilliSleep()(200); // let the connection establish itself
82  for ( unsigned int i = 0; i < 4; ++i ) {
83  oldtimer_publisher.publish(mm_core_msgs::TestStrings, std::string("hello old man"));
84  ecl::MilliSleep()(500);
85  oldman_publisher.publish(mm_core_msgs::TestStrings, std::string("aye carumba"));
86  ecl::MilliSleep()(500);
87  }
88  mm_radio::Radio::shutdown(); // shutdown all named radios
89  }
90  return 0;
91 }
static void shutdown()
Definition: lib/radio.cpp:273
int main(int argc, char **argv)
Definition: mm_radio.cpp:38
void publish(const unsigned int &id, const T &msg)
bool isSet() const
void oldman_foo(std::string data)
Definition: mm_radio.cpp:30
static void startClient(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET)
Pre-establish named connections for a client.
Definition: lib/radio.cpp:234
static void startServer(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET)
Pre-establish named connections for a server.
Definition: lib/radio.cpp:212
void parse(int argc, char **argv)
void xorAdd(Arg &a, Arg &b)
void oldtimer_foo(std::string data)
Definition: mm_radio.cpp:26


mm_radio
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:52:16