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 <iostream>
fp@1142: #include <iomanip>
fp@1142: using namespace std;
fp@1142: 
fp@1142: #include "CommandSdos.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@1142: string CommandSdos::helpString() const
fp@1142: {
fp@1142:     stringstream str;
fp@1142: 
fp@1142:     str << getName() << " [OPTIONS]" << endl
fp@1142:     	<< endl
fp@1142:     	<< getBriefDescription() << endl
fp@1142:     	<< endl
fp@1327:     	<< "SDO dictionary information is displayed in two layers," << endl
fp@1142:     	<< "which are indented accordingly:" << endl
fp@1142:     	<< endl
fp@1327:     	<< "1) SDOs - Hexadecimal SDO index and the name. Example:" << endl
fp@1142:     	<< endl
fp@1327:     	<< "   SDO 0x1018, \"Identity object\"" << endl
fp@1142:     	<< endl
fp@1327:     	<< "2) SDO entries - SDO index and SDO entry subindex (both" << endl
fp@1142: 		<< "   hexadecimal) followed by the data type, the length in" << endl
fp@1142: 		<< "   bit, and the description. Example:" << endl
fp@1142:     	<< endl
fp@1142:     	<< "   0x1018:01, uint32, 32 bit, \"Vendor id\"" << endl
fp@1142:     	<< endl
fp@1327:     	<< "If the --quiet option is given, only the SDOs are output."
fp@1142: 		<< endl << endl
fp@1142:     	<< "Command-specific options:" << endl
fp@1157:         << "  --alias    -a <alias>" << endl
fp@1157:         << "  --position -p <pos>    Slave selection. See the help of" << endl
fp@1157:         << "                         the 'slaves' command." << endl
fp@1327:     	<< "  --quiet    -q          Only output SDOs (without the" << endl
fp@1327: 		<< "                         SDO entries)." << endl
fp@1142:     	<< endl
fp@1142: 		<< numericInfo();
fp@1142: 
fp@1142: 	return str.str();
fp@1142: }
fp@1142: 
fp@1142: /****************************************************************************/
fp@1142: 
fp@1142: void CommandSdos::execute(MasterDevice &m, const StringVector &args)
fp@1142: {
fp@1151:     SlaveList slaves;
fp@1151:     SlaveList::const_iterator si;
fp@1151:     bool showHeader;
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@1142:     m.open(MasterDevice::Read);
fp@1151:     slaves = selectedSlaves(m);
fp@1151:     showHeader = slaves.size() > 1;
fp@1142: 
fp@1151:     for (si = slaves.begin(); si != slaves.end(); si++) {
fp@1151:         listSlaveSdos(m, *si, showHeader);
fp@1142:     }
fp@1142: }
fp@1142: 
fp@1142: /****************************************************************************/
fp@1142: 
fp@1142: void CommandSdos::listSlaveSdos(
fp@1142: 		MasterDevice &m,
fp@1151:         const ec_ioctl_slave_t &slave,
fp@1151: 		bool showHeader
fp@1142: 		)
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@1142:     
fp@1151:     if (showHeader)
fp@1151:         cout << "=== 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@1151:             m.getSdoEntry(&entry, slave.position, -i, j);
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@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: /*****************************************************************************/