tool/CommandRegWrite.cpp
branchstable-1.5
changeset 2529 c7e1f2616a9d
parent 2443 2c3ccdde3919
equal deleted inserted replaced
2528:8bb574da5da2 2529:c7e1f2616a9d
    66         << "          interpreted respective to the given type." << endl
    66         << "          interpreted respective to the given type." << endl
    67         << endl
    67         << endl
    68         << typeInfo()
    68         << typeInfo()
    69         << endl
    69         << endl
    70         << "Command-specific options:" << endl
    70         << "Command-specific options:" << endl
    71         << "  --alias    -a <alias>" << endl
    71         << "  --alias     -a <alias>" << endl
    72         << "  --position -p <pos>    Slave selection. See the help of" << endl
    72         << "  --position  -p <pos>    Slave selection. See the help of"
    73         << "                         the 'slaves' command." << endl
    73         << endl
    74         << "  --type     -t <type>   Data type (see above)." << endl
    74         << "                          the 'slaves' command." << endl
       
    75         << "  --type      -t <type>   Data type (see above)." << endl
       
    76         << "  --emergency -e          Send as emergency request." << endl
    75         << endl
    77         << endl
    76         << numericInfo();
    78         << numericInfo();
    77 
    79 
    78     return str.str();
    80     return str.str();
    79 }
    81 }
    83 void CommandRegWrite::execute(const StringVector &args)
    85 void CommandRegWrite::execute(const StringVector &args)
    84 {
    86 {
    85     stringstream strOffset, err;
    87     stringstream strOffset, err;
    86     ec_ioctl_slave_reg_t io;
    88     ec_ioctl_slave_reg_t io;
    87     ifstream file;
    89     ifstream file;
    88     SlaveList slaves;
       
    89 
    90 
    90     if (args.size() != 2) {
    91     if (args.size() != 2) {
    91         err << "'" << getName() << "' takes exactly two arguments!";
    92         err << "'" << getName() << "' takes exactly two arguments!";
    92         throwInvalidUsageException(err);
    93         throwInvalidUsageException(err);
    93     }
    94     }
   156     } catch (MasterDeviceException &e) {
   157     } catch (MasterDeviceException &e) {
   157         delete [] io.data;
   158         delete [] io.data;
   158         throw e;
   159         throw e;
   159     }
   160     }
   160 
   161 
   161     slaves = selectedSlaves(m);
   162     if (getEmergency()) {
   162     if (slaves.size() != 1) {
   163         io.slave_position = emergencySlave();
   163         delete [] io.data;
   164         io.emergency = true;
   164         throwSingleSlaveRequired(slaves.size());
   165     }
   165     }
   166     else {
   166     io.slave_position = slaves.front().position;
   167         SlaveList slaves = selectedSlaves(m);
       
   168         if (slaves.size() != 1) {
       
   169             delete [] io.data;
       
   170             throwSingleSlaveRequired(slaves.size());
       
   171         }
       
   172         io.slave_position = slaves.front().position;
       
   173         io.emergency = false;
       
   174     }
   167 
   175 
   168     // send data to master
   176     // send data to master
   169     try {
   177     try {
   170         m.writeReg(&io);
   178         m.writeReg(&io);
   171     } catch (MasterDeviceException &e) {
   179     } catch (MasterDeviceException &e) {