tool/Command.cpp
changeset 2589 2b9c78543663
parent 2014 1d2111370ad5
child 2590 0e207abed88a
equal deleted inserted replaced
2415:af21f0bdc7c9 2589:2b9c78543663
   148 /*****************************************************************************/
   148 /*****************************************************************************/
   149 
   149 
   150 Command::Command(const string &name, const string &briefDesc):
   150 Command::Command(const string &name, const string &briefDesc):
   151     name(name),
   151     name(name),
   152     briefDesc(briefDesc),
   152     briefDesc(briefDesc),
   153     verbosity(Normal)
   153     verbosity(Normal),
       
   154     emergency(false),
       
   155     force(false)
   154 {
   156 {
   155 }
   157 }
   156 
   158 
   157 /*****************************************************************************/
   159 /*****************************************************************************/
   158 
   160 
   202     dataType = t;
   204     dataType = t;
   203 };
   205 };
   204 
   206 
   205 /*****************************************************************************/
   207 /*****************************************************************************/
   206 
   208 
       
   209 void Command::setEmergency(bool e)
       
   210 {
       
   211     emergency = e;
       
   212 };
       
   213 
       
   214 /*****************************************************************************/
       
   215 
   207 void Command::setForce(bool f)
   216 void Command::setForce(bool f)
   208 {
   217 {
   209     force = f;
   218     force = f;
   210 };
   219 };
   211 
   220 
   214 void Command::setOutputFile(const string &f)
   223 void Command::setOutputFile(const string &f)
   215 {
   224 {
   216     outputFile = f;
   225     outputFile = f;
   217 };
   226 };
   218 
   227 
       
   228 /*****************************************************************************/
       
   229 
       
   230 void Command::setSkin(const string &s)
       
   231 {
       
   232     skin = s;
       
   233 };
       
   234 
   219 /****************************************************************************/
   235 /****************************************************************************/
   220 
   236 
   221 bool Command::matchesSubstr(const string &cmd) const
   237 bool Command::matchesSubstr(const string &cmd) const
   222 {
   238 {
   223     return name.substr(0, cmd.length()) == cmd;
   239     return name.substr(0, cmd.length()) == cmd;
   224 }
   240 }
   225     
   241 
   226 /****************************************************************************/
   242 /****************************************************************************/
   227 
   243 
   228 bool Command::matchesAbbrev(const string &abb) const
   244 bool Command::matchesAbbrev(const string &abb) const
   229 {
   245 {
   230     unsigned int i;
   246     unsigned int i;
   236             return false;
   252             return false;
   237     }
   253     }
   238 
   254 
   239     return true;
   255     return true;
   240 }
   256 }
   241     
   257 
   242 /*****************************************************************************/
   258 /*****************************************************************************/
   243 
   259 
   244 string Command::numericInfo()
   260 string Command::numericInfo()
   245 {
   261 {
   246     stringstream str;
   262     stringstream str;
   458     return list;
   474     return list;
   459 }
   475 }
   460 
   476 
   461 /****************************************************************************/
   477 /****************************************************************************/
   462 
   478 
   463 Command::DomainList Command::selectedDomains(MasterDevice &m)
   479 Command::DomainList Command::selectedDomains(MasterDevice &m,
   464 {
   480         const ec_ioctl_master_t &io)
   465     ec_ioctl_master_t master;
   481 {
   466     DomainList list;
   482     DomainList list;
   467 
   483 
   468     m.getMaster(&master);
   484     PositionParser pp(io.domain_count);
   469 
       
   470     PositionParser pp(master.domain_count);
       
   471     NumberListParser::List domList = pp.parse(domains.c_str());
   485     NumberListParser::List domList = pp.parse(domains.c_str());
   472     NumberListParser::List::const_iterator di;
   486     NumberListParser::List::const_iterator di;
   473 
   487 
   474     for (di = domList.begin(); di != domList.end(); di++) {
   488     for (di = domList.begin(); di != domList.end(); di++) {
   475         if (*di < master.domain_count) {
   489         if (*di < io.domain_count) {
   476             ec_ioctl_domain_t d;
   490             ec_ioctl_domain_t d;
   477             m.getDomain(&d, *di);
   491             m.getDomain(&d, *di);
   478             list.push_back(d);
   492             list.push_back(d);
   479         }
   493         }
   480     }
   494     }
   481 
   495 
   482     return list;
   496     return list;
       
   497 }
       
   498 
       
   499 /****************************************************************************/
       
   500 
       
   501 int Command::emergencySlave() const
       
   502 {
       
   503     unsigned int ret;
       
   504 
       
   505     stringstream str;
       
   506     str << positions;
       
   507     str >> ret;
       
   508 
       
   509     return ret;
   483 }
   510 }
   484 
   511 
   485 /****************************************************************************/
   512 /****************************************************************************/
   486 
   513 
   487 string Command::alStateString(uint8_t state)
   514 string Command::alStateString(uint8_t state)
   495         case 4: ret = "SAFEOP"; break;
   522         case 4: ret = "SAFEOP"; break;
   496         case 8: ret = "OP"; break;
   523         case 8: ret = "OP"; break;
   497         default: ret = "???";
   524         default: ret = "???";
   498     }
   525     }
   499 
   526 
   500     if (state & EC_SLAVE_STATE_ACK_ERR) { 
   527     if (state & EC_SLAVE_STATE_ACK_ERR) {
   501         ret += "+ERROR";
   528         ret += "+ERROR";
   502     }
   529     }
   503 
   530 
   504     return ret;
   531     return ret;
   505 }
   532 }