tool/CommandDownload.cpp
changeset 1151 1fc1535dec29
parent 1144 7dbfdd61812c
child 1155 bd4e5b544473
equal deleted inserted replaced
1150:c589b54ade01 1151:1fc1535dec29
    62 {
    62 {
    63     stringstream strIndex, strSubIndex, strValue, err;
    63     stringstream strIndex, strSubIndex, strValue, err;
    64     ec_ioctl_slave_sdo_download_t data;
    64     ec_ioctl_slave_sdo_download_t data;
    65     unsigned int number;
    65     unsigned int number;
    66     const CoEDataType *dataType = NULL;
    66     const CoEDataType *dataType = NULL;
    67 
    67     SlaveList slaves;
    68     if (slavePosition < 0) {
       
    69         err << "'" << getName() << "' requires a slave! "
       
    70             << "Please specify --slave.";
       
    71         throwInvalidUsageException(err);
       
    72     }
       
    73     data.slave_position = slavePosition;
       
    74 
    68 
    75     if (args.size() != 3) {
    69     if (args.size() != 3) {
    76         err << "'" << getName() << "' takes 3 arguments!";
    70         err << "'" << getName() << "' takes 3 arguments!";
    77         throwInvalidUsageException(err);
    71         throwInvalidUsageException(err);
    78     }
    72     }
    94         err << "Invalid Sdo subindex '" << args[1] << "'!";
    88         err << "Invalid Sdo subindex '" << args[1] << "'!";
    95         throwInvalidUsageException(err);
    89         throwInvalidUsageException(err);
    96     }
    90     }
    97     data.sdo_entry_subindex = number;
    91     data.sdo_entry_subindex = number;
    98 
    92 
       
    93     m.open(MasterDevice::ReadWrite);
       
    94     slaves = selectedSlaves(m);
       
    95     if (slaves.size() != 1) {
       
    96         err << slaves.size() << " slaves selected, single slave required!";
       
    97         throwInvalidUsageException(err);
       
    98     }
       
    99     data.slave_position = slaves.front().position;
       
   100 
    99     if (dataTypeStr != "") { // data type specified
   101     if (dataTypeStr != "") { // data type specified
   100         if (!(dataType = findDataType(dataTypeStr))) {
   102         if (!(dataType = findDataType(dataTypeStr))) {
   101             err << "Invalid data type '" << dataTypeStr << "'!";
   103             err << "Invalid data type '" << dataTypeStr << "'!";
   102             throwInvalidUsageException(err);
   104             throwInvalidUsageException(err);
   103         }
   105         }
   104     } else { // no data type specified: fetch from dictionary
   106     } else { // no data type specified: fetch from dictionary
   105         ec_ioctl_slave_sdo_entry_t entry;
   107         ec_ioctl_slave_sdo_entry_t entry;
   106 
   108 
   107         m.open(MasterDevice::ReadWrite);
       
   108 
       
   109         try {
   109         try {
   110             m.getSdoEntry(&entry, slavePosition,
   110             m.getSdoEntry(&entry, data.slave_position,
   111                     data.sdo_index, data.sdo_entry_subindex);
   111                     data.sdo_index, data.sdo_entry_subindex);
   112         } catch (MasterDeviceException &e) {
   112         } catch (MasterDeviceException &e) {
   113             err << "Failed to determine Sdo entry data type. "
   113             err << "Failed to determine Sdo entry data type. "
   114                 << "Please specify --type.";
   114                 << "Please specify --type.";
   115             throwCommandException(err);
   115             throwCommandException(err);
   201         err << "Invalid value argument '" << args[2]
   201         err << "Invalid value argument '" << args[2]
   202             << "' for type '" << dataType->name << "'!";
   202             << "' for type '" << dataType->name << "'!";
   203         throwInvalidUsageException(err);
   203         throwInvalidUsageException(err);
   204     }
   204     }
   205 
   205 
   206     m.open(MasterDevice::ReadWrite);
       
   207 
       
   208 	try {
   206 	try {
   209 			m.sdoDownload(&data);
   207         m.sdoDownload(&data);
   210 	} catch(MasterDeviceException &e) {
   208 	} catch(MasterDeviceException &e) {
   211         delete [] data.data;
   209         delete [] data.data;
   212         throw e;
   210         throw e;
   213     }
   211     }
   214 
   212