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@1142: << "| | | | | \\- Name from SII if avaliable," << endl fp@1142: << "| | | | | otherwise hexadecimal vendor ID" << endl fp@1142: << "| | | | | and product code separated by a" << endl fp@1142: << "| | | | | colon." << endl fp@1142: << "| | | | \\- Error flag. '+' means no error," << endl fp@1142: << "| | | | 'E' means that scanning or" << endl fp@1142: << "| | | | configuration failed." << endl fp@1142: << "| | | \\- Current slave state." << endl fp@1142: << "| | \\- Relative position (decimal) after the last" << endl fp@1142: << "| | slave with an alias address set." << endl fp@1142: << "| \\- Alias address of the slave (if set to non-zero)," << endl fp@1142: << "| or the alias of the last slave with an alias set," << endl fp@1142: << "| or zero if there is none." << endl fp@1142: << "\\- Ring position (use this with any --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@1142: info.state = slaveState(slave.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@1142: << "State: " << slaveState(slave.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: /****************************************************************************/ fp@1142: fp@1142: string CommandSlaves::slaveState(uint8_t state) fp@1142: { fp@1142: switch (state) { fp@1142: case 1: return "INIT"; fp@1142: case 2: return "PREOP"; fp@1142: case 4: return "SAFEOP"; fp@1142: case 8: return "OP"; fp@1142: default: return "???"; fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/