short_single_delay_heavy.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012, 2013 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003  *
00004  * This file is part of SocRob Multicast.
00005  *
00006  * SocRob Multicast is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * SocRob Multicast is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with SocRob Multicast.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <iostream>
00021 
00022 #include <ros/console.h>
00023 
00024 #include <socrob/multicast.h>
00025 
00026 #include "TestShortSingleDelay.h"
00027 #include "ShortHeavyLoader.h"
00028 
00029 
00030 
00031 using namespace std;
00032 using namespace ros;
00033 using namespace socrob::multicast;
00034 
00035 
00036 
00037 void
00038 short_handler (TestShortSingleDelay& test_short,
00039                ShortHeavyLoader& heavy_loader,
00040                vector<uint8_t>& answer,
00041                id_type from,
00042                vector<uint8_t> & question)
00043 {
00044   if (test_short.is_question (question)) {
00045     test_short.short_handler (answer, from, question);
00046   }
00047   else if (heavy_loader.is_question (question)) {
00048     heavy_loader.short_handler (answer, from, question);
00049   }
00050   else {
00051     ROS_FATAL ("Neither tester nor loader claimed the question");
00052     abort();
00053   }
00054 }
00055 
00056 
00057 
00058 int main (int argc, char** argv)
00059 {
00060   init (argc, argv, "short_single_delay_heavy");
00061   
00062   ros::NodeHandle nh;
00063   
00064   int sid;
00065   if (! ros::param::getCached ("robot_number", sid)) {
00066     ROS_FATAL ("Could not get robot_number param");
00067     abort();
00068   }
00069   sid -= 1;
00070   
00071   TestShortSingleDelay test_short (sid, "Heavy");
00072   ShortHeavyLoader heavy_loader (sid);
00073   
00074   {
00075     Manager srmm (ManagerOptions (sid, 5, "239.255.1.1")
00076                   .bandwidth_bps (57671) // 2.2*1024*1024/8/5
00077                   .ports (2000, 2001)
00078                   .tup_ms (100)
00079                   .short_handler (boost::bind (&short_handler, boost::ref (test_short), boost::ref (heavy_loader), _1, _2, _3)));
00080                   
00081     ros::Rate loop_rate (10);
00082     while (ros::ok()) {
00083       test_short.timer (srmm);
00084       heavy_loader.timer (srmm);
00085       loop_rate.sleep();
00086     }
00087   }
00088   
00089   test_short.statistics();
00090   heavy_loader.statistics();
00091 }


socrob_multicast
Author(s): Joao Reis/jreis@isr.ist.utl.pt
autogenerated on Mon Jan 6 2014 11:47:49