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] <STATE>\n" |
|
16 "\n" |
|
17 "Request an application-layer state change for the specified slaves.\n" |
|
18 "\n" |
|
19 "Arguments:\n" |
|
20 " STATE can be 'INIT', 'PREOP', 'SAFEOP', or 'OP'\n" |
|
21 "\n" |
|
22 "Command-specific options:\n" |
|
23 " --slave -s <index> Positive numerical ring position, or 'all' for\n" |
|
24 " all slaves (default).\n" |
|
25 "\n" |
|
26 "Numerical values can be specified either with decimal (no prefix),\n" |
|
27 "octal (prefix '0') or hexadecimal (prefix '0x') base.\n"; |
|
28 |
|
29 /****************************************************************************/ |
|
30 |
|
31 void command_states(void) |
|
32 { |
|
33 stringstream err; |
|
34 string stateStr; |
|
35 uint8_t state; |
|
36 |
|
37 if (commandArgs.size() != 1) { |
|
38 err << "'" << commandName << "' takes exactly one argument!"; |
|
39 throw InvalidUsageException(err); |
|
40 } |
|
41 |
|
42 stateStr = commandArgs[0]; |
|
43 transform(stateStr.begin(), stateStr.end(), |
|
44 stateStr.begin(), (int (*) (int)) std::toupper); |
|
45 |
|
46 if (stateStr == "INIT") { |
|
47 state = 0x01; |
|
48 } else if (stateStr == "PREOP") { |
|
49 state = 0x02; |
|
50 } else if (stateStr == "SAFEOP") { |
|
51 state = 0x04; |
|
52 } else if (stateStr == "OP") { |
|
53 state = 0x08; |
|
54 } else { |
|
55 err << "Invalid state '" << commandArgs[0] << "'!"; |
|
56 throw InvalidUsageException(err); |
|
57 } |
|
58 |
|
59 masterDev.open(MasterDevice::ReadWrite); |
|
60 |
|
61 if (slavePosition == -1) { |
|
62 unsigned int i, numSlaves = masterDev.slaveCount(); |
|
63 for (i = 0; i < numSlaves; i++) |
|
64 masterDev.requestState(i, state); |
|
65 } else { |
|
66 masterDev.requestState(slavePosition, state); |
|
67 } |
|
68 } |
|
69 |
|
70 /*****************************************************************************/ |
|