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@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1222: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandStates.h" fp@1826: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandStates::CommandStates(): fp@1142: Command("states", "Request application-layer states.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1968: string CommandStates::helpString(const string &binaryBaseName) const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1968: str << binaryBaseName << " " << getName() << " [OPTIONS] " << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Arguments:" << endl fp@1337: << " STATE can be 'INIT', 'PREOP', 'BOOT', 'SAFEOP', or 'OP'." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1157: << " --alias -a " << endl fp@1157: << " --position -p Slave selection. See the help of" << endl fp@1157: << " the 'slaves' command." << endl fp@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1826: void CommandStates::execute(const StringVector &args) fp@1142: { fp@1869: MasterIndexList masterIndices; fp@1151: SlaveList slaves; fp@1151: SlaveList::const_iterator si; fp@1142: stringstream err; fp@1142: string stateStr; fp@1142: uint8_t state = 0x00; fp@2421: fp@1142: if (args.size() != 1) { fp@1142: err << "'" << getName() << "' takes exactly one argument!"; fp@1142: throwInvalidUsageException(err); fp@1142: } fp@1142: fp@1142: stateStr = args[0]; fp@1142: transform(stateStr.begin(), stateStr.end(), fp@1142: stateStr.begin(), (int (*) (int)) std::toupper); fp@1142: fp@1142: if (stateStr == "INIT") { fp@1142: state = 0x01; fp@1142: } else if (stateStr == "PREOP") { fp@1142: state = 0x02; fp@1337: } else if (stateStr == "BOOT") { fp@1337: state = 0x03; fp@1142: } else if (stateStr == "SAFEOP") { fp@1142: state = 0x04; fp@1142: } else if (stateStr == "OP") { fp@1142: state = 0x08; fp@1142: } else { fp@1142: err << "Invalid state '" << 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: slaves = selectedSlaves(m); fp@1142: fp@1826: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1826: m.requestState(si->position, state); fp@1826: } fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/