tool/Command.cpp
changeset 1151 1fc1535dec29
parent 1146 f18d124d7fbc
child 1155 bd4e5b544473
equal deleted inserted replaced
1150:c589b54ade01 1151:1fc1535dec29
    24 /*****************************************************************************/
    24 /*****************************************************************************/
    25 
    25 
    26 void Command::setVerbosity(Verbosity v)
    26 void Command::setVerbosity(Verbosity v)
    27 {
    27 {
    28 	verbosity = v;
    28 	verbosity = v;
       
    29 };
       
    30 
       
    31 /*****************************************************************************/
       
    32 
       
    33 void Command::setAlias(int a)
       
    34 {
       
    35 	alias = a;
       
    36 };
       
    37 
       
    38 /*****************************************************************************/
       
    39 
       
    40 void Command::setPosition(int p)
       
    41 {
       
    42 	position = p;
    29 };
    43 };
    30 
    44 
    31 /****************************************************************************/
    45 /****************************************************************************/
    32 
    46 
    33 bool Command::matchesSubstr(const string &cmd) const
    47 bool Command::matchesSubstr(const string &cmd) const
    76 void Command::throwCommandException(const stringstream &s)
    90 void Command::throwCommandException(const stringstream &s)
    77 {
    91 {
    78     throw CommandException(s);
    92     throw CommandException(s);
    79 }
    93 }
    80 
    94 
       
    95 /*****************************************************************************/
       
    96 
       
    97 Command::SlaveList Command::selectedSlaves(MasterDevice &m)
       
    98 {
       
    99     unsigned int numSlaves = m.slaveCount(), i, aliasIndex;
       
   100     uint16_t lastAlias;
       
   101     ec_ioctl_slave_t slave;
       
   102     SlaveList list;
       
   103 
       
   104     if (alias == -1) { // no alias given
       
   105         if (position == -1) { // no alias and position given
       
   106             // all items
       
   107             for (i = 0; i < numSlaves; i++) {
       
   108                 m.getSlave(&slave, i);
       
   109                 list.push_back(slave);
       
   110             }
       
   111         } else { // no alias, but position given
       
   112             // one item by position
       
   113             m.getSlave(&slave, position);
       
   114             list.push_back(slave);
       
   115         }
       
   116     } else { // alias given
       
   117         if (position == -1) { // alias, but no position given
       
   118             // take all items with a given alias
       
   119             lastAlias = 0;
       
   120             for (i = 0; i < numSlaves; i++) {
       
   121                 m.getSlave(&slave, i);
       
   122                 if (slave.alias) {
       
   123                     lastAlias = slave.alias;
       
   124                 }
       
   125                 if (lastAlias == (uint16_t) alias) {
       
   126                     list.push_back(slave);
       
   127                 }
       
   128             }
       
   129         } else { // alias and position given
       
   130             lastAlias = 0;
       
   131             aliasIndex = 0;
       
   132             for (i = 0; i < numSlaves; i++) {
       
   133                 m.getSlave(&slave, i);
       
   134                 if (slave.alias) { // FIXME 'lock' first alias
       
   135                     lastAlias = slave.alias;
       
   136                     aliasIndex = 0;
       
   137                 }
       
   138                 if (lastAlias == (uint16_t) alias
       
   139                         && aliasIndex == (unsigned int) position) {
       
   140                     list.push_back(slave);
       
   141                 }
       
   142                 aliasIndex++;
       
   143             }
       
   144         }
       
   145     }
       
   146 
       
   147     return list;
       
   148 }
       
   149 
    81 /****************************************************************************/
   150 /****************************************************************************/
    82 
   151 
    83 string Command::alStateString(uint8_t state)
   152 string Command::alStateString(uint8_t state)
    84 {
   153 {
    85     switch (state) {
   154     switch (state) {