tool/cmd_states.cpp
changeset 1126 b09fd81894cb
child 1130 bb1c11adb2db
equal deleted inserted replaced
1125:9976f7b9fe66 1126:b09fd81894cb
       
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <iostream>
       
     8 using namespace std;
       
     9 
       
    10 #include "globals.h"
       
    11 
       
    12 /****************************************************************************/
       
    13 
       
    14 const char *help_states =
       
    15     "[OPTIONS]\n"
       
    16     "\n"
       
    17     "\n"
       
    18     "Command-specific options:\n";
       
    19 
       
    20 /****************************************************************************/
       
    21 
       
    22 void command_states(void)
       
    23 {
       
    24     string stateStr;
       
    25     uint8_t state;
       
    26     
       
    27     if (commandArgs.size() != 1) {
       
    28         stringstream err;
       
    29         err << "'state' takes exactly one argument!";
       
    30         throw MasterDeviceException(err.str());
       
    31     }
       
    32 
       
    33     stateStr = commandArgs[0];
       
    34     transform(stateStr.begin(), stateStr.end(),
       
    35             stateStr.begin(), (int (*) (int)) std::toupper);
       
    36 
       
    37     if (stateStr == "INIT") {
       
    38         state = 0x01;
       
    39     } else if (stateStr == "PREOP") {
       
    40         state = 0x02;
       
    41     } else if (stateStr == "SAFEOP") {
       
    42         state = 0x04;
       
    43     } else if (stateStr == "OP") {
       
    44         state = 0x08;
       
    45     } else {
       
    46         stringstream err;
       
    47         err << "Invalid state '" << commandArgs[0] << "'!";
       
    48         throw MasterDeviceException(err.str());
       
    49     }
       
    50 
       
    51     masterDev.open(MasterDevice::ReadWrite);
       
    52 
       
    53     if (slavePosition == -1) {
       
    54         unsigned int i, numSlaves = masterDev.slaveCount();
       
    55         for (i = 0; i < numSlaves; i++)
       
    56             masterDev.requestState(i, state);
       
    57     } else {
       
    58         masterDev.requestState(slavePosition, state);
       
    59     }
       
    60 }
       
    61 
       
    62 /*****************************************************************************/