fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandSlaves.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandSlaves::CommandSlaves(): fp@1142: Command("slaves", "Display slaves on the bus.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: string CommandSlaves::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1142: str << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "If the --verbose option is not given, the slaves are" << endl fp@1142: << "displayed one-per-line. Example:" << endl fp@1142: << endl fp@1142: << "1 5555:0 PREOP + EL3162 2C. Ana. Input 0-10V" << endl fp@1142: << "| | | | | |" << endl fp@1144: << "| | | | | \\- Name from the SII if avaliable," << endl fp@1144: << "| | | | | otherwise vendor ID and product" << endl fp@1144: << "| | | | | code (both hexadecimal)." << endl fp@1142: << "| | | | \\- Error flag. '+' means no error," << endl fp@1144: << "| | | | 'E' means that scan or" << endl fp@1142: << "| | | | configuration failed." << endl fp@1144: << "| | | \\- Current application-layer state." << endl fp@1142: << "| | \\- Relative position (decimal) after the last" << endl fp@1142: << "| | slave with an alias address set." << endl fp@1144: << "| \\- Alias address of the slave (if set), or the alias" << endl fp@1144: << "| of the last slave with an alias, or zero if not" << endl fp@1144: << "| applicable" << endl fp@1144: << "\\- Absolute ring position in the bus (use this with any" << endl fp@1144: << " --slave option)." << endl fp@1142: << endl fp@1142: << "If the --verbose option is given, a detailed (multi-line)" << endl fp@1142: << "description is output for each slave." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --slave -s Positive numerical ring position," << endl fp@1142: << " or 'all' for all slaves (default)." << endl fp@1142: << " --verbose -v Show detailed slave information." << endl fp@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSlaves::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1142: m.open(MasterDevice::Read); fp@1142: fp@1142: if (getVerbosity() == Verbose) { fp@1142: if (slavePosition == -1) { fp@1142: unsigned int numSlaves = m.slaveCount(), i; fp@1142: fp@1142: for (i = 0; i < numSlaves; i++) { fp@1142: showSlave(m, i); fp@1142: } fp@1142: } else { fp@1142: showSlave(m, slavePosition); fp@1142: } fp@1142: } else { fp@1142: listSlaves(m, slavePosition); fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSlaves::listSlaves( fp@1142: MasterDevice &m, fp@1142: int slavePosition fp@1142: ) fp@1142: { fp@1142: unsigned int numSlaves, i; fp@1142: ec_ioctl_slave_t slave; fp@1142: uint16_t lastAlias, aliasIndex; fp@1142: Info info; fp@1142: typedef list InfoList; fp@1142: InfoList infoList; fp@1142: InfoList::const_iterator iter; fp@1142: stringstream str; fp@1142: unsigned int maxPosWidth = 0, maxAliasWidth = 0, fp@1142: maxRelPosWidth = 0, maxStateWidth = 0; fp@1142: fp@1142: numSlaves = m.slaveCount(); fp@1142: fp@1142: lastAlias = 0; fp@1142: aliasIndex = 0; fp@1142: for (i = 0; i < numSlaves; i++) { fp@1142: m.getSlave(&slave, i); fp@1142: fp@1142: if (slave.alias) { fp@1142: lastAlias = slave.alias; fp@1142: aliasIndex = 0; fp@1142: } fp@1142: fp@1142: if (slavePosition == -1 || i == (unsigned int) slavePosition) { fp@1142: str << dec << i; fp@1142: info.pos = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: str << lastAlias; fp@1142: info.alias = str.str(); fp@1142: str.str(""); fp@1142: fp@1142: str << aliasIndex; fp@1142: info.relPos = str.str(); fp@1142: str.str(""); fp@1142: fp@1148: info.state = alStateString(slave.al_state); fp@1142: info.flag = (slave.error_flag ? 'E' : '+'); fp@1142: fp@1142: if (strlen(slave.name)) { fp@1142: info.name = slave.name; fp@1142: } else { fp@1142: str << "0x" << hex << setfill('0') fp@1142: << setw(8) << slave.vendor_id << ":0x" fp@1142: << setw(8) << slave.product_code; fp@1142: info.name = str.str(); fp@1142: str.str(""); fp@1142: } fp@1142: fp@1142: fp@1142: infoList.push_back(info); fp@1142: fp@1142: if (info.pos.length() > maxPosWidth) fp@1142: maxPosWidth = info.pos.length(); fp@1142: if (info.alias.length() > maxAliasWidth) fp@1142: maxAliasWidth = info.alias.length(); fp@1142: if (info.relPos.length() > maxRelPosWidth) fp@1142: maxRelPosWidth = info.relPos.length(); fp@1142: if (info.state.length() > maxStateWidth) fp@1142: maxStateWidth = info.state.length(); fp@1142: } fp@1142: fp@1142: aliasIndex++; fp@1142: } fp@1142: fp@1142: for (iter = infoList.begin(); iter != infoList.end(); iter++) { fp@1142: cout << setfill(' ') << right fp@1142: << setw(maxPosWidth) << iter->pos << " " fp@1142: << setw(maxAliasWidth) << iter->alias fp@1142: << ":" << left fp@1142: << setw(maxRelPosWidth) << iter->relPos << " " fp@1142: << setw(maxStateWidth) << iter->state << " " fp@1142: << iter->flag << " " fp@1142: << iter->name << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSlaves::showSlave( fp@1142: MasterDevice &m, fp@1142: uint16_t slavePosition fp@1142: ) fp@1142: { fp@1142: ec_ioctl_slave_t slave; fp@1142: list protoList; fp@1142: list::const_iterator protoIter; fp@1142: fp@1142: m.getSlave(&slave, slavePosition); fp@1142: fp@1142: cout << "=== Slave " << dec << slavePosition << " ===" << endl; fp@1142: fp@1142: if (slave.alias) fp@1142: cout << "Alias: " << slave.alias << endl; fp@1142: fp@1142: cout fp@1148: << "State: " << alStateString(slave.al_state) << endl fp@1142: << "Flag: " << (slave.error_flag ? 'E' : '+') << endl fp@1142: << "Identity:" << endl fp@1142: << " Vendor Id: 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(8) << slave.vendor_id << endl fp@1142: << " Product code: 0x" fp@1142: << setw(8) << slave.product_code << endl fp@1142: << " Revision number: 0x" fp@1142: << setw(8) << slave.revision_number << endl fp@1142: << " Serial number: 0x" fp@1142: << setw(8) << slave.serial_number << endl; fp@1142: fp@1142: if (slave.mailbox_protocols) { fp@1142: cout << "Mailboxes:" << endl fp@1142: << " RX: 0x" fp@1142: << hex << setw(4) << slave.rx_mailbox_offset << "/" fp@1142: << dec << slave.rx_mailbox_size fp@1142: << ", TX: 0x" fp@1142: << hex << setw(4) << slave.tx_mailbox_offset << "/" fp@1142: << dec << slave.tx_mailbox_size << endl fp@1142: << " Supported protocols: "; fp@1142: fp@1142: if (slave.mailbox_protocols & EC_MBOX_AOE) { fp@1142: protoList.push_back("AoE"); fp@1142: } fp@1142: if (slave.mailbox_protocols & EC_MBOX_EOE) { fp@1142: protoList.push_back("EoE"); fp@1142: } fp@1142: if (slave.mailbox_protocols & EC_MBOX_COE) { fp@1142: protoList.push_back("CoE"); fp@1142: } fp@1142: if (slave.mailbox_protocols & EC_MBOX_FOE) { fp@1142: protoList.push_back("FoE"); fp@1142: } fp@1142: if (slave.mailbox_protocols & EC_MBOX_SOE) { fp@1142: protoList.push_back("SoE"); fp@1142: } fp@1142: if (slave.mailbox_protocols & EC_MBOX_VOE) { fp@1142: protoList.push_back("VoE"); fp@1142: } fp@1142: fp@1142: for (protoIter = protoList.begin(); protoIter != protoList.end(); fp@1142: protoIter++) { fp@1142: if (protoIter != protoList.begin()) fp@1142: cout << ", "; fp@1142: cout << *protoIter; fp@1142: } fp@1142: cout << endl; fp@1142: } fp@1142: fp@1142: if (slave.has_general_category) { fp@1142: cout << "General:" << endl fp@1142: << " Group: " << slave.group << endl fp@1142: << " Image name: " << slave.image << endl fp@1142: << " Order number: " << slave.order << endl fp@1142: << " Device name: " << slave.name << endl; fp@1142: fp@1142: if (slave.mailbox_protocols & EC_MBOX_COE) { fp@1142: cout << " CoE details:" << endl fp@1142: << " Enable Sdo: " fp@1142: << (slave.coe_details.enable_sdo ? "yes" : "no") << endl fp@1142: << " Enable Sdo Info: " fp@1142: << (slave.coe_details.enable_sdo_info ? "yes" : "no") << endl fp@1142: << " Enable Pdo Assign: " fp@1142: << (slave.coe_details.enable_pdo_assign fp@1142: ? "yes" : "no") << endl fp@1142: << " Enable Pdo Configuration: " fp@1142: << (slave.coe_details.enable_pdo_configuration fp@1142: ? "yes" : "no") << endl fp@1142: << " Enable Upload at startup: " fp@1142: << (slave.coe_details.enable_upload_at_startup fp@1142: ? "yes" : "no") << endl fp@1142: << " Enable Sdo complete access: " fp@1142: << (slave.coe_details.enable_sdo_complete_access fp@1142: ? "yes" : "no") << endl; fp@1142: } fp@1142: fp@1142: cout << " Flags:" << endl fp@1142: << " Enable SafeOp: " fp@1142: << (slave.general_flags.enable_safeop ? "yes" : "no") << endl fp@1142: << " Enable notLRW: " fp@1142: << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl fp@1142: << " Current consumption: " fp@1142: << dec << slave.current_on_ebus << " mA" << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/