fp@1142: /***************************************************************************** fp@1142: * fp@1363: * $Id$ fp@1363: * fp@2542: * Copyright (C) 2006-2014 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@1222: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandXml.h" fp@1826: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandXml::CommandXml(): fp@1142: Command("xml", "Generate slave information XML.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1968: string CommandXml::helpString(const string &binaryBaseName) const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1968: str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1327: << "Note that the PDO information can either originate" << endl fp@1142: << "from the SII or from the CoE communication area. For" << endl fp@1327: << "slaves, that support configuring PDO assignment and" << endl fp@1144: << "mapping, the output depends on the last configuration." << endl fp@1142: << endl fp@1142: << "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@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1826: void CommandXml::execute(const StringVector &args) fp@1142: { fp@1151: SlaveList slaves; fp@1151: SlaveList::const_iterator si; 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@1870: MasterDevice m(getSingleMasterIndex()); fp@1142: m.open(MasterDevice::Read); fp@1151: slaves = selectedSlaves(m); fp@1142: fp@1474: cout << "" << endl; fp@1474: if (slaves.size() > 1) { fp@1474: cout << "" << endl; fp@1474: } fp@1474: fp@1151: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1474: generateSlaveXml(m, *si, slaves.size() > 1 ? 1 : 0); fp@1474: } fp@1474: fp@1474: if (slaves.size() > 1) { fp@1474: cout << "" << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1151: void CommandXml::generateSlaveXml( fp@1151: MasterDevice &m, fp@1474: const ec_ioctl_slave_t &slave, fp@1474: unsigned int indent fp@1151: ) fp@1142: { fp@1142: ec_ioctl_slave_sync_t sync; fp@1142: ec_ioctl_slave_sync_pdo_t pdo; fp@1474: string pdoType, in; fp@1142: ec_ioctl_slave_sync_pdo_entry_t entry; fp@1142: unsigned int i, j, k; fp@1474: fp@1474: for (i = 0; i < indent; i++) { fp@1474: in += " "; fp@1474: } fp@2421: fp@1142: cout fp@1474: << in << "" << endl fp@2542: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << " " << slave.vendor_id << "" << endl fp@1474: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << " " << slave.order << "" << endl; fp@1142: fp@1142: if (strlen(slave.name)) { fp@1142: cout fp@1474: << in << " " << endl; fp@1142: } fp@1142: fp@1142: for (i = 0; i < slave.sync_count; i++) { fp@1151: m.getSync(&sync, slave.position, i); fp@1142: fp@1142: cout fp@2542: << in << " " << endl; fp@1142: } fp@1142: fp@1142: for (i = 0; i < slave.sync_count; i++) { fp@1151: m.getSync(&sync, slave.position, i); fp@1142: fp@1142: for (j = 0; j < sync.pdo_count; j++) { fp@1151: m.getPdo(&pdo, slave.position, i, j); fp@1142: pdoType = (sync.control_register & 0x04 ? "R" : "T"); fp@1327: pdoType += "xPdo"; // last 2 letters lowercase in XML! fp@1142: fp@1142: cout fp@1474: << in << " <" << pdoType fp@1142: << " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl fp@1474: << in << " #x" fp@1142: << hex << setfill('0') << setw(4) << pdo.index fp@1142: << "" << endl fp@1474: << in << " " << pdo.name << "" << endl; fp@1142: fp@1142: for (k = 0; k < pdo.entry_count; k++) { fp@1151: m.getPdoEntry(&entry, slave.position, i, j, k); fp@1142: fp@1142: cout fp@1474: << in << " " << endl fp@1474: << in << " #x" fp@1142: << hex << setfill('0') << setw(4) << entry.index fp@1142: << "" << endl; fp@1142: if (entry.index) fp@1142: cout fp@1474: << in << " " fp@1142: << dec << (unsigned int) entry.subindex fp@1142: << "" << endl; fp@2421: fp@1142: cout fp@1474: << in << " " fp@1142: << dec << (unsigned int) entry.bit_length fp@1142: << "" << endl; fp@1142: fp@1142: if (entry.index) { fp@1142: cout fp@1474: << in << " " << entry.name fp@1142: << "" << endl fp@1474: << in << " "; fp@1142: fp@1142: if (entry.bit_length == 1) { fp@1142: cout << "BOOL"; fp@1142: } else if (!(entry.bit_length % 8)) { fp@1560: if (entry.bit_length <= 64) { fp@1142: cout << "UINT" << (unsigned int) entry.bit_length; fp@1560: } else { fp@1142: cout << "STRING(" fp@1142: << (unsigned int) (entry.bit_length / 8) fp@1142: << ")"; fp@1560: } fp@1142: } else { fp@1560: cout << "BIT" << (unsigned int) entry.bit_length; fp@1142: } fp@1142: fp@1560: cout << "" << endl; fp@1142: } fp@1142: fp@1474: cout << in << " " << endl; fp@1142: } fp@1142: fp@1142: cout fp@1474: << in << " " << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: cout fp@1474: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << " " << endl fp@1474: << in << "" << endl; fp@1474: } fp@1474: fp@1142: /*****************************************************************************/