tool/CommandSlaves.cpp
changeset 2589 2b9c78543663
parent 1968 4f682084c643
equal deleted inserted replaced
2415:af21f0bdc7c9 2589:2b9c78543663
   109 void CommandSlaves::execute(const StringVector &args)
   109 void CommandSlaves::execute(const StringVector &args)
   110 {
   110 {
   111 	MasterIndexList masterIndices;
   111 	MasterIndexList masterIndices;
   112     SlaveList slaves;
   112     SlaveList slaves;
   113     bool doIndent;
   113     bool doIndent;
   114     
   114 
   115     if (args.size()) {
   115     if (args.size()) {
   116         stringstream err;
   116         stringstream err;
   117         err << "'" << getName() << "' takes no arguments!";
   117         err << "'" << getName() << "' takes no arguments!";
   118         throwInvalidUsageException(err);
   118         throwInvalidUsageException(err);
   119     }
   119     }
   142         const SlaveList &slaves,
   142         const SlaveList &slaves,
   143         bool doIndent
   143         bool doIndent
   144         )
   144         )
   145 {
   145 {
   146     ec_ioctl_master_t master;
   146     ec_ioctl_master_t master;
   147     unsigned int i;
   147     unsigned int i, lastDevice;
   148     ec_ioctl_slave_t slave;
   148     ec_ioctl_slave_t slave;
   149     uint16_t lastAlias, aliasIndex;
   149     uint16_t lastAlias, aliasIndex;
   150     Info info;
   150     Info info;
   151     typedef list<Info> InfoList;
   151     typedef list<Info> InfoList;
   152     InfoList infoList;
   152     InfoList infoList;
   153     InfoList::const_iterator iter;
   153     InfoList::const_iterator iter;
   154     stringstream str;
   154     stringstream str;
   155     unsigned int maxPosWidth = 0, maxAliasWidth = 0,
   155     unsigned int maxPosWidth = 0, maxAliasWidth = 0,
   156                  maxRelPosWidth = 0, maxStateWidth = 0;
   156                  maxRelPosWidth = 0, maxStateWidth = 0;
   157     string indent(doIndent ? "  " : "");
   157     string indent(doIndent ? "  " : "");
   158     
   158 
   159     m.getMaster(&master);
   159     m.getMaster(&master);
   160 
   160 
   161     lastAlias = 0;
   161     lastAlias = 0;
   162     aliasIndex = 0;
   162     aliasIndex = 0;
   163     for (i = 0; i < master.slave_count; i++) {
   163     for (i = 0; i < master.slave_count; i++) {
   164         m.getSlave(&slave, i);
   164         m.getSlave(&slave, i);
   165         
   165 
   166         if (slave.alias) {
   166         if (slave.alias) {
   167             lastAlias = slave.alias;
   167             lastAlias = slave.alias;
   168             aliasIndex = 0;
   168             aliasIndex = 0;
   169         }
   169         }
   170 
   170 
   182             info.relPos = str.str();
   182             info.relPos = str.str();
   183             str.str("");
   183             str.str("");
   184 
   184 
   185             info.state = alStateString(slave.al_state);
   185             info.state = alStateString(slave.al_state);
   186             info.flag = (slave.error_flag ? 'E' : '+');
   186             info.flag = (slave.error_flag ? 'E' : '+');
       
   187             info.device = slave.device_index;
   187 
   188 
   188             if (strlen(slave.name)) {
   189             if (strlen(slave.name)) {
   189                 info.name = slave.name;
   190                 info.name = slave.name;
   190             } else {
   191             } else {
   191                 str << "0x" << hex << setfill('0')
   192                 str << "0x" << hex << setfill('0')
   213 
   214 
   214     if (infoList.size() && doIndent) {
   215     if (infoList.size() && doIndent) {
   215         cout << "Master" << dec << m.getIndex() << endl;
   216         cout << "Master" << dec << m.getIndex() << endl;
   216     }
   217     }
   217 
   218 
       
   219     lastDevice = EC_DEVICE_MAIN;
   218     for (iter = infoList.begin(); iter != infoList.end(); iter++) {
   220     for (iter = infoList.begin(); iter != infoList.end(); iter++) {
       
   221         if (iter->device != lastDevice) {
       
   222             lastDevice = iter->device;
       
   223             cout << "xxx LINK FAILURE xxx" << endl;
       
   224         }
   219         cout << indent << setfill(' ') << right
   225         cout << indent << setfill(' ') << right
   220             << setw(maxPosWidth) << iter->pos << "  "
   226             << setw(maxPosWidth) << iter->pos << "  "
   221             << setw(maxAliasWidth) << iter->alias
   227             << setw(maxAliasWidth) << iter->alias
   222             << ":" << left
   228             << ":" << left
   223             << setw(maxRelPosWidth) << iter->relPos << "  "
   229             << setw(maxRelPosWidth) << iter->relPos << "  "
   243 
   249 
   244         if (si->alias)
   250         if (si->alias)
   245             cout << "Alias: " << si->alias << endl;
   251             cout << "Alias: " << si->alias << endl;
   246 
   252 
   247         cout
   253         cout
       
   254             << "Device: " << (si->device_index ? "Backup" : "Main") << endl
   248             << "State: " << alStateString(si->al_state) << endl
   255             << "State: " << alStateString(si->al_state) << endl
   249             << "Flag: " << (si->error_flag ? 'E' : '+') << endl
   256             << "Flag: " << (si->error_flag ? 'E' : '+') << endl
   250             << "Identity:" << endl
   257             << "Identity:" << endl
   251             << "  Vendor Id:       0x"
   258             << "  Vendor Id:       0x"
   252             << hex << setfill('0')
   259             << hex << setfill('0')
   287 
   294 
   288         cout << "Port  Type  Link  Loop    Signal  NextSlave";
   295         cout << "Port  Type  Link  Loop    Signal  NextSlave";
   289         if (si->dc_supported)
   296         if (si->dc_supported)
   290             cout << "  RxTime [ns]  Diff [ns]   NextDc [ns]";
   297             cout << "  RxTime [ns]  Diff [ns]   NextDc [ns]";
   291         cout << endl;
   298         cout << endl;
   292             
   299 
   293         for (i = 0; i < EC_MAX_PORTS; i++) {
   300         for (i = 0; i < EC_MAX_PORTS; i++) {
   294             cout << "   " << i << "  " << setfill(' ') << left << setw(4);
   301             cout << "   " << i << "  " << setfill(' ') << left << setw(4);
   295             switch (si->ports[i].desc) {
   302             switch (si->ports[i].desc) {
   296                 case EC_PORT_NOT_IMPLEMENTED:
   303                 case EC_PORT_NOT_IMPLEMENTED:
   297                     cout << "N/A";
   304                     cout << "N/A";
   320             if (si->ports[i].next_slave != 0xffff) {
   327             if (si->ports[i].next_slave != 0xffff) {
   321                 cout << dec << si->ports[i].next_slave;
   328                 cout << dec << si->ports[i].next_slave;
   322             } else {
   329             } else {
   323                 cout << "-";
   330                 cout << "-";
   324             }
   331             }
   325             
   332 
   326             if (si->dc_supported) {
   333             if (si->dc_supported) {
   327                 cout << "  " << setw(11) << right;
   334                 cout << "  " << setw(11) << right;
   328                 if (!si->ports[i].link.loop_closed) {
   335                 if (!si->ports[i].link.loop_closed) {
   329                     cout << dec << si->ports[i].receive_time;
   336                     cout << dec << si->ports[i].receive_time;
   330                 } else {
   337                 } else {
   331                     cout << "-";
   338                     cout << "-";
   332                 }
   339                 }
   333                 cout << "  " << setw(10);
   340                 cout << "  " << setw(10);
   334                 if (!si->ports[i].link.loop_closed) {
   341                 if (!si->ports[i].link.loop_closed) {
   335                     cout << si->ports[i].receive_time - si->ports[0].receive_time;
   342                     cout << si->ports[i].receive_time -
       
   343                         si->ports[0].receive_time;
   336                 } else {
   344                 } else {
   337                     cout << "-";
   345                     cout << "-";
   338                 }
   346                 }
   339                 cout << "  " << setw(10);
   347                 cout << "  " << setw(10);
   340                 if (!si->ports[i].link.loop_closed) {
   348                 if (!si->ports[i].link.loop_closed) {
   404             if (si->mailbox_protocols & EC_MBOX_COE) {
   412             if (si->mailbox_protocols & EC_MBOX_COE) {
   405                 cout << "  CoE details:" << endl
   413                 cout << "  CoE details:" << endl
   406                     << "    Enable SDO: "
   414                     << "    Enable SDO: "
   407                     << (si->coe_details.enable_sdo ? "yes" : "no") << endl
   415                     << (si->coe_details.enable_sdo ? "yes" : "no") << endl
   408                     << "    Enable SDO Info: "
   416                     << "    Enable SDO Info: "
   409                     << (si->coe_details.enable_sdo_info ? "yes" : "no") << endl
   417                     << (si->coe_details.enable_sdo_info ? "yes" : "no")
       
   418                     << endl
   410                     << "    Enable PDO Assign: "
   419                     << "    Enable PDO Assign: "
   411                     << (si->coe_details.enable_pdo_assign
   420                     << (si->coe_details.enable_pdo_assign
   412                             ? "yes" : "no") << endl
   421                             ? "yes" : "no") << endl
   413                     << "    Enable PDO Configuration: "
   422                     << "    Enable PDO Configuration: "
   414                     << (si->coe_details.enable_pdo_configuration
   423                     << (si->coe_details.enable_pdo_configuration