tool/CommandAlias.cpp
changeset 1826 ec6223c3b7ec
parent 1363 11c0b2caa253
child 1869 14f634f5b613
equal deleted inserted replaced
1825:65781b048a47 1826:ec6223c3b7ec
    32 #include <sstream>
    32 #include <sstream>
    33 using namespace std;
    33 using namespace std;
    34 
    34 
    35 #include "CommandAlias.h"
    35 #include "CommandAlias.h"
    36 #include "sii_crc.h"
    36 #include "sii_crc.h"
       
    37 #include "MasterDevice.h"
    37 
    38 
    38 /*****************************************************************************/
    39 /*****************************************************************************/
    39 
    40 
    40 CommandAlias::CommandAlias():
    41 CommandAlias::CommandAlias():
    41     Command("alias", "Write alias addresses.")
    42     Command("alias", "Write alias addresses.")
    73 
    74 
    74 /*****************************************************************************/
    75 /*****************************************************************************/
    75 
    76 
    76 /** Writes the Secondary slave address (alias) to the slave's SII.
    77 /** Writes the Secondary slave address (alias) to the slave's SII.
    77  */
    78  */
    78 void CommandAlias::execute(MasterDevice &m, const StringVector &args)
    79 void CommandAlias::execute(const StringVector &args)
    79 {
    80 {
    80     uint16_t alias;
    81     uint16_t alias;
    81     stringstream err, strAlias;
    82     stringstream err, strAlias;
    82     int number;
    83     int number;
    83     SlaveList slaves;
    84     SlaveList slaves;
    96         err << "Invalid alias '" << args[0] << "'!";
    97         err << "Invalid alias '" << args[0] << "'!";
    97         throwInvalidUsageException(err);
    98         throwInvalidUsageException(err);
    98     }
    99     }
    99     alias = number;
   100     alias = number;
   100 
   101 
       
   102     if (getMasterIndices().size() != 1) {
       
   103         err << getName() << " requires to select a single master!";
       
   104         throwInvalidUsageException(err);
       
   105     }
       
   106     MasterDevice m(getMasterIndices().front());
   101     m.open(MasterDevice::ReadWrite);
   107     m.open(MasterDevice::ReadWrite);
   102     slaves = selectedSlaves(m);
   108     slaves = selectedSlaves(m);
   103     
   109     
   104     if (slaves.size() > 1 && !getForce()) {
   110     if (slaves.size() > 1 && !getForce()) {
   105         err << "This will write the alias addresses of "
   111         err << "This will write the alias addresses of "