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@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandSdos.h" fp@1826: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandSdos::CommandSdos(): fp@1327: SdoCommand("sdos", "List SDO dictionaries.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1968: string CommandSdos::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: << "SDO dictionary information is displayed in two layers," << endl fp@1804: << "which are indented accordingly:" << endl fp@1804: << endl fp@1804: << "1) SDOs - Hexadecimal SDO index and the name. Example:" << endl fp@1804: << endl fp@1804: << " SDO 0x1018, \"Identity object\"" << endl fp@1804: << endl fp@1804: << "2) SDO entries - SDO index and SDO entry subindex (both" << endl fp@1804: << " hexadecimal) followed by the access rights (see" << endl fp@1382: << " below), the data type, the length in bit, and the" << endl fp@1382: << " description. Example:" << endl fp@1804: << endl fp@1804: << " 0x1018:01, rwrwrw, uint32, 32 bit, \"Vendor id\"" << endl fp@1804: << endl fp@1382: << "The access rights are specified for the AL states PREOP," << endl fp@1382: << "SAFEOP and OP. An 'r' means, that the entry is readable" << endl fp@1382: << "in the corresponding state, an 'w' means writable," << endl fp@1382: << "respectively. If a right is not granted, a dash '-' is" << endl fp@1382: << "shown." << endl fp@1382: << endl fp@1804: << "If the --quiet option is given, only the SDOs are output." fp@1804: << endl << endl fp@1804: << "Command-specific options:" << endl fp@1157: << " --alias -a " << endl fp@1157: << " --position -p Slave selection. See the help of" << endl fp@1157: << " the 'slaves' command." << endl fp@1804: << " --quiet -q Only output SDOs (without the" << endl fp@1804: << " SDO entries)." << endl fp@1804: << endl fp@1804: << numericInfo(); fp@1142: fp@1804: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1826: void CommandSdos::execute(const StringVector &args) fp@1142: { fp@1869: MasterIndexList masterIndices; fp@1151: SlaveList slaves; fp@1151: SlaveList::const_iterator si; fp@1826: bool showHeader, multiMaster; fp@1151: 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@1869: masterIndices = getMasterIndices(); fp@1869: multiMaster = 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: slaves = selectedSlaves(m); fp@1826: showHeader = multiMaster || slaves.size() > 1; fp@1142: fp@1826: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1826: listSlaveSdos(m, *si, showHeader); fp@1826: } fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSdos::listSlaveSdos( fp@1804: MasterDevice &m, fp@1151: const ec_ioctl_slave_t &slave, fp@1804: bool showHeader fp@1804: ) fp@1142: { fp@1142: ec_ioctl_slave_sdo_t sdo; fp@1142: ec_ioctl_slave_sdo_entry_t entry; fp@1142: unsigned int i, j; fp@1184: const DataType *d; fp@2421: fp@1827: if (showHeader && slave.sdo_count) fp@1826: cout << "=== Master " << m.getIndex() fp@1826: << ", Slave " << slave.position << " ===" << endl; fp@1142: fp@1142: for (i = 0; i < slave.sdo_count; i++) { fp@1151: m.getSdo(&sdo, slave.position, i); fp@1142: fp@1327: cout << "SDO 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(4) << sdo.sdo_index fp@1142: << ", \"" << sdo.name << "\"" << endl; fp@1142: fp@1142: if (getVerbosity() == Quiet) fp@1142: continue; fp@1142: fp@1142: for (j = 0; j <= sdo.max_subindex; j++) { fp@2694: try { fp@2694: m.getSdoEntry(&entry, slave.position, -i, j); fp@2694: } fp@2694: catch (MasterDeviceException &e) { fp@2694: continue; fp@2694: } fp@1142: fp@1142: cout << " 0x" << hex << setfill('0') fp@1142: << setw(4) << sdo.sdo_index << ":" fp@1142: << setw(2) << (unsigned int) entry.sdo_entry_subindex fp@1382: << ", " fp@1382: << (entry.read_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "r" : "-") fp@1382: << (entry.write_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "w" : "-") fp@1382: << (entry.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "r" : "-") fp@1382: << (entry.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "w" : "-") fp@1382: << (entry.read_access[EC_SDO_ENTRY_ACCESS_OP] ? "r" : "-") fp@1382: << (entry.write_access[EC_SDO_ENTRY_ACCESS_OP] ? "w" : "-") fp@1142: << ", "; fp@1142: fp@1142: if ((d = findDataType(entry.data_type))) { fp@1142: cout << d->name; fp@1142: } else { fp@1142: cout << "type " << setw(4) << entry.data_type; fp@1142: } fp@1142: fp@1142: cout << ", " << dec << entry.bit_length << " bit, \"" fp@1142: << entry.description << "\"" << endl; fp@1142: } fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/