fp@1126: /***************************************************************************** fp@1126: * fp@1126: * $Id$ fp@1126: * fp@1126: ****************************************************************************/ fp@1126: fp@1126: #include fp@1126: using namespace std; fp@1126: fp@1126: #include "globals.h" fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: const char *help_states = fp@1137: "[OPTIONS] \n" fp@1126: "\n" fp@1137: "Request an application-layer state change for the specified slaves.\n" fp@1126: "\n" fp@1137: "Arguments:\n" fp@1137: " STATE can be 'INIT', 'PREOP', 'SAFEOP', or 'OP'\n" fp@1137: "\n" fp@1137: "Command-specific options:\n" fp@1137: " --slave -s Positive numerical ring position, or 'all' for\n" fp@1137: " all slaves (default).\n" fp@1137: "\n" fp@1137: "Numerical values can be specified either with decimal (no prefix),\n" fp@1137: "octal (prefix '0') or hexadecimal (prefix '0x') base.\n"; fp@1126: fp@1126: /****************************************************************************/ fp@1126: fp@1126: void command_states(void) fp@1126: { fp@1136: stringstream err; fp@1126: string stateStr; fp@1126: uint8_t state; fp@1126: fp@1126: if (commandArgs.size() != 1) { fp@1136: err << "'" << commandName << "' takes exactly one argument!"; fp@1136: throw InvalidUsageException(err); fp@1126: } fp@1126: fp@1126: stateStr = commandArgs[0]; fp@1126: transform(stateStr.begin(), stateStr.end(), fp@1126: stateStr.begin(), (int (*) (int)) std::toupper); fp@1126: fp@1126: if (stateStr == "INIT") { fp@1126: state = 0x01; fp@1126: } else if (stateStr == "PREOP") { fp@1126: state = 0x02; fp@1126: } else if (stateStr == "SAFEOP") { fp@1126: state = 0x04; fp@1126: } else if (stateStr == "OP") { fp@1126: state = 0x08; fp@1126: } else { fp@1126: err << "Invalid state '" << commandArgs[0] << "'!"; fp@1136: throw InvalidUsageException(err); fp@1126: } fp@1126: fp@1126: masterDev.open(MasterDevice::ReadWrite); fp@1126: fp@1126: if (slavePosition == -1) { fp@1126: unsigned int i, numSlaves = masterDev.slaveCount(); fp@1126: for (i = 0; i < numSlaves; i++) fp@1126: masterDev.requestState(i, state); fp@1126: } else { fp@1126: masterDev.requestState(slavePosition, state); fp@1126: } fp@1126: } fp@1126: fp@1126: /*****************************************************************************/