tool/cmd_alias.cpp
changeset 1136 a0982873d655
parent 1126 b09fd81894cb
child 1137 a73c0f54be42
equal deleted inserted replaced
1135:807ec6498502 1136:a0982873d655
    64 
    64 
    65     if (slavePosition == -1) {
    65     if (slavePosition == -1) {
    66         if (!force) {
    66         if (!force) {
    67             err << "This will write the alias addresses of all slaves to "
    67             err << "This will write the alias addresses of all slaves to "
    68                 << alias << "! Please specify --force to proceed.";
    68                 << alias << "! Please specify --force to proceed.";
    69             throw ExecutionFailureException(err);
    69             throw CommandException(err);
    70         }
    70         }
    71 
    71 
    72         masterDev.open(MasterDevice::ReadWrite);
    72         masterDev.open(MasterDevice::ReadWrite);
    73         numSlaves = masterDev.slaveCount();
    73         numSlaves = masterDev.slaveCount();
    74 
    74 
    98     masterDev.getSlave(&slave, slavePosition);
    98     masterDev.getSlave(&slave, slavePosition);
    99 
    99 
   100     if (slave.sii_nwords < 8) {
   100     if (slave.sii_nwords < 8) {
   101         err << "Current SII contents are too small to set an alias "
   101         err << "Current SII contents are too small to set an alias "
   102             << "(" << slave.sii_nwords << " words)!";
   102             << "(" << slave.sii_nwords << " words)!";
   103         throw ExecutionFailureException(err);
   103         throw CommandException(err);
   104     }
   104     }
   105 
   105 
   106     // read first 8 SII words
   106     // read first 8 SII words
   107     data.slave_position = slavePosition;
   107     data.slave_position = slavePosition;
   108     data.offset = 0;
   108     data.offset = 0;
   112     try {
   112     try {
   113         masterDev.readSii(&data);
   113         masterDev.readSii(&data);
   114     } catch (MasterDeviceException &e) {
   114     } catch (MasterDeviceException &e) {
   115         delete [] data.words;
   115         delete [] data.words;
   116         err << "Failed to read SII: " << e.what();
   116         err << "Failed to read SII: " << e.what();
   117         throw ExecutionFailureException(err);
   117         throw CommandException(err);
   118     }
   118     }
   119 
   119 
   120     // write new alias address in word 4
   120     // write new alias address in word 4
   121     data.words[4] = cputole16(alias);
   121     data.words[4] = cputole16(alias);
   122 
   122 
   130     try {
   130     try {
   131         masterDev.writeSii(&data);
   131         masterDev.writeSii(&data);
   132     } catch (MasterDeviceException &e) {
   132     } catch (MasterDeviceException &e) {
   133         delete [] data.words;
   133         delete [] data.words;
   134         err << "Failed to read SII: " << e.what();
   134         err << "Failed to read SII: " << e.what();
   135         throw ExecutionFailureException(err);
   135         throw CommandException(err);
   136     }
   136     }
   137 
   137 
   138     delete [] data.words;
   138     delete [] data.words;
   139 }
   139 }
   140 
   140