tools/Master.cpp
changeset 1099 eb8d16507d88
parent 1082 ff06c58e269c
child 1100 af0b187de6ef
equal deleted inserted replaced
1098:ff5b1722581c 1099:eb8d16507d88
    98 /****************************************************************************/
    98 /****************************************************************************/
    99 
    99 
   100 Master::Master()
   100 Master::Master()
   101 {
   101 {
   102     index = 0;
   102     index = 0;
       
   103     verbosity = Normal;
   103     fd = -1;
   104     fd = -1;
   104 }
   105 }
   105 
   106 
   106 /****************************************************************************/
   107 /****************************************************************************/
   107 
   108 
   113 /****************************************************************************/
   114 /****************************************************************************/
   114 
   115 
   115 void Master::setIndex(unsigned int i)
   116 void Master::setIndex(unsigned int i)
   116 {
   117 {
   117     index = i;
   118     index = i;
       
   119 }
       
   120 
       
   121 /****************************************************************************/
       
   122 
       
   123 void Master::setVerbosity(Verbosity v)
       
   124 {
       
   125     verbosity = v;
   118 }
   126 }
   119 
   127 
   120 /*****************************************************************************/
   128 /*****************************************************************************/
   121 
   129 
   122 /**
   130 /**
   126         int slavePosition,
   134         int slavePosition,
   127         bool force,
   135         bool force,
   128         const vector<string> &commandArgs
   136         const vector<string> &commandArgs
   129         )
   137         )
   130 {
   138 {
   131     ec_ioctl_slave_sii_t data;
       
   132     ec_ioctl_slave_t slave;
       
   133     unsigned int i;
       
   134     uint16_t alias;
   139     uint16_t alias;
   135     stringstream err, strAlias;
   140     stringstream err, strAlias;
   136     int number;
   141     int number;
   137 
   142 
   138     if (commandArgs.size() != 1) {
   143     if (commandArgs.size() != 1) {
   174 
   179 
   175 /*****************************************************************************/
   180 /*****************************************************************************/
   176 
   181 
   177 /** Lists the bus configuration.
   182 /** Lists the bus configuration.
   178  */
   183  */
   179 void Master::showConfigs(bool verbose)
   184 void Master::showConfigs()
   180 {
   185 {
   181     if (verbose) {
   186     if (verbosity == Verbose) {
   182         showConfigs();
   187         showDetailedConfigs();
   183     } else {
   188     } else {
   184         listConfigs();
   189         listConfigs();
   185     }
   190     }
   186 }
   191 }
   187 
   192 
   310     }
   315     }
   311 }
   316 }
   312 
   317 
   313 /****************************************************************************/
   318 /****************************************************************************/
   314 
   319 
   315 void Master::listPdos(int slavePosition, bool quiet)
   320 void Master::listPdos(int slavePosition)
   316 {
   321 {
   317     open(Read);
   322     open(Read);
   318 
   323 
   319     if (slavePosition == -1) {
   324     if (slavePosition == -1) {
   320         unsigned int numSlaves = slaveCount(), i;
   325         unsigned int numSlaves = slaveCount(), i;
   321 
   326 
   322         for (i = 0; i < numSlaves; i++) {
   327         for (i = 0; i < numSlaves; i++) {
   323             listSlavePdos(i, quiet, true);
   328             listSlavePdos(i, true);
   324         }
   329         }
   325     } else {
   330     } else {
   326         listSlavePdos(slavePosition, quiet, false);
   331         listSlavePdos(slavePosition, false);
   327     }
   332     }
   328 }
   333 }
   329 
   334 
   330 /****************************************************************************/
   335 /****************************************************************************/
   331 
   336 
   332 void Master::listSdos(int slavePosition, bool quiet)
   337 void Master::listSdos(int slavePosition)
   333 {
   338 {
   334     open(Read);
   339     open(Read);
   335 
   340 
   336     if (slavePosition == -1) {
   341     if (slavePosition == -1) {
   337         unsigned int numSlaves = slaveCount(), i;
   342         unsigned int numSlaves = slaveCount(), i;
   338 
   343 
   339         for (i = 0; i < numSlaves; i++) {
   344         for (i = 0; i < numSlaves; i++) {
   340             listSlaveSdos(i, quiet, true);
   345             listSlaveSdos(i, true);
   341         }
   346         }
   342     } else {
   347     } else {
   343         listSlaveSdos(slavePosition, quiet, false);
   348         listSlaveSdos(slavePosition, false);
   344     }
   349     }
   345 }
   350 }
   346 
   351 
   347 /****************************************************************************/
   352 /****************************************************************************/
   348 
   353 
   352         const vector<string> &commandArgs
   357         const vector<string> &commandArgs
   353         )
   358         )
   354 {
   359 {
   355     stringstream strIndex, strSubIndex, strValue, err;
   360     stringstream strIndex, strSubIndex, strValue, err;
   356     ec_ioctl_slave_sdo_download_t data;
   361     ec_ioctl_slave_sdo_download_t data;
   357     unsigned int i, number;
   362     unsigned int number;
   358     const CoEDataType *dataType = NULL;
   363     const CoEDataType *dataType = NULL;
   359 
   364 
   360     if (slavePosition < 0) {
   365     if (slavePosition < 0) {
   361         err << "'sdo_download' requires a slave! Please specify --slave.";
   366         err << "'sdo_download' requires a slave! Please specify --slave.";
   362         throw MasterException(err.str());
   367         throw MasterException(err.str());
   392             err << "Invalid data type '" << dataTypeStr << "'!";
   397             err << "Invalid data type '" << dataTypeStr << "'!";
   393             throw MasterException(err.str());
   398             throw MasterException(err.str());
   394         }
   399         }
   395     } else { // no data type specified: fetch from dictionary
   400     } else { // no data type specified: fetch from dictionary
   396         ec_ioctl_slave_sdo_entry_t entry;
   401         ec_ioctl_slave_sdo_entry_t entry;
   397         unsigned int entryByteSize;
       
   398 
   402 
   399         open(ReadWrite);
   403         open(ReadWrite);
   400 
   404 
   401         try {
   405         try {
   402             getSdoEntry(&entry, slavePosition,
   406             getSdoEntry(&entry, slavePosition,
   522         )
   526         )
   523 {
   527 {
   524     stringstream strIndex, strSubIndex;
   528     stringstream strIndex, strSubIndex;
   525     int sval;
   529     int sval;
   526     ec_ioctl_slave_sdo_upload_t data;
   530     ec_ioctl_slave_sdo_upload_t data;
   527     unsigned int i, uval;
   531     unsigned int uval;
   528     const CoEDataType *dataType = NULL;
   532     const CoEDataType *dataType = NULL;
   529 
   533 
   530     if (slavePosition < 0) {
   534     if (slavePosition < 0) {
   531         stringstream err;
   535         stringstream err;
   532         err << "'sdo_upload' requires a slave! Please specify --slave.";
   536         err << "'sdo_upload' requires a slave! Please specify --slave.";
   567             err << "Invalid data type '" << dataTypeStr << "'!";
   571             err << "Invalid data type '" << dataTypeStr << "'!";
   568             throw MasterException(err.str());
   572             throw MasterException(err.str());
   569         }
   573         }
   570     } else { // no data type specified: fetch from dictionary
   574     } else { // no data type specified: fetch from dictionary
   571         ec_ioctl_slave_sdo_entry_t entry;
   575         ec_ioctl_slave_sdo_entry_t entry;
   572         unsigned int entryByteSize;
       
   573 
   576 
   574         open(Read);
   577         open(Read);
   575 
   578 
   576         try {
   579         try {
   577             getSdoEntry(&entry, slavePosition,
   580             getSdoEntry(&entry, slavePosition,
   663     delete [] data.target;
   666     delete [] data.target;
   664 }
   667 }
   665 
   668 
   666 /****************************************************************************/
   669 /****************************************************************************/
   667 
   670 
   668 void Master::showSlaves(int slavePosition, bool verbose)
   671 void Master::showSlaves(int slavePosition)
   669 {
   672 {
   670     open(Read);
   673     open(Read);
   671 
   674 
   672     if (verbose) {
   675     if (verbosity == Verbose) {
   673         if (slavePosition == -1) {
   676         if (slavePosition == -1) {
   674             unsigned int numSlaves = slaveCount(), i;
   677             unsigned int numSlaves = slaveCount(), i;
   675 
   678 
   676             for (i = 0; i < numSlaves; i++) {
   679             for (i = 0; i < numSlaves; i++) {
   677                 showSlave(i);
   680                 showSlave(i);
   973 
   976 
   974 /*****************************************************************************/
   977 /*****************************************************************************/
   975 
   978 
   976 /** Lists the complete bus configuration.
   979 /** Lists the complete bus configuration.
   977  */
   980  */
   978 void Master::showConfigs()
   981 void Master::showDetailedConfigs()
   979 {
   982 {
   980     ec_ioctl_master_t master;
   983     ec_ioctl_master_t master;
   981     unsigned int i, j, k, l;
   984     unsigned int i, j, k, l;
   982     ec_ioctl_config_t config;
   985     ec_ioctl_config_t config;
   983     ec_ioctl_config_pdo_t pdo;
   986     ec_ioctl_config_pdo_t pdo;
  1246 
  1249 
  1247 /****************************************************************************/
  1250 /****************************************************************************/
  1248 
  1251 
  1249 void Master::listSlavePdos(
  1252 void Master::listSlavePdos(
  1250         uint16_t slavePosition,
  1253         uint16_t slavePosition,
  1251         bool quiet,
       
  1252         bool withHeader
  1254         bool withHeader
  1253         )
  1255         )
  1254 {
  1256 {
  1255     ec_ioctl_slave_t slave;
  1257     ec_ioctl_slave_t slave;
  1256     ec_ioctl_slave_sync_t sync;
  1258     ec_ioctl_slave_sync_t sync;
  1285                 << "xPdo 0x"
  1287                 << "xPdo 0x"
  1286                 << hex << setfill('0')
  1288                 << hex << setfill('0')
  1287                 << setw(4) << pdo.index
  1289                 << setw(4) << pdo.index
  1288                 << " \"" << pdo.name << "\"" << endl;
  1290                 << " \"" << pdo.name << "\"" << endl;
  1289 
  1291 
  1290             if (quiet)
  1292             if (verbosity == Quiet)
  1291                 continue;
  1293                 continue;
  1292 
  1294 
  1293             for (k = 0; k < pdo.entry_count; k++) {
  1295             for (k = 0; k < pdo.entry_count; k++) {
  1294                 getPdoEntry(&entry, slavePosition, i, j, k);
  1296                 getPdoEntry(&entry, slavePosition, i, j, k);
  1295 
  1297 
  1306 
  1308 
  1307 /****************************************************************************/
  1309 /****************************************************************************/
  1308 
  1310 
  1309 void Master::listSlaveSdos(
  1311 void Master::listSlaveSdos(
  1310         uint16_t slavePosition,
  1312         uint16_t slavePosition,
  1311         bool quiet,
       
  1312         bool withHeader
  1313         bool withHeader
  1313         )
  1314         )
  1314 {
  1315 {
  1315     ec_ioctl_slave_t slave;
  1316     ec_ioctl_slave_t slave;
  1316     ec_ioctl_slave_sdo_t sdo;
  1317     ec_ioctl_slave_sdo_t sdo;
  1317     ec_ioctl_slave_sdo_entry_t entry;
  1318     ec_ioctl_slave_sdo_entry_t entry;
  1318     unsigned int i, j, k;
  1319     unsigned int i, j;
  1319     const CoEDataType *d;
  1320     const CoEDataType *d;
  1320     
  1321     
  1321     getSlave(&slave, slavePosition);
  1322     getSlave(&slave, slavePosition);
  1322 
  1323 
  1323     if (withHeader)
  1324     if (withHeader)
  1329         cout << "Sdo 0x"
  1330         cout << "Sdo 0x"
  1330             << hex << setfill('0')
  1331             << hex << setfill('0')
  1331             << setw(4) << sdo.sdo_index
  1332             << setw(4) << sdo.sdo_index
  1332             << ", \"" << sdo.name << "\"" << endl;
  1333             << ", \"" << sdo.name << "\"" << endl;
  1333 
  1334 
  1334         if (quiet)
  1335         if (verbosity == Quiet)
  1335             continue;
  1336             continue;
  1336 
  1337 
  1337         for (j = 0; j <= sdo.max_subindex; j++) {
  1338         for (j = 0; j <= sdo.max_subindex; j++) {
  1338             getSdoEntry(&entry, slavePosition, -i, j);
  1339             getSdoEntry(&entry, slavePosition, -i, j);
  1339 
  1340 
  1390         if (slave.alias) {
  1391         if (slave.alias) {
  1391             lastAlias = slave.alias;
  1392             lastAlias = slave.alias;
  1392             aliasIndex = 0;
  1393             aliasIndex = 0;
  1393         }
  1394         }
  1394 
  1395 
  1395         if (slavePosition == -1 || i == slavePosition) {
  1396         if (slavePosition == -1 || i == (unsigned int) slavePosition) {
  1396             str << dec << i;
  1397             str << dec << i;
  1397             slaveInfo.pos = str.str();
  1398             slaveInfo.pos = str.str();
  1398             str.clear();
  1399             str.clear();
  1399             str.str("");
  1400             str.str("");
  1400 
  1401