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@1144: str << getName() << " [OPTIONS]" << endl fp@1144: << endl fp@1144: << getBriefDescription() << 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@1147: << "1001:0 0x0000003b/0x02010000 3 OP" << endl fp@1142: << "| | | |" << endl fp@1147: << "| | | \\- Application-layer" << endl fp@1147: << "| | | state of the attached" << endl fp@1147: << "| | | slave, or '-', if no" << endl fp@1147: << "| | | slave is attached." << endl fp@1147: << "| | \\- Absolute decimal ring" << endl fp@1147: << "| | position of the attached" << endl fp@1147: << "| | slave, or '-' if none" << endl fp@1147: << "| | attached." << endl fp@1157: << "| \\- Expected vendor ID and product code (both" << endl fp@1144: << "| hexadecimal)." << endl fp@1157: << "\\- Alias address and relative position (both decimal)." << endl fp@1142: << endl fp@1686: << "With the --verbose option given, the configured PDOs and" << endl fp@1686: << "SDOs are output in addition." << endl fp@1157: << endl fp@1157: << "Configuration selection:" << endl fp@1157: << " Slave configurations 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@1167: << " is given, all slave configurations are displayed." << endl fp@1157: << " 2) If only the --position option is given, an alias" << endl fp@1157: << " of zero is assumed (see 4))." << endl fp@1157: << " 3) If only the --alias option is given, all slave" << endl fp@1157: << " configurations with the given alias address" << endl fp@1167: << " are displayed." << endl fp@1157: << " 4) If both the --alias and the --position option are" << endl fp@1167: << " given, the selection can match a single" << endl fp@1167: << " configuration, that is displayed, if it exists." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1157: << " --alias -a Configuration alias (see above)." << endl fp@1157: << " --position -p Relative position (see above)." << endl fp@1157: << " --verbose -v Show detailed configurations." << endl fp@1157: << endl fp@1157: << numericInfo(); fp@1142: fp@1142: return str.str(); 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@1156: ConfigList configs; fp@1142: fp@1142: m.open(MasterDevice::Read); fp@1156: configs = selectedConfigs(m); fp@1142: fp@1142: if (getVerbosity() == Verbose) { fp@1156: showDetailedConfigs(m, configs); fp@1142: } else { fp@1156: listConfigs(m, configs); 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@1147: ec_ioctl_slave_t slave; 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@1147: << "Attached slave: "; fp@1147: fp@1147: if (configIter->slave_position != -1) { fp@1147: m.getSlave(&slave, configIter->slave_position); fp@1172: cout << dec << configIter->slave_position fp@1148: << " (" << alStateString(slave.al_state) << ")" << endl; fp@1147: } else { fp@1147: cout << "none" << endl; fp@1147: } 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@1686: cout << " PDO 0x" << hex << setw(4) << pdo.index << 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@1686: cout << " PDO entry 0x" << hex << setfill('0') fp@1142: << setw(4) << entry.index << ":" fp@1142: << setw(2) << (unsigned int) entry.subindex fp@1188: << ", " << dec << setfill(' ') fp@1188: << setw(2) << (unsigned int) entry.bit_length fp@1188: << " bit" << endl; fp@1142: } fp@1142: } fp@1142: } fp@1142: } fp@1142: fp@1686: 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@1147: void CommandConfig::listConfigs( fp@1147: MasterDevice &m, fp@1147: const ConfigList &configList fp@1147: ) 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@1147: maxSlavePosWidth = 0, maxStateWidth = 0; fp@1147: ec_ioctl_slave_t slave; 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@1147: if (configIter->slave_position != -1) { fp@1147: m.getSlave(&slave, configIter->slave_position); fp@1147: fp@1172: str << dec << configIter->slave_position; fp@1147: info.slavePos = str.str(); fp@1147: str.clear(); fp@1147: str.str(""); fp@1147: fp@1148: str << alStateString(slave.al_state); fp@1147: info.state = str.str(); fp@1147: str.clear(); fp@1147: str.str(""); fp@1147: } else { fp@1147: str << "-"; fp@1147: info.slavePos = str.str(); fp@1147: str.clear(); fp@1147: str.str(""); fp@1147: fp@1147: str << "-"; fp@1147: info.state = str.str(); fp@1147: str.clear(); fp@1147: str.str(""); fp@1147: } 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@1147: if (info.slavePos.length() > maxSlavePosWidth) fp@1147: maxSlavePosWidth = info.slavePos.length(); fp@1147: if (info.state.length() > maxStateWidth) fp@1147: maxStateWidth = info.state.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@1147: << setw(maxSlavePosWidth) << iter->slavePos << " " fp@1147: << setw(maxStateWidth) << iter->state << " " fp@1142: << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/