tool/CommandSlaves.cpp
changeset 1151 1fc1535dec29
parent 1148 1762296870bd
child 1157 04d1c950cf9d
equal deleted inserted replaced
1150:c589b54ade01 1151:1fc1535dec29
    63 
    63 
    64 /****************************************************************************/
    64 /****************************************************************************/
    65 
    65 
    66 void CommandSlaves::execute(MasterDevice &m, const StringVector &args)
    66 void CommandSlaves::execute(MasterDevice &m, const StringVector &args)
    67 {
    67 {
       
    68     SlaveList slaves;
       
    69     
    68     m.open(MasterDevice::Read);
    70     m.open(MasterDevice::Read);
       
    71     slaves = selectedSlaves(m);
    69 
    72 
    70     if (getVerbosity() == Verbose) {
    73     if (getVerbosity() == Verbose) {
    71         if (slavePosition == -1) {
    74         showSlaves(m, slaves);
    72             unsigned int numSlaves = m.slaveCount(), i;
       
    73 
       
    74             for (i = 0; i < numSlaves; i++) {
       
    75                 showSlave(m, i);
       
    76             }
       
    77         } else {
       
    78             showSlave(m, slavePosition);
       
    79         }
       
    80     } else {
    75     } else {
    81         listSlaves(m, slavePosition);
    76         listSlaves(m, slaves);
    82     }
    77     }
    83 }
    78 }
    84 
    79 
    85 /****************************************************************************/
    80 /****************************************************************************/
    86 
    81 
    87 void CommandSlaves::listSlaves(
    82 void CommandSlaves::listSlaves(
    88         MasterDevice &m,
    83         MasterDevice &m,
    89         int slavePosition
    84         const SlaveList &slaves
    90         )
    85         )
    91 {
    86 {
    92     unsigned int numSlaves, i;
    87     unsigned int numSlaves, i;
    93     ec_ioctl_slave_t slave;
    88     ec_ioctl_slave_t slave;
    94     uint16_t lastAlias, aliasIndex;
    89     uint16_t lastAlias, aliasIndex;
   110         if (slave.alias) {
   105         if (slave.alias) {
   111             lastAlias = slave.alias;
   106             lastAlias = slave.alias;
   112             aliasIndex = 0;
   107             aliasIndex = 0;
   113         }
   108         }
   114 
   109 
   115         if (slavePosition == -1 || i == (unsigned int) slavePosition) {
   110         if (slaveInList(slave, slaves)) {
   116             str << dec << i;
   111             str << dec << i;
   117             info.pos = str.str();
   112             info.pos = str.str();
   118             str.clear();
   113             str.clear();
   119             str.str("");
   114             str.str("");
   120 
   115 
   167     }
   162     }
   168 }
   163 }
   169 
   164 
   170 /****************************************************************************/
   165 /****************************************************************************/
   171 
   166 
   172 void CommandSlaves::showSlave(
   167 void CommandSlaves::showSlaves(
   173         MasterDevice &m,
   168         MasterDevice &m,
   174         uint16_t slavePosition
   169         const SlaveList &slaves
   175         )
   170         )
   176 {
   171 {
   177     ec_ioctl_slave_t slave;
   172     SlaveList::const_iterator si;
   178     list<string> protoList;
   173     list<string> protoList;
   179     list<string>::const_iterator protoIter;
   174     list<string>::const_iterator protoIter;
   180     
   175 
   181     m.getSlave(&slave, slavePosition);
   176     for (si = slaves.begin(); si != slaves.end(); si++) {
   182         
   177         cout << "=== Slave " << dec << si->position << " ===" << endl;
   183     cout << "=== Slave " << dec << slavePosition << " ===" << endl;
   178 
   184     
   179         if (si->alias)
   185     if (slave.alias)
   180             cout << "Alias: " << si->alias << endl;
   186         cout << "Alias: " << slave.alias << endl;
   181 
   187 
   182         cout
   188     cout
   183             << "State: " << alStateString(si->al_state) << endl
   189         << "State: " << alStateString(slave.al_state) << endl
   184             << "Flag: " << (si->error_flag ? 'E' : '+') << endl
   190         << "Flag: " << (slave.error_flag ? 'E' : '+') << endl
   185             << "Identity:" << endl
   191         << "Identity:" << endl
   186             << "  Vendor Id:       0x"
   192         << "  Vendor Id:       0x"
   187             << hex << setfill('0')
   193         << hex << setfill('0')
   188             << setw(8) << si->vendor_id << endl
   194         << setw(8) << slave.vendor_id << endl
   189             << "  Product code:    0x"
   195         << "  Product code:    0x"
   190             << setw(8) << si->product_code << endl
   196         << setw(8) << slave.product_code << endl
   191             << "  Revision number: 0x"
   197         << "  Revision number: 0x"
   192             << setw(8) << si->revision_number << endl
   198         << setw(8) << slave.revision_number << endl
   193             << "  Serial number:   0x"
   199         << "  Serial number:   0x"
   194             << setw(8) << si->serial_number << endl;
   200         << setw(8) << slave.serial_number << endl;
   195 
   201 
   196         if (si->mailbox_protocols) {
   202     if (slave.mailbox_protocols) {
   197             cout << "Mailboxes:" << endl
   203         cout << "Mailboxes:" << endl
   198                 << "  RX: 0x"
   204         << "  RX: 0x"
   199                 << hex << setw(4) << si->rx_mailbox_offset << "/"
   205         << hex << setw(4) << slave.rx_mailbox_offset << "/"
   200                 << dec << si->rx_mailbox_size
   206         << dec << slave.rx_mailbox_size
   201                 << ", TX: 0x"
   207         << ", TX: 0x"
   202                 << hex << setw(4) << si->tx_mailbox_offset << "/"
   208         << hex << setw(4) << slave.tx_mailbox_offset << "/"
   203                 << dec << si->tx_mailbox_size << endl
   209         << dec << slave.tx_mailbox_size << endl
   204                 << "  Supported protocols: ";
   210         << "  Supported protocols: ";
   205 
   211 
   206             if (si->mailbox_protocols & EC_MBOX_AOE) {
   212         if (slave.mailbox_protocols & EC_MBOX_AOE) {
   207                 protoList.push_back("AoE");
   213             protoList.push_back("AoE");
   208             }
   214         }
   209             if (si->mailbox_protocols & EC_MBOX_EOE) {
   215         if (slave.mailbox_protocols & EC_MBOX_EOE) {
   210                 protoList.push_back("EoE");
   216             protoList.push_back("EoE");
   211             }
   217         }
   212             if (si->mailbox_protocols & EC_MBOX_COE) {
   218         if (slave.mailbox_protocols & EC_MBOX_COE) {
   213                 protoList.push_back("CoE");
   219             protoList.push_back("CoE");
   214             }
   220         }
   215             if (si->mailbox_protocols & EC_MBOX_FOE) {
   221         if (slave.mailbox_protocols & EC_MBOX_FOE) {
   216                 protoList.push_back("FoE");
   222             protoList.push_back("FoE");
   217             }
   223         }
   218             if (si->mailbox_protocols & EC_MBOX_SOE) {
   224         if (slave.mailbox_protocols & EC_MBOX_SOE) {
   219                 protoList.push_back("SoE");
   225             protoList.push_back("SoE");
   220             }
   226         }
   221             if (si->mailbox_protocols & EC_MBOX_VOE) {
   227         if (slave.mailbox_protocols & EC_MBOX_VOE) {
   222                 protoList.push_back("VoE");
   228             protoList.push_back("VoE");
   223             }
   229         }
   224 
   230 
   225             for (protoIter = protoList.begin(); protoIter != protoList.end();
   231         for (protoIter = protoList.begin(); protoIter != protoList.end();
   226                     protoIter++) {
   232                 protoIter++) {
   227                 if (protoIter != protoList.begin())
   233             if (protoIter != protoList.begin())
   228                     cout << ", ";
   234                 cout << ", ";
   229                 cout << *protoIter;
   235             cout << *protoIter;
   230             }
   236         }
   231             cout << endl;
   237         cout << endl;
   232         }
   238     }
   233 
   239 
   234         if (si->has_general_category) {
   240     if (slave.has_general_category) {
   235             cout << "General:" << endl
   241         cout << "General:" << endl
   236                 << "  Group: " << si->group << endl
   242             << "  Group: " << slave.group << endl
   237                 << "  Image name: " << si->image << endl
   243             << "  Image name: " << slave.image << endl
   238                 << "  Order number: " << si->order << endl
   244             << "  Order number: " << slave.order << endl
   239                 << "  Device name: " << si->name << endl;
   245             << "  Device name: " << slave.name << endl;
   240 
   246 
   241             if (si->mailbox_protocols & EC_MBOX_COE) {
   247         if (slave.mailbox_protocols & EC_MBOX_COE) {
   242                 cout << "  CoE details:" << endl
   248             cout << "  CoE details:" << endl
   243                     << "    Enable Sdo: "
   249                 << "    Enable Sdo: "
   244                     << (si->coe_details.enable_sdo ? "yes" : "no") << endl
   250                 << (slave.coe_details.enable_sdo ? "yes" : "no") << endl
   245                     << "    Enable Sdo Info: "
   251                 << "    Enable Sdo Info: "
   246                     << (si->coe_details.enable_sdo_info ? "yes" : "no") << endl
   252                 << (slave.coe_details.enable_sdo_info ? "yes" : "no") << endl
   247                     << "    Enable Pdo Assign: "
   253                 << "    Enable Pdo Assign: "
   248                     << (si->coe_details.enable_pdo_assign
   254                 << (slave.coe_details.enable_pdo_assign
   249                             ? "yes" : "no") << endl
   255                         ? "yes" : "no") << endl
   250                     << "    Enable Pdo Configuration: "
   256                 << "    Enable Pdo Configuration: "
   251                     << (si->coe_details.enable_pdo_configuration
   257                 << (slave.coe_details.enable_pdo_configuration
   252                             ? "yes" : "no") << endl
   258                         ? "yes" : "no") << endl
   253                     << "    Enable Upload at startup: "
   259                 << "    Enable Upload at startup: "
   254                     << (si->coe_details.enable_upload_at_startup
   260                 << (slave.coe_details.enable_upload_at_startup
   255                             ? "yes" : "no") << endl
   261                         ? "yes" : "no") << endl
   256                     << "    Enable Sdo complete access: "
   262                 << "    Enable Sdo complete access: "
   257                     << (si->coe_details.enable_sdo_complete_access
   263                 << (slave.coe_details.enable_sdo_complete_access
   258                             ? "yes" : "no") << endl;
   264                         ? "yes" : "no") << endl;
   259             }
   265         }
   260 
   266 
   261             cout << "  Flags:" << endl
   267         cout << "  Flags:" << endl
   262                 << "    Enable SafeOp: "
   268             << "    Enable SafeOp: "
   263                 << (si->general_flags.enable_safeop ? "yes" : "no") << endl
   269             << (slave.general_flags.enable_safeop ? "yes" : "no") << endl
   264                 << "    Enable notLRW: "
   270             << "    Enable notLRW: "
   265                 << (si->general_flags.enable_not_lrw ? "yes" : "no") << endl
   271             << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl
   266                 << "  Current consumption: "
   272             << "  Current consumption: "
   267                 << dec << si->current_on_ebus << " mA" << endl;
   273             << dec << slave.current_on_ebus << " mA" << endl;
   268         }
   274     }
   269     }
       
   270 }
       
   271 
       
   272 /****************************************************************************/
       
   273 
       
   274 bool CommandSlaves::slaveInList(
       
   275         const ec_ioctl_slave_t &slave,
       
   276         const SlaveList &slaves
       
   277         )
       
   278 {
       
   279     SlaveList::const_iterator si;
       
   280 
       
   281     for (si = slaves.begin(); si != slaves.end(); si++) {
       
   282         if (si->position == slave.position) {
       
   283             return true;
       
   284         }
       
   285     }
       
   286 
       
   287     return false;
   275 }
   288 }
   276 
   289 
   277 /*****************************************************************************/
   290 /*****************************************************************************/