fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: #include fp@1636: #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@1157: << "| | \\- Decimal relative position to the last" << endl fp@1142: << "| | slave with an alias address set." << endl fp@1157: << "| \\- Decimal alias address of this slave (if set)," << endl fp@1157: << "| otherwise of the last slave with an alias set," << endl fp@1157: << "| or zero, if no alias was encountered up to this" << endl fp@1157: << "| position." << endl fp@1157: << "\\- Absolute ring position in the bus." << 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@1157: << "Slave selection:" << endl fp@1157: << " Slaves for this and other commands can be selected with" << endl fp@1157: << " the --alias and --position parameters as follows:" << endl fp@1157: << endl fp@1157: << " 1) If neither the --alias nor the --position option" << endl fp@1157: << " is given, all slaves are selected." << endl fp@1157: << " 2) If only the --position option is given, it is" << endl fp@1157: << " interpreted as an absolute ring position and" << endl fp@1157: << " a slave with this position is matched." << endl fp@1157: << " 3) If only the --alias option is given, all slaves" << endl fp@1157: << " with the given alias address and subsequent" << endl fp@1157: << " slaves before a slave with a different alias" << endl fp@1157: << " address match (use -p0 if only the slaves" << endl fp@1157: << " with the given alias are desired, see 4))." << endl fp@1157: << " 4) If both the --alias and the --position option are" << endl fp@1157: << " given, the latter is interpreted as relative" << endl fp@1157: << " position behind any slave with the given alias." << endl fp@1157: << endl fp@1142: << "Command-specific options:" << endl fp@1157: << " --alias -a Slave alias (see above)." << endl fp@1157: << " --position -p Slave position (see above)." << endl fp@1157: << " --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@1151: SlaveList slaves; fp@1151: fp@1142: m.open(MasterDevice::Read); fp@1151: slaves = selectedSlaves(m); fp@1142: fp@1142: if (getVerbosity() == Verbose) { fp@1151: showSlaves(m, slaves); fp@1142: } else { fp@1151: listSlaves(m, slaves); fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSlaves::listSlaves( fp@1142: MasterDevice &m, fp@1151: const SlaveList &slaves fp@1142: ) fp@1142: { fp@1160: ec_ioctl_master_t master; fp@1160: unsigned int 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@1160: m.getMaster(&master); fp@1142: fp@1142: lastAlias = 0; fp@1142: aliasIndex = 0; fp@1160: for (i = 0; i < master.slave_count; 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@1151: if (slaveInList(slave, slaves)) { 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@1151: void CommandSlaves::showSlaves( fp@1142: MasterDevice &m, fp@1151: const SlaveList &slaves fp@1142: ) fp@1142: { fp@1151: SlaveList::const_iterator si; fp@1151: fp@1151: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1151: cout << "=== Slave " << dec << si->position << " ===" << endl; fp@1151: fp@1151: if (si->alias) fp@1151: cout << "Alias: " << si->alias << endl; fp@1151: fp@1151: cout fp@1151: << "State: " << alStateString(si->al_state) << endl fp@1151: << "Flag: " << (si->error_flag ? 'E' : '+') << endl fp@1151: << "Identity:" << endl fp@1151: << " Vendor Id: 0x" fp@1151: << hex << setfill('0') fp@1151: << setw(8) << si->vendor_id << endl fp@1151: << " Product code: 0x" fp@1151: << setw(8) << si->product_code << endl fp@1151: << " Revision number: 0x" fp@1151: << setw(8) << si->revision_number << endl fp@1151: << " Serial number: 0x" fp@1151: << setw(8) << si->serial_number << endl; fp@1151: fp@1151: if (si->mailbox_protocols) { fp@1634: list protoList; fp@1634: list::const_iterator protoIter; fp@1634: fp@1151: cout << "Mailboxes:" << endl fp@1709: << " Bootstrap RX: 0x" fp@1709: << hex << setw(4) << si->boot_rx_mailbox_offset << "/" fp@1709: << dec << si->boot_rx_mailbox_size fp@1151: << ", TX: 0x" fp@1709: << hex << setw(4) << si->boot_tx_mailbox_offset << "/" fp@1709: << dec << si->boot_tx_mailbox_size << endl fp@1709: << " Standard RX: 0x" fp@1709: << hex << setw(4) << si->std_rx_mailbox_offset << "/" fp@1709: << dec << si->std_rx_mailbox_size fp@1709: << ", TX: 0x" fp@1709: << hex << setw(4) << si->std_tx_mailbox_offset << "/" fp@1709: << dec << si->std_tx_mailbox_size << endl fp@1151: << " Supported protocols: "; fp@1151: fp@1151: if (si->mailbox_protocols & EC_MBOX_AOE) { fp@1151: protoList.push_back("AoE"); fp@1151: } fp@1151: if (si->mailbox_protocols & EC_MBOX_EOE) { fp@1151: protoList.push_back("EoE"); fp@1151: } fp@1151: if (si->mailbox_protocols & EC_MBOX_COE) { fp@1151: protoList.push_back("CoE"); fp@1151: } fp@1151: if (si->mailbox_protocols & EC_MBOX_FOE) { fp@1151: protoList.push_back("FoE"); fp@1151: } fp@1151: if (si->mailbox_protocols & EC_MBOX_SOE) { fp@1151: protoList.push_back("SoE"); fp@1151: } fp@1151: if (si->mailbox_protocols & EC_MBOX_VOE) { fp@1151: protoList.push_back("VoE"); fp@1151: } fp@1151: fp@1151: for (protoIter = protoList.begin(); protoIter != protoList.end(); fp@1151: protoIter++) { fp@1151: if (protoIter != protoList.begin()) fp@1151: cout << ", "; fp@1151: cout << *protoIter; fp@1151: } fp@1151: cout << endl; fp@1151: } fp@1151: fp@1151: if (si->has_general_category) { fp@1151: cout << "General:" << endl fp@1151: << " Group: " << si->group << endl fp@1151: << " Image name: " << si->image << endl fp@1151: << " Order number: " << si->order << endl fp@1151: << " Device name: " << si->name << endl; fp@1151: fp@1151: if (si->mailbox_protocols & EC_MBOX_COE) { fp@1151: cout << " CoE details:" << endl fp@1686: << " Enable SDO: " fp@1151: << (si->coe_details.enable_sdo ? "yes" : "no") << endl fp@1686: << " Enable SDO Info: " fp@1151: << (si->coe_details.enable_sdo_info ? "yes" : "no") << endl fp@1686: << " Enable PDO Assign: " fp@1151: << (si->coe_details.enable_pdo_assign fp@1151: ? "yes" : "no") << endl fp@1686: << " Enable PDO Configuration: " fp@1151: << (si->coe_details.enable_pdo_configuration fp@1151: ? "yes" : "no") << endl fp@1151: << " Enable Upload at startup: " fp@1151: << (si->coe_details.enable_upload_at_startup fp@1151: ? "yes" : "no") << endl fp@1686: << " Enable SDO complete access: " fp@1151: << (si->coe_details.enable_sdo_complete_access fp@1151: ? "yes" : "no") << endl; fp@1151: } fp@1151: fp@1151: cout << " Flags:" << endl fp@1151: << " Enable SafeOp: " fp@1151: << (si->general_flags.enable_safeop ? "yes" : "no") << endl fp@1151: << " Enable notLRW: " fp@1151: << (si->general_flags.enable_not_lrw ? "yes" : "no") << endl fp@1151: << " Current consumption: " fp@1151: << dec << si->current_on_ebus << " mA" << endl; fp@1151: } fp@1151: } fp@1151: } fp@1151: fp@1151: /****************************************************************************/ fp@1151: fp@1151: bool CommandSlaves::slaveInList( fp@1151: const ec_ioctl_slave_t &slave, fp@1151: const SlaveList &slaves fp@1151: ) fp@1151: { fp@1151: SlaveList::const_iterator si; fp@1151: fp@1151: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1151: if (si->position == slave.position) { fp@1151: return true; fp@1151: } fp@1151: } fp@1151: fp@1151: return false; fp@1142: } fp@1142: fp@1142: /*****************************************************************************/