fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandConfig.h" fp@1142: #include "byteorder.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandConfig::CommandConfig(): fp@1142: Command("config", "Show slave configurations.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: string CommandConfig::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1142: str << "[OPTIONS]" << endl fp@1142: << endl fp@1142: << "Output information about the slave configurations" << endl fp@1142: << "supplied by the application." << endl fp@1142: << endl fp@1142: << "Without the --verbose option, slave configurations are" << endl fp@1142: << "output one-per-line. Example:" << endl fp@1142: << endl fp@1142: << "1001:0 0x0000003b/0x02010000 - -" << endl fp@1142: << "| | | |" << endl fp@1142: << "| | | \\- Slave is operational." fp@1142: << endl fp@1142: << "| | \\- Slave has been found." << endl fp@1142: << "| \\- Hexadecimal vendor ID and product code, separated" fp@1142: << endl fp@1142: << "| by a slash." << endl fp@1142: << "\\- Decimal alias and position, separated by a colon." << endl fp@1142: << endl fp@1142: << "With the --verbose option given, the configured Pdos and" << endl fp@1142: << "Sdos are additionally printed." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --verbose -v Show detailed configurations." << endl; fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: bool operator<(const ec_ioctl_config_t &a, const ec_ioctl_config_t &b) fp@1142: { fp@1142: return a.alias < b.alias fp@1142: || (a.alias == b.alias && a.position < b.position); fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: /** Lists the bus configuration. fp@1142: */ fp@1142: void CommandConfig::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1142: ec_ioctl_master_t master; fp@1142: unsigned int i; fp@1142: ec_ioctl_config_t config; fp@1142: ConfigList configList; fp@1142: fp@1142: m.open(MasterDevice::Read); fp@1142: m.getMaster(&master); fp@1142: fp@1142: for (i = 0; i < master.config_count; i++) { fp@1142: m.getConfig(&config, i); fp@1142: configList.push_back(config); fp@1142: } fp@1142: fp@1142: configList.sort(); fp@1142: fp@1142: if (getVerbosity() == Verbose) { fp@1142: showDetailedConfigs(m, configList); fp@1142: } else { fp@1142: listConfigs(configList); fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: /** Lists the complete bus configuration. fp@1142: */ fp@1142: void CommandConfig::showDetailedConfigs( fp@1142: MasterDevice &m, fp@1142: const ConfigList &configList fp@1142: ) fp@1142: { fp@1142: ConfigList::const_iterator configIter; fp@1142: unsigned int j, k, l; fp@1142: ec_ioctl_config_pdo_t pdo; fp@1142: ec_ioctl_config_pdo_entry_t entry; fp@1142: ec_ioctl_config_sdo_t sdo; fp@1142: fp@1142: for (configIter = configList.begin(); fp@1142: configIter != configList.end(); fp@1142: configIter++) { fp@1142: fp@1142: cout << "Alias: " fp@1142: << dec << configIter->alias << endl fp@1142: << "Position: " << configIter->position << endl fp@1142: << "Vendor Id: 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(8) << configIter->vendor_id << endl fp@1142: << "Product code: 0x" fp@1142: << setw(8) << configIter->product_code << endl fp@1142: << "Attached: " << (configIter->attached ? "yes" : "no") << endl fp@1142: << "Operational: " << (configIter->operational ? "yes" : "no") << endl; fp@1142: fp@1142: for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { fp@1142: if (configIter->syncs[j].pdo_count) { fp@1142: cout << "SM" << dec << j << " (" fp@1142: << (configIter->syncs[j].dir == EC_DIR_INPUT fp@1142: ? "Input" : "Output") << ")" << endl; fp@1142: for (k = 0; k < configIter->syncs[j].pdo_count; k++) { fp@1142: m.getConfigPdo(&pdo, configIter->config_index, j, k); fp@1142: fp@1142: cout << " Pdo 0x" << hex fp@1142: << setw(4) << pdo.index fp@1142: << " \"" << pdo.name << "\"" << endl; fp@1142: fp@1142: for (l = 0; l < pdo.entry_count; l++) { fp@1142: m.getConfigPdoEntry(&entry, fp@1142: configIter->config_index, j, k, l); fp@1142: fp@1142: cout << " Pdo entry 0x" << hex fp@1142: << setw(4) << entry.index << ":" fp@1142: << setw(2) << (unsigned int) entry.subindex fp@1142: << ", " << dec << (unsigned int) entry.bit_length fp@1142: << " bit, \"" << entry.name << "\"" << endl; fp@1142: } fp@1142: } fp@1142: } fp@1142: } fp@1142: fp@1142: cout << "Sdo configuration:" << endl; fp@1142: if (configIter->sdo_count) { fp@1142: for (j = 0; j < configIter->sdo_count; j++) { fp@1142: m.getConfigSdo(&sdo, configIter->config_index, j); fp@1142: fp@1142: cout << " 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(4) << sdo.index << ":" fp@1142: << setw(2) << (unsigned int) sdo.subindex fp@1142: << ", " << dec << sdo.size << " byte: " << hex; fp@1142: fp@1142: switch (sdo.size) { fp@1142: case 1: fp@1142: cout << "0x" << setw(2) fp@1142: << (unsigned int) *(uint8_t *) &sdo.data; fp@1142: break; fp@1142: case 2: fp@1142: cout << "0x" << setw(4) fp@1142: << le16tocpu(*(uint16_t *) &sdo.data); fp@1142: break; fp@1142: case 4: fp@1142: cout << "0x" << setw(8) fp@1142: << le32tocpu(*(uint32_t *) &sdo.data); fp@1142: break; fp@1142: default: fp@1142: cout << "???"; fp@1142: } fp@1142: fp@1142: cout << endl; fp@1142: } fp@1142: } else { fp@1142: cout << " None." << endl; fp@1142: } fp@1142: fp@1142: cout << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: /** Lists the bus configuration. fp@1142: */ fp@1142: void CommandConfig::listConfigs(const ConfigList &configList) fp@1142: { fp@1142: ConfigList::const_iterator configIter; fp@1142: stringstream str; fp@1142: Info info; fp@1142: typedef list InfoList; fp@1142: InfoList list; fp@1142: InfoList::const_iterator iter; fp@1142: unsigned int maxAliasWidth = 0, maxPosWidth = 0, fp@1142: maxAttWidth = 0, maxOpWidth = 0; fp@1142: fp@1142: for (configIter = configList.begin(); fp@1142: configIter != configList.end(); fp@1142: configIter++) { fp@1142: fp@1142: str << dec << configIter->alias; fp@1142: info.alias = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: str << configIter->position; fp@1142: info.pos = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: str << hex << setfill('0') fp@1142: << "0x" << setw(8) << configIter->vendor_id fp@1142: << "/0x" << setw(8) << configIter->product_code; fp@1142: info.ident = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: str << (configIter->attached ? "attached" : "-"); fp@1142: info.att = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: str << (configIter->operational ? "operational" : "-"); fp@1142: info.op = str.str(); fp@1142: str.clear(); fp@1142: str.str(""); fp@1142: fp@1142: list.push_back(info); fp@1142: fp@1142: if (info.alias.length() > maxAliasWidth) fp@1142: maxAliasWidth = info.alias.length(); fp@1142: if (info.pos.length() > maxPosWidth) fp@1142: maxPosWidth = info.pos.length(); fp@1142: if (info.att.length() > maxAttWidth) fp@1142: maxAttWidth = info.att.length(); fp@1142: if (info.op.length() > maxOpWidth) fp@1142: maxOpWidth = info.op.length(); fp@1142: } fp@1142: fp@1142: for (iter = list.begin(); iter != list.end(); iter++) { fp@1142: cout << setfill(' ') << right fp@1142: << setw(maxAliasWidth) << iter->alias fp@1142: << ":" << left fp@1142: << setw(maxPosWidth) << iter->pos fp@1142: << " " fp@1142: << iter->ident fp@1142: << " " fp@1142: << setw(maxAttWidth) << iter->att << " " fp@1142: << setw(maxOpWidth) << iter->op << " " fp@1142: << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/