tool/CommandSdos.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 02 Oct 2008 07:16:17 +0000
branchstable-1.4
changeset 1645 bbdaddf33131
parent 1184 75cd6681eb08
child 1327 4d179b06dd3c
permissions -rw-r--r--
Version 1.4.0-rc3.
/*****************************************************************************
 *
 * $Id$
 *
 ****************************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;

#include "CommandSdos.h"

/*****************************************************************************/

CommandSdos::CommandSdos():
    SdoCommand("sdos", "List Sdo dictionaries.")
{
}

/*****************************************************************************/

string CommandSdos::helpString() const
{
    stringstream str;

    str << getName() << " [OPTIONS]" << endl
    	<< endl
    	<< getBriefDescription() << endl
    	<< endl
    	<< "Sdo dictionary information is displayed in two layers," << endl
    	<< "which are indented accordingly:" << endl
    	<< endl
    	<< "1) Sdos - Hexadecimal Sdo index and the name. Example:" << endl
    	<< endl
    	<< "   Sdo 0x1018, \"Identity object\"" << endl
    	<< endl
    	<< "2) Sdo entries - Sdo index and Sdo entry subindex (both" << endl
		<< "   hexadecimal) followed by the data type, the length in" << endl
		<< "   bit, and the description. Example:" << endl
    	<< endl
    	<< "   0x1018:01, uint32, 32 bit, \"Vendor id\"" << endl
    	<< endl
    	<< "If the --quiet option is given, only the Sdos are output."
		<< endl << endl
    	<< "Command-specific options:" << endl
        << "  --alias    -a <alias>" << endl
        << "  --position -p <pos>    Slave selection. See the help of" << endl
        << "                         the 'slaves' command." << endl
    	<< "  --quiet    -q          Only output Sdos (without the" << endl
		<< "                         Sdo entries)." << endl
    	<< endl
		<< numericInfo();

	return str.str();
}

/****************************************************************************/

void CommandSdos::execute(MasterDevice &m, const StringVector &args)
{
    SlaveList slaves;
    SlaveList::const_iterator si;
    bool showHeader;

    m.open(MasterDevice::Read);
    slaves = selectedSlaves(m);
    showHeader = slaves.size() > 1;

    for (si = slaves.begin(); si != slaves.end(); si++) {
        listSlaveSdos(m, *si, showHeader);
    }
}

/****************************************************************************/

void CommandSdos::listSlaveSdos(
		MasterDevice &m,
        const ec_ioctl_slave_t &slave,
		bool showHeader
		)
{
    ec_ioctl_slave_sdo_t sdo;
    ec_ioctl_slave_sdo_entry_t entry;
    unsigned int i, j;
    const DataType *d;
    
    if (showHeader)
        cout << "=== Slave " << slave.position << " ===" << endl;

    for (i = 0; i < slave.sdo_count; i++) {
        m.getSdo(&sdo, slave.position, i);

        cout << "Sdo 0x"
            << hex << setfill('0')
            << setw(4) << sdo.sdo_index
            << ", \"" << sdo.name << "\"" << endl;

        if (getVerbosity() == Quiet)
            continue;

        for (j = 0; j <= sdo.max_subindex; j++) {
            m.getSdoEntry(&entry, slave.position, -i, j);

            cout << "  0x" << hex << setfill('0')
                << setw(4) << sdo.sdo_index << ":"
                << setw(2) << (unsigned int) entry.sdo_entry_subindex
                << ", ";

            if ((d = findDataType(entry.data_type))) {
                cout << d->name;
            } else {
                cout << "type " << setw(4) << entry.data_type;
            }

            cout << ", " << dec << entry.bit_length << " bit, \""
                << entry.description << "\"" << endl;
        }
    }
}

/*****************************************************************************/