fp@1142: /***************************************************************************** fp@1142: * fp@1363: * $Id$ fp@1363: * fp@1363: * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH fp@1363: * fp@1363: * This file is part of the IgH EtherCAT Master. fp@1363: * fp@1363: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1363: * modify it under the terms of the GNU General Public License version 2, as fp@1363: * published by the Free Software Foundation. fp@1363: * fp@1363: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1363: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1363: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1363: * Public License for more details. fp@1363: * fp@1363: * You should have received a copy of the GNU General Public License along fp@1363: * with the IgH EtherCAT Master; if not, write to the Free Software fp@1363: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1363: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@1142: * fp@1880: * vim: expandtab fp@1880: * 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@1826: #include "MasterDevice.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@1968: string CommandConfig::helpString(const string &binaryBaseName) const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1968: str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl fp@1804: << endl fp@1804: << getBriefDescription() << endl fp@1804: << endl fp@1804: << "Without the --verbose option, slave configurations are" << endl fp@1804: << "output one-per-line. Example:" << endl fp@1804: << endl fp@1804: << "1001:0 0x0000003b/0x02010000 3 OP" << endl fp@1804: << "| | | |" << endl fp@1804: << "| | | \\- Application-layer" << endl fp@1804: << "| | | state of the attached" << endl fp@1804: << "| | | slave, or '-', if no" << endl fp@1804: << "| | | slave is attached." << endl fp@1804: << "| | \\- Absolute decimal ring" << endl fp@1804: << "| | position of the attached" << endl fp@1804: << "| | slave, or '-' if none" << endl fp@1804: << "| | attached." << endl fp@1804: << "| \\- Expected vendor ID and product code (both" << endl fp@1804: << "| hexadecimal)." << endl fp@1804: << "\\- Alias address and relative position (both decimal)." << endl fp@1804: << endl fp@1804: << "With the --verbose option given, the configured PDOs and" << endl fp@1804: << "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@1804: << endl fp@1804: << "Command-specific options:" << endl fp@1157: << " --alias -a Configuration alias (see above)." << endl fp@1157: << " --position -p Relative position (see above)." << endl fp@1804: << " --verbose -v Show detailed configurations." << endl fp@1157: << endl fp@1157: << numericInfo(); fp@1142: fp@1804: return str.str(); fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: /** Lists the bus configuration. fp@1142: */ fp@1826: void CommandConfig::execute(const StringVector &args) fp@1142: { fp@1880: MasterIndexList masterIndices; fp@1869: bool doIndent; fp@1156: ConfigList configs; fp@1142: fp@1373: if (args.size()) { fp@1373: stringstream err; fp@1373: err << "'" << getName() << "' takes no arguments!"; fp@1373: throwInvalidUsageException(err); fp@1373: } fp@1373: fp@1880: masterIndices = getMasterIndices(); fp@1869: doIndent = masterIndices.size() > 1; fp@1826: MasterIndexList::const_iterator mi; fp@1869: for (mi = masterIndices.begin(); fp@1869: mi != masterIndices.end(); mi++) { fp@1826: MasterDevice m(*mi); fp@1826: m.open(MasterDevice::Read); fp@1826: configs = selectedConfigs(m); fp@1826: fp@1827: if (configs.size() && doIndent) { fp@1827: cout << "Master" << dec << m.getIndex() << endl; fp@1826: } fp@1826: fp@1826: if (getVerbosity() == Verbose) { fp@1826: showDetailedConfigs(m, configs, doIndent); fp@1826: } else { fp@1826: listConfigs(m, configs, doIndent); fp@1826: } 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@1804: MasterDevice &m, fp@1826: const ConfigList &configList, fp@1826: bool doIndent fp@1804: ) fp@1142: { fp@1142: ConfigList::const_iterator configIter; fp@1526: unsigned int i, 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@1966: ec_ioctl_config_idn_t idn; fp@1826: string indent(doIndent ? " " : ""); fp@1142: fp@1142: for (configIter = configList.begin(); fp@1142: configIter != configList.end(); fp@1142: configIter++) { fp@1142: fp@1826: cout << indent fp@1826: << "Alias: " fp@1826: << dec << configIter->alias << endl << indent fp@1826: << "Position: " << configIter->position << endl << indent fp@1142: << "Vendor Id: 0x" fp@1142: << hex << setfill('0') fp@1826: << setw(8) << configIter->vendor_id << endl << indent fp@1142: << "Product code: 0x" fp@1826: << setw(8) << configIter->product_code << endl << indent 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@1826: cout << indent << "Watchdog divider: "; fp@1518: if (configIter->watchdog_divider) { fp@1518: cout << dec << configIter->watchdog_divider; fp@1518: } else { fp@1519: cout << "(Default)"; fp@1518: } fp@1826: cout << endl << indent fp@1519: << "Watchdog intervals: "; fp@1518: if (configIter->watchdog_intervals) { fp@1518: cout << dec << configIter->watchdog_intervals; fp@1518: } else { fp@1519: cout << "(Default)"; fp@1518: } fp@1518: cout << endl; fp@1518: fp@1142: for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { fp@1142: if (configIter->syncs[j].pdo_count) { fp@1826: cout << indent << "SM" << dec << j << ", Dir: " fp@1142: << (configIter->syncs[j].dir == EC_DIR_INPUT fp@1518: ? "Input" : "Output") << ", Watchdog: "; fp@1518: switch (configIter->syncs[j].watchdog_mode) { fp@1518: case EC_WD_DEFAULT: cout << "Default"; break; fp@1518: case EC_WD_ENABLE: cout << "Enable"; break; fp@1518: case EC_WD_DISABLE: cout << "Disable"; break; fp@1518: default: cout << "???"; break; fp@1518: } fp@1518: cout << endl; fp@1518: 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@1826: cout << indent << " PDO 0x" << hex << setfill('0') fp@1467: << 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@1826: cout << indent << " PDO entry 0x" fp@1826: << 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@1826: cout << indent << "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@1826: cout << indent << " 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(4) << sdo.index << ":" fp@1142: << setw(2) << (unsigned int) sdo.subindex fp@1526: << ", " << dec << sdo.size << " byte" << endl; fp@1526: fp@1826: cout << indent << " " << hex; fp@1526: for (i = 0; i < min((uint32_t) sdo.size, fp@1526: (uint32_t) EC_MAX_SDO_DATA_SIZE); i++) { fp@1526: cout << setw(2) << (unsigned int) sdo.data[i]; fp@1526: if ((i + 1) % 16 == 0 && i < sdo.size - 1) { fp@1826: cout << endl << indent << " "; fp@1526: } else { fp@1526: cout << " "; fp@1526: } fp@1142: } fp@1142: fp@1142: cout << endl; fp@1526: if (sdo.size > EC_MAX_SDO_DATA_SIZE) { fp@1826: cout << indent << " ..." << endl; fp@1526: } fp@1142: } fp@1142: } else { fp@1826: cout << indent << " None." << endl; fp@1142: } fp@1142: fp@1966: cout << indent << "IDN configuration:" << endl; fp@1966: if (configIter->idn_count) { fp@1966: for (j = 0; j < configIter->idn_count; j++) { fp@1966: m.getConfigIdn(&idn, configIter->config_index, j); fp@1966: fp@1966: cout << indent << " Drive " << (unsigned int) idn.drive_no fp@1966: << ", " << outputIdn(idn.idn) fp@1966: << ", " << dec << idn.size << " byte" << endl; fp@1966: fp@1966: cout << indent << " " << hex << setfill('0'); fp@1966: for (i = 0; i < min((uint32_t) idn.size, fp@1966: (uint32_t) EC_MAX_IDN_DATA_SIZE); i++) { fp@1966: cout << setw(2) << (unsigned int) idn.data[i]; fp@1966: if ((i + 1) % 16 == 0 && i < idn.size - 1) { fp@1966: cout << endl << indent << " "; fp@1966: } else { fp@1966: cout << " "; fp@1966: } fp@1966: } fp@1966: fp@1966: cout << endl; fp@1966: if (idn.size > EC_MAX_IDN_DATA_SIZE) { fp@1966: cout << indent << " ..." << endl; fp@1966: } fp@1966: } fp@1966: } else { fp@1966: cout << indent << " None." << endl; fp@1966: } fp@1455: if (configIter->dc_assign_activate) { fp@1455: int i; fp@1455: fp@1826: cout << indent << "DC configuration:" << endl fp@1826: << indent << " AssignActivate: 0x" << hex << setfill('0') fp@1455: << setw(4) << configIter->dc_assign_activate << endl; fp@1455: fp@1826: cout << indent << " Cycle [ns] Shift [ns]" << endl; fp@1455: for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) { fp@1826: cout << indent << " SYNC" << dec << i << " " fp@1456: << setfill(' ') << right fp@1455: << setw(11) << configIter->dc_sync[i].cycle_time fp@1456: << " " fp@1455: << setw(11) << configIter->dc_sync[i].shift_time fp@1455: << endl; fp@1455: } fp@1455: } 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@1826: const ConfigList &configList, fp@1826: bool doIndent 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@1826: string indent(doIndent ? " " : ""); 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@1918: info.state = alStateString(slave.al_state); 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@1826: cout << indent << 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: /*****************************************************************************/