tool/Command.cpp
changeset 1880 f46bec1b5f21
parent 1870 0cee1fb7f0fd
child 1918 c58633eed20b
equal deleted inserted replaced
1879:7539329b5cf6 1880:f46bec1b5f21
    22  *  ---
    22  *  ---
    23  *
    23  *
    24  *  The license mentioned above concerns the source code only. Using the
    24  *  The license mentioned above concerns the source code only. Using the
    25  *  EtherCAT technology and brand is only permitted in compliance with the
    25  *  EtherCAT technology and brand is only permitted in compliance with the
    26  *  industrial property and similar rights of Beckhoff Automation GmbH.
    26  *  industrial property and similar rights of Beckhoff Automation GmbH.
       
    27  *
       
    28  *  vim: expandtab
    27  *
    29  *
    28  ****************************************************************************/
    30  ****************************************************************************/
    29 
    31 
    30 #include "Command.h"
    32 #include "Command.h"
    31 #include "MasterDevice.h"
    33 #include "MasterDevice.h"
   187 
   189 
   188 /*****************************************************************************/
   190 /*****************************************************************************/
   189 
   191 
   190 Command::MasterIndexList Command::getMasterIndices() const
   192 Command::MasterIndexList Command::getMasterIndices() const
   191 {
   193 {
   192 	MasterIndexList indices;
   194     MasterIndexList indices;
   193 
   195 
   194     try {
   196     try {
   195         MasterIndexParser p;
   197         MasterIndexParser p;
   196         indices = p.parse(masters.c_str());
   198         indices = p.parse(masters.c_str());
   197     } catch (MasterDeviceException &e) {
   199     } catch (MasterDeviceException &e) {
   198 		stringstream err;
   200         stringstream err;
   199 		err << "Failed to obtain number of masters: " << e.what();
   201         err << "Failed to obtain number of masters: " << e.what();
   200 		throwCommandException(err);
   202         throwCommandException(err);
   201     } catch (runtime_error &e) {
   203     } catch (runtime_error &e) {
   202 		stringstream err;
   204         stringstream err;
   203         err << "Invalid master argument '" << masters << "': " << e.what();
   205         err << "Invalid master argument '" << masters << "': " << e.what();
   204 		throwInvalidUsageException(err);
   206         throwInvalidUsageException(err);
   205     }
   207     }
   206 
   208 
   207 	return indices;
   209     return indices;
   208 }
   210 }
   209 
   211 
   210 /*****************************************************************************/
   212 /*****************************************************************************/
   211 
   213 
   212 unsigned int Command::getSingleMasterIndex() const
   214 unsigned int Command::getSingleMasterIndex() const
   213 {
   215 {
   214 	MasterIndexList masterIndices = getMasterIndices();
   216     MasterIndexList masterIndices = getMasterIndices();
   215     if (masterIndices.size() != 1) {
   217     if (masterIndices.size() != 1) {
   216 		stringstream err;
   218         stringstream err;
   217         err << getName() << " requires to select a single master!";
   219         err << getName() << " requires to select a single master!";
   218         throwInvalidUsageException(err);
   220         throwInvalidUsageException(err);
   219     }
   221     }
   220 	return masterIndices.front();
   222     return masterIndices.front();
   221 }
   223 }
   222 
   224 
   223 /*****************************************************************************/
   225 /*****************************************************************************/
   224 
   226 
   225 Command::SlaveList Command::selectedSlaves(MasterDevice &m)
   227 Command::SlaveList Command::selectedSlaves(MasterDevice &m)