fp@1142: /*****************************************************************************
fp@1142:  *
fp@1363:  *  $Id$
fp@1363:  *
fp@1363:  *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
fp@1363:  *
fp@1363:  *  This file is part of the IgH EtherCAT Master.
fp@1363:  *
fp@1363:  *  The IgH EtherCAT Master is free software; you can redistribute it and/or
fp@1363:  *  modify it under the terms of the GNU General Public License version 2, as
fp@1363:  *  published by the Free Software Foundation.
fp@1363:  *
fp@1363:  *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
fp@1363:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
fp@1363:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
fp@1363:  *  Public License for more details.
fp@1363:  *
fp@1363:  *  You should have received a copy of the GNU General Public License along
fp@1363:  *  with the IgH EtherCAT Master; if not, write to the Free Software
fp@1363:  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
fp@1363:  *
fp@1363:  *  ---
fp@1363:  *
fp@1363:  *  The license mentioned above concerns the source code only. Using the
fp@1363:  *  EtherCAT technology and brand is only permitted in compliance with the
fp@1363:  *  industrial property and similar rights of Beckhoff Automation GmbH.
fp@1142:  *
fp@1880:  *  vim: expandtab
fp@1880:  *
fp@1142:  ****************************************************************************/
fp@1142: 
fp@1142: #include <sstream>
fp@1142: #include <iomanip>
fp@1142: using namespace std;
fp@1142: 
fp@1142: #include "CommandDebug.h"
fp@1826: #include "MasterDevice.h"
fp@1142: 
fp@1142: /*****************************************************************************/
fp@1142: 
fp@1142: CommandDebug::CommandDebug():
fp@1142:     Command("debug", "Set the master's debug level.")
fp@1142: {
fp@1142: }
fp@1142: 
fp@1142: /*****************************************************************************/
fp@1142: 
fp@1968: string CommandDebug::helpString(const string &binaryBaseName) const
fp@1142: {
fp@1142:     stringstream str;
fp@1142: 
fp@1968:     str << binaryBaseName << " " << getName() << " <LEVEL>" << endl
fp@1804:         << endl
fp@1804:         << getBriefDescription() << endl
fp@1804:         << endl
fp@1804:         << "Debug messages are printed to syslog." << endl
fp@1804:         << endl
fp@1804:         << "Arguments:" << endl
fp@1804:         << "  LEVEL can have one of the following values:" << endl
fp@1804:         << "        0 for no debugging output," << endl
fp@1804:         << "        1 for some debug messages, or" << endl
fp@1804:         << "        2 for printing all frame contents (use with caution!)."
fp@1804:         << endl << endl
fp@1804:         << numericInfo();
fp@1142: 
fp@1804:     return str.str();
fp@1142: }
fp@1142: 
fp@1142: /****************************************************************************/
fp@1142: 
fp@1826: void CommandDebug::execute(const StringVector &args)
fp@1142: {
fp@1869: 	MasterIndexList masterIndices;
fp@1142:     stringstream str;
fp@1142:     int debugLevel;
fp@2421: 
fp@1142:     if (args.size() != 1) {
fp@1142:         stringstream err;
fp@1142:         err << "'" << getName() << "' takes exactly one argument!";
fp@1142:         throwInvalidUsageException(err);
fp@1142:     }
fp@1142: 
fp@1142:     str << args[0];
fp@1142:     str >> resetiosflags(ios::basefield) // guess base from prefix
fp@1142:         >> debugLevel;
fp@1142: 
fp@1142:     if (str.fail()) {
fp@1142:         stringstream err;
fp@1142:         err << "Invalid debug level '" << args[0] << "'!";
fp@1142:         throwInvalidUsageException(err);
fp@1142:     }
fp@1142: 
fp@1869: 	masterIndices = getMasterIndices();
fp@1826:     MasterIndexList::const_iterator mi;
fp@1869:     for (mi = masterIndices.begin();
fp@1869:             mi != masterIndices.end(); mi++) {
fp@1826:         MasterDevice m(*mi);
fp@1826:         m.open(MasterDevice::ReadWrite);
fp@1826:         m.setDebug(debugLevel);
fp@1826:     }
fp@1142: }
fp@1142: 
fp@1142: /*****************************************************************************/