tool/CommandUpload.cpp
changeset 1151 1fc1535dec29
parent 1144 7dbfdd61812c
child 1155 bd4e5b544473
equal deleted inserted replaced
1150:c589b54ade01 1151:1fc1535dec29
    56 
    56 
    57 /****************************************************************************/
    57 /****************************************************************************/
    58 
    58 
    59 void CommandUpload::execute(MasterDevice &m, const StringVector &args)
    59 void CommandUpload::execute(MasterDevice &m, const StringVector &args)
    60 {
    60 {
       
    61     SlaveList slaves;
    61     stringstream err, strIndex, strSubIndex;
    62     stringstream err, strIndex, strSubIndex;
    62     int sval;
    63     int sval;
    63     ec_ioctl_slave_sdo_upload_t data;
    64     ec_ioctl_slave_sdo_upload_t data;
    64     unsigned int uval;
    65     unsigned int uval;
    65     const CoEDataType *dataType = NULL;
    66     const CoEDataType *dataType = NULL;
    66 
       
    67     if (slavePosition < 0) {
       
    68         err << "'" << getName() << "' requires a slave! "
       
    69             << "Please specify --slave.";
       
    70         throwInvalidUsageException(err);
       
    71     }
       
    72     data.slave_position = slavePosition;
       
    73 
    67 
    74     if (args.size() != 2) {
    68     if (args.size() != 2) {
    75         err << "'" << getName() << "' takes two arguments!";
    69         err << "'" << getName() << "' takes two arguments!";
    76         throwInvalidUsageException(err);
    70         throwInvalidUsageException(err);
    77     }
    71     }
    92     if (strSubIndex.fail() || uval > 0xff) {
    86     if (strSubIndex.fail() || uval > 0xff) {
    93         err << "Invalid Sdo subindex '" << args[1] << "'!";
    87         err << "Invalid Sdo subindex '" << args[1] << "'!";
    94         throwInvalidUsageException(err);
    88         throwInvalidUsageException(err);
    95     }
    89     }
    96     data.sdo_entry_subindex = uval;
    90     data.sdo_entry_subindex = uval;
       
    91 
       
    92     m.open(MasterDevice::Read);
       
    93     slaves = selectedSlaves(m);
       
    94     if (slaves.size() != 1) {
       
    95         err << slaves.size() << " slaves selected, single slave required!";
       
    96         throwInvalidUsageException(err);
       
    97     }
       
    98     data.slave_position = slaves.front().position;
    97 
    99 
    98     if (dataTypeStr != "") { // data type specified
   100     if (dataTypeStr != "") { // data type specified
    99         if (!(dataType = findDataType(dataTypeStr))) {
   101         if (!(dataType = findDataType(dataTypeStr))) {
   100             err << "Invalid data type '" << dataTypeStr << "'!";
   102             err << "Invalid data type '" << dataTypeStr << "'!";
   101             throwInvalidUsageException(err);
   103             throwInvalidUsageException(err);
   102         }
   104         }
   103     } else { // no data type specified: fetch from dictionary
   105     } else { // no data type specified: fetch from dictionary
   104         ec_ioctl_slave_sdo_entry_t entry;
   106         ec_ioctl_slave_sdo_entry_t entry;
   105 
   107 
   106         m.open(MasterDevice::Read);
       
   107 
       
   108         try {
   108         try {
   109             m.getSdoEntry(&entry, slavePosition,
   109             m.getSdoEntry(&entry, data.slave_position,
   110                     data.sdo_index, data.sdo_entry_subindex);
   110                     data.sdo_index, data.sdo_entry_subindex);
   111         } catch (MasterDeviceException &e) {
   111         } catch (MasterDeviceException &e) {
   112             err << "Failed to determine Sdo entry data type. "
   112             err << "Failed to determine Sdo entry data type. "
   113                 << "Please specify --type.";
   113                 << "Please specify --type.";
   114             throwCommandException(err);
   114             throwCommandException(err);
   127         data.target_size = DefaultBufferSize;
   127         data.target_size = DefaultBufferSize;
   128     }
   128     }
   129 
   129 
   130     data.target = new uint8_t[data.target_size + 1];
   130     data.target = new uint8_t[data.target_size + 1];
   131 
   131 
   132     m.open(MasterDevice::Read);
       
   133 
       
   134 	try {
   132 	try {
   135 		m.sdoUpload(&data);
   133 		m.sdoUpload(&data);
   136 	} catch (MasterDeviceException &e) {
   134 	} catch (MasterDeviceException &e) {
   137         delete [] data.target;
   135         delete [] data.target;
   138         throw e;
   136         throw e;