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