tools/Master.cpp
changeset 1065 d1d2aa556344
parent 1062 75a2b2934e2b
child 1066 7ece00bd6559
equal deleted inserted replaced
1064:5f27403587a8 1065:d1d2aa556344
   327         for (i = 0; i < master.domain_count; i++) {
   327         for (i = 0; i < master.domain_count; i++) {
   328             showDomain(i);
   328             showDomain(i);
   329         }
   329         }
   330     } else {
   330     } else {
   331         showDomain(domainIndex);
   331         showDomain(domainIndex);
   332     }
       
   333 }
       
   334 
       
   335 /****************************************************************************/
       
   336 
       
   337 struct SlaveInfo {
       
   338     string pos;
       
   339     string alias;
       
   340     string relPos;
       
   341     string state;
       
   342     string flag;
       
   343     string name;
       
   344 };
       
   345 
       
   346 void Master::listSlaves()
       
   347 {
       
   348     unsigned int numSlaves, i;
       
   349     ec_ioctl_slave_t slave;
       
   350     uint16_t lastAlias, aliasIndex;
       
   351     SlaveInfo slaveInfo;
       
   352     typedef list<SlaveInfo> SlaveInfoList;
       
   353     SlaveInfoList slaveInfoList;
       
   354     SlaveInfoList::const_iterator iter;
       
   355     stringstream str;
       
   356     unsigned int maxPosWidth = 0, maxAliasWidth = 0,
       
   357                  maxRelPosWidth = 0, maxStateWidth = 0;
       
   358     
       
   359     open(Read);
       
   360 
       
   361     numSlaves = slaveCount();
       
   362 
       
   363     lastAlias = 0;
       
   364     aliasIndex = 0;
       
   365     for (i = 0; i < numSlaves; i++) {
       
   366         getSlave(&slave, i);
       
   367         
       
   368         str << dec << i;
       
   369         slaveInfo.pos = str.str();
       
   370         str.clear();
       
   371         str.str("");
       
   372 
       
   373         if (slave.alias) {
       
   374             lastAlias = slave.alias;
       
   375             aliasIndex = 0;
       
   376         }
       
   377         if (lastAlias) {
       
   378             str << "#" << hex << lastAlias;
       
   379             slaveInfo.alias = str.str();
       
   380             str.str("");
       
   381             str << ":" << dec << aliasIndex;
       
   382             slaveInfo.relPos = str.str();
       
   383             str.str("");
       
   384             aliasIndex++;
       
   385         } else {
       
   386             slaveInfo.alias = "";
       
   387             slaveInfo.relPos = "";
       
   388         }
       
   389 
       
   390         slaveInfo.state = slaveState(slave.state);
       
   391         slaveInfo.flag = (slave.error_flag ? 'E' : '+');
       
   392 
       
   393         if (strlen(slave.name)) {
       
   394             slaveInfo.name = slave.name;
       
   395         } else {
       
   396             str << hex << setfill('0')
       
   397                 << setw(8) << slave.vendor_id << ":"
       
   398                 << setw(8) << slave.product_code;
       
   399             slaveInfo.name = str.str();
       
   400             str.str("");
       
   401         }
       
   402 
       
   403         slaveInfoList.push_back(slaveInfo);
       
   404         if (slaveInfo.pos.length() > maxPosWidth)
       
   405             maxPosWidth = slaveInfo.pos.length();
       
   406         if (slaveInfo.alias.length() > maxAliasWidth)
       
   407             maxAliasWidth = slaveInfo.alias.length();
       
   408         if (slaveInfo.relPos.length() > maxRelPosWidth)
       
   409             maxRelPosWidth = slaveInfo.relPos.length();
       
   410         if (slaveInfo.state.length() > maxStateWidth)
       
   411             maxStateWidth = slaveInfo.state.length();
       
   412     }
       
   413 
       
   414     for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) {
       
   415         cout << setfill(' ') << right
       
   416             << setw(maxPosWidth) << iter->pos << "  "
       
   417             << setw(maxAliasWidth) << iter->alias
       
   418             << left
       
   419             << setw(maxRelPosWidth) << iter->relPos << "  "
       
   420             << setw(maxStateWidth) << iter->state << "  "
       
   421             << iter->flag << "  "
       
   422             << iter->name << endl;
       
   423     }
   332     }
   424 }
   333 }
   425 
   334 
   426 /****************************************************************************/
   335 /****************************************************************************/
   427 
   336 
   819     delete [] data.target;
   728     delete [] data.target;
   820 }
   729 }
   821 
   730 
   822 /****************************************************************************/
   731 /****************************************************************************/
   823 
   732 
   824 void Master::showSlaves(int slavePosition)
   733 void Master::showSlaves(int slavePosition, bool verbose)
   825 {
   734 {
   826     open(Read);
   735     open(Read);
   827 
   736 
   828     if (slavePosition == -1) {
   737     if (verbose) {
   829         unsigned int numSlaves = slaveCount(), i;
   738         if (slavePosition == -1) {
   830 
   739             unsigned int numSlaves = slaveCount(), i;
   831         for (i = 0; i < numSlaves; i++) {
   740 
   832             showSlave(i);
   741             for (i = 0; i < numSlaves; i++) {
       
   742                 showSlave(i);
       
   743             }
       
   744         } else {
       
   745             showSlave(slavePosition);
   833         }
   746         }
   834     } else {
   747     } else {
   835         showSlave(slavePosition);
   748         listSlaves(slavePosition);
   836     }
   749     }
   837 }
   750 }
   838 
   751 
   839 /****************************************************************************/
   752 /****************************************************************************/
   840 
   753 
  1318             }
  1231             }
  1319 
  1232 
  1320             cout << ", " << dec << entry.bit_length << " bit, \""
  1233             cout << ", " << dec << entry.bit_length << " bit, \""
  1321                 << entry.description << "\"" << endl;
  1234                 << entry.description << "\"" << endl;
  1322         }
  1235         }
       
  1236     }
       
  1237 }
       
  1238 
       
  1239 /****************************************************************************/
       
  1240 
       
  1241 struct SlaveInfo {
       
  1242     string pos;
       
  1243     string alias;
       
  1244     string relPos;
       
  1245     string state;
       
  1246     string flag;
       
  1247     string name;
       
  1248 };
       
  1249 
       
  1250 void Master::listSlaves(int slavePosition)
       
  1251 {
       
  1252     unsigned int numSlaves, i;
       
  1253     ec_ioctl_slave_t slave;
       
  1254     uint16_t lastAlias, aliasIndex;
       
  1255     SlaveInfo slaveInfo;
       
  1256     typedef list<SlaveInfo> SlaveInfoList;
       
  1257     SlaveInfoList slaveInfoList;
       
  1258     SlaveInfoList::const_iterator iter;
       
  1259     stringstream str;
       
  1260     unsigned int maxPosWidth = 0, maxAliasWidth = 0,
       
  1261                  maxRelPosWidth = 0, maxStateWidth = 0;
       
  1262     
       
  1263     open(Read);
       
  1264 
       
  1265     numSlaves = slaveCount();
       
  1266 
       
  1267     lastAlias = 0;
       
  1268     aliasIndex = 0;
       
  1269     for (i = 0; i < numSlaves; i++) {
       
  1270         getSlave(&slave, i);
       
  1271         
       
  1272         if (slave.alias) {
       
  1273             lastAlias = slave.alias;
       
  1274             aliasIndex = 0;
       
  1275         }
       
  1276 
       
  1277         if (slavePosition == -1 || i == slavePosition) {
       
  1278             str << dec << i;
       
  1279             slaveInfo.pos = str.str();
       
  1280             str.clear();
       
  1281             str.str("");
       
  1282 
       
  1283             if (lastAlias) {
       
  1284                 str << "#" << hex << lastAlias;
       
  1285                 slaveInfo.alias = str.str();
       
  1286                 str.str("");
       
  1287                 str << ":" << dec << aliasIndex;
       
  1288                 slaveInfo.relPos = str.str();
       
  1289                 str.str("");
       
  1290             } else {
       
  1291                 slaveInfo.alias = "";
       
  1292                 slaveInfo.relPos = "";
       
  1293             }
       
  1294 
       
  1295             slaveInfo.state = slaveState(slave.state);
       
  1296             slaveInfo.flag = (slave.error_flag ? 'E' : '+');
       
  1297 
       
  1298             if (strlen(slave.name)) {
       
  1299                 slaveInfo.name = slave.name;
       
  1300             } else {
       
  1301                 str << hex << setfill('0')
       
  1302                     << setw(8) << slave.vendor_id << ":"
       
  1303                     << setw(8) << slave.product_code;
       
  1304                 slaveInfo.name = str.str();
       
  1305                 str.str("");
       
  1306             }
       
  1307 
       
  1308 
       
  1309             slaveInfoList.push_back(slaveInfo);
       
  1310 
       
  1311             if (slaveInfo.pos.length() > maxPosWidth)
       
  1312                 maxPosWidth = slaveInfo.pos.length();
       
  1313             if (slaveInfo.alias.length() > maxAliasWidth)
       
  1314                 maxAliasWidth = slaveInfo.alias.length();
       
  1315             if (slaveInfo.relPos.length() > maxRelPosWidth)
       
  1316                 maxRelPosWidth = slaveInfo.relPos.length();
       
  1317             if (slaveInfo.state.length() > maxStateWidth)
       
  1318                 maxStateWidth = slaveInfo.state.length();
       
  1319         }
       
  1320 
       
  1321         if (lastAlias)
       
  1322             aliasIndex++;
       
  1323     }
       
  1324 
       
  1325     for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) {
       
  1326         cout << setfill(' ') << right
       
  1327             << setw(maxPosWidth) << iter->pos << "  "
       
  1328             << setw(maxAliasWidth) << iter->alias
       
  1329             << left
       
  1330             << setw(maxRelPosWidth) << iter->relPos << "  "
       
  1331             << setw(maxStateWidth) << iter->state << "  "
       
  1332             << iter->flag << "  "
       
  1333             << iter->name << endl;
  1323     }
  1334     }
  1324 }
  1335 }
  1325 
  1336 
  1326 /****************************************************************************/
  1337 /****************************************************************************/
  1327 
  1338