rec.cpp
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "../common/consts.h"
00022 #include "../msg/msg.h"
00023 #include "../utils/utils.h"
00024 #include <dashel/dashel.h>
00025 #include "../transport/dashel_plugins/dashel-plugins.h"
00026 #include <time.h>
00027 #include <iostream>
00028 #include <cstring>
00029 
00030 namespace Aseba
00031 {
00032         using namespace Dashel;
00033         using namespace std;
00034         
00039         
00042         class Recorder : public Hub
00043         {
00044         protected:
00045                 
00046                 void incomingData(Stream *stream)
00047                 {
00048                         Message *message = Message::receive(stream);
00049                         UserMessage *userMessage = dynamic_cast<UserMessage *>(message);
00050                         if (userMessage)
00051                         {
00052                                 dumpTime(cout, true);
00053                                 cout << userMessage->source << " ";
00054                                 cout << userMessage->type << " ";
00055                                 cout << userMessage->data.size() << " ";
00056                                 for (UserMessage::DataVector::const_iterator it = userMessage->data.begin(); it != userMessage->data.end(); ++it)
00057                                         cout << *it << " ";
00058                                 cout << endl;
00059                         }
00060                 }
00061         };
00062         
00064 }
00065 
00066 
00068 void dumpHelp(std::ostream &stream, const char *programName)
00069 {
00070         stream << "Aseba rec, record the user messages to stdout for later replay, usage:\n";
00071         stream << programName << " [options] [targets]*\n";
00072         stream << "Options:\n";
00073         stream << "-h, --help      : shows this help\n";
00074         stream << "-V, --version   : shows the version number\n";
00075         stream << "Targets are any valid Dashel targets." << std::endl;
00076         stream << "Report bugs to: aseba-dev@gna.org" << std::endl;
00077 }
00078 
00080 void dumpVersion(std::ostream &stream)
00081 {
00082         stream << "Aseba rec " << ASEBA_VERSION << std::endl;
00083         stream << "Aseba protocol " << ASEBA_PROTOCOL_VERSION << std::endl;
00084         stream << "Licence LGPLv3: GNU LGPL version 3 <http://www.gnu.org/licenses/lgpl.html>\n";
00085 }
00086 
00087 int main(int argc, char *argv[])
00088 {
00089         Dashel::initPlugins();
00090         std::vector<std::string> targets;
00091         
00092         int argCounter = 1;
00093         
00094         while (argCounter < argc)
00095         {
00096                 const char *arg = argv[argCounter];
00097                 
00098                 if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
00099                 {
00100                         dumpHelp(std::cout, argv[0]);
00101                         return 0;
00102                 }
00103                 else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
00104                 {
00105                         dumpVersion(std::cout);
00106                         return 0;
00107                 }
00108                 else
00109                 {
00110                         targets.push_back(argv[argCounter]);
00111                 }
00112                 argCounter++;
00113         }
00114         
00115         if (targets.empty())
00116                 targets.push_back(ASEBA_DEFAULT_TARGET);
00117         
00118         try
00119         {
00120                 Aseba::Recorder recorder;
00121                 for (size_t i = 0; i < targets.size(); i++)
00122                         recorder.connect(targets[i]);
00123                 recorder.run();
00124         }
00125         catch(Dashel::DashelException e)
00126         {
00127                 std::cerr << e.what() << std::endl;
00128         }
00129         
00130         return 0;
00131 }


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:17