tool/CommandConfig.cpp
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sat, 29 Sep 2018 23:58:09 +0200
branchstable-1.5
changeset 2714 ec417efca1fd
parent 2435 4151f6f4c3e1
permissions -rw-r--r--
This fix a segfault in xenomai_posix example when calling pthread_setschedparam(cyclic_thread, ...) from main thread. As a side effect EL2004 becomes EL2088 - that's what IU have for testing.
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
    28
 *  vim: expandtab
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
    29
 *
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <list>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <iostream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <iomanip>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <sstream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
using namespace std;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "CommandConfig.h"
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    39
#include "MasterDevice.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
CommandConfig::CommandConfig():
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
    Command("config", "Show slave configurations.")
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    50
string CommandConfig::helpString(const string &binaryBaseName) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    54
    str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    55
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    56
        << getBriefDescription() << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    57
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    58
        << "Without the --verbose option, slave configurations are" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    59
        << "output one-per-line. Example:" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    60
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    61
        << "1001:0  0x0000003b/0x02010000  3  OP" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    62
        << "|       |                      |  |" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    63
        << "|       |                      |  \\- Application-layer" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    64
        << "|       |                      |     state of the attached" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    65
        << "|       |                      |     slave, or '-', if no" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    66
        << "|       |                      |     slave is attached." << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    67
        << "|       |                      \\- Absolute decimal ring" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    68
        << "|       |                         position of the attached" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    69
        << "|       |                         slave, or '-' if none" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    70
        << "|       |                         attached." << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    71
        << "|       \\- Expected vendor ID and product code (both" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    72
        << "|          hexadecimal)." << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    73
        << "\\- Alias address and relative position (both decimal)." << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    74
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    75
        << "With the --verbose option given, the configured PDOs and" << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    76
        << "SDOs are output in addition." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    77
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    78
        << "Configuration selection:" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    79
        << "  Slave configurations can be selected with" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    80
        << "  the --alias and --position parameters as follows:" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    81
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    82
        << "  1) If neither the --alias nor the --position option" << endl
1167
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    83
        << "     is given, all slave configurations are displayed." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    84
        << "  2) If only the --position option is given, an alias" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    85
        << "     of zero is assumed (see 4))." << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    86
        << "  3) If only the --alias option is given, all slave" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    87
        << "     configurations with the given alias address" << endl
1167
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    88
        << "     are displayed." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    89
        << "  4) If both the --alias and the --position option are" << endl
1167
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    90
        << "     given, the selection can match a single" << endl
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    91
        << "     configuration, that is displayed, if it exists." << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    92
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    93
        << "Command-specific options:" << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    94
        << "  --alias    -a <alias>  Configuration alias (see above)." << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    95
        << "  --position -p <pos>    Relative position (see above)." << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
    96
        << "  --verbose  -v          Show detailed configurations." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    97
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    98
        << numericInfo();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   100
    return str.str();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
/** Lists the bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
 */
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   107
void CommandConfig::execute(const StringVector &args)
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
{
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   109
    MasterIndexList masterIndices;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
   110
    bool doIndent;
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
   111
    ConfigList configs;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
1373
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   113
    if (args.size()) {
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   114
        stringstream err;
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   115
        err << "'" << getName() << "' takes no arguments!";
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   116
        throwInvalidUsageException(err);
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   117
    }
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   118
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   119
    masterIndices = getMasterIndices();
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
   120
    doIndent = masterIndices.size() > 1;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   121
    MasterIndexList::const_iterator mi;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
   122
    for (mi = masterIndices.begin();
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
   123
            mi != masterIndices.end(); mi++) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   124
        MasterDevice m(*mi);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   125
        m.open(MasterDevice::Read);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   126
        configs = selectedConfigs(m);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   127
1827
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   128
        if (configs.size() && doIndent) {
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   129
            cout << "Master" << dec << m.getIndex() << endl;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   130
        }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   131
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   132
        if (getVerbosity() == Verbose) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   133
            showDetailedConfigs(m, configs, doIndent);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   134
        } else {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   135
            listConfigs(m, configs, doIndent);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   136
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
/** Lists the complete bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
 */
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
void CommandConfig::showDetailedConfigs(
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   145
        MasterDevice &m,
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   146
        const ConfigList &configList,
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   147
        bool doIndent
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   148
        )
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    ConfigList::const_iterator configIter;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   151
    unsigned int i, j, k, l;
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   152
    ec_ioctl_slave_t slave;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    ec_ioctl_config_pdo_t pdo;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    ec_ioctl_config_pdo_entry_t entry;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    ec_ioctl_config_sdo_t sdo;
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   156
    ec_ioctl_config_idn_t idn;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   157
    string indent(doIndent ? "  " : "");
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    for (configIter = configList.begin();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
            configIter != configList.end();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
            configIter++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   163
        cout << indent
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   164
            << "Alias: "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   165
            << dec << configIter->alias << endl << indent
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   166
            << "Position: " << configIter->position << endl << indent
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
            << "Vendor Id: 0x"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
            << hex << setfill('0')
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   169
            << setw(8) << configIter->vendor_id << endl << indent
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
            << "Product code: 0x"
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   171
            << setw(8) << configIter->product_code << endl << indent
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   172
            << "Attached slave: ";
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   173
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   174
        if (configIter->slave_position != -1) {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   175
            m.getSlave(&slave, configIter->slave_position);
1172
74ee632c3b5e Fixed attached slave position in 'ethercat config' -> decimal.
Florian Pose <fp@igh-essen.com>
parents: 1167
diff changeset
   176
            cout << dec << configIter->slave_position
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   177
                << " (" << alStateString(slave.al_state) << ")" << endl;
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   178
        } else {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   179
            cout << "none" << endl;
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   180
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   182
        cout << indent << "Watchdog divider: ";
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   183
        if (configIter->watchdog_divider) {
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   184
            cout << dec << configIter->watchdog_divider;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   185
        } else {
1519
75629ad02ca9 Minrt changes.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
   186
            cout << "(Default)";
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   187
        }
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   188
        cout << endl << indent
1519
75629ad02ca9 Minrt changes.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
   189
            << "Watchdog intervals: ";
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   190
        if (configIter->watchdog_intervals) {
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   191
            cout << dec << configIter->watchdog_intervals;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   192
        } else {
1519
75629ad02ca9 Minrt changes.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
   193
            cout << "(Default)";
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   194
        }
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   195
        cout << endl;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   196
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
        for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
            if (configIter->syncs[j].pdo_count) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   199
                cout << indent << "SM" << dec << j << ", Dir: "
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
                    << (configIter->syncs[j].dir == EC_DIR_INPUT
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   201
                            ? "Input" : "Output") << ", Watchdog: ";
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   202
                switch (configIter->syncs[j].watchdog_mode) {
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   203
                    case EC_WD_DEFAULT: cout << "Default"; break;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   204
                    case EC_WD_ENABLE: cout << "Enable"; break;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   205
                    case EC_WD_DISABLE: cout << "Disable"; break;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   206
                    default: cout << "???"; break;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   207
                }
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   208
                cout << endl;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1467
diff changeset
   209
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
                for (k = 0; k < configIter->syncs[j].pdo_count; k++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
                    m.getConfigPdo(&pdo, configIter->config_index, j, k);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   213
                    cout << indent << "  PDO 0x" << hex << setfill('0')
1467
013a4e42a9fb Minor fix in 'ethercat config' output.
Florian Pose <fp@igh-essen.com>
parents: 1456
diff changeset
   214
                        << setw(4) << pdo.index << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
                    for (l = 0; l < pdo.entry_count; l++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
                        m.getConfigPdoEntry(&entry,
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
                                configIter->config_index, j, k, l);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   220
                        cout << indent << "    PDO entry 0x"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   221
                            << hex << setfill('0')
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
                            << setw(4) << entry.index << ":"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
                            << setw(2) << (unsigned int) entry.subindex
1188
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   224
                            << ", " << dec << setfill(' ')
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   225
                            << setw(2) << (unsigned int) entry.bit_length
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   226
                            << " bit" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
                    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
                }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
            }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   232
        cout << indent << "SDO configuration:" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        if (configIter->sdo_count) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
            for (j = 0; j < configIter->sdo_count; j++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
                m.getConfigSdo(&sdo, configIter->config_index, j);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   237
                cout << indent << "  0x"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
                    << hex << setfill('0')
2435
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   239
                    << setw(4) << sdo.index;
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   240
                if (sdo.complete_access) {
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   241
                    cout << " C";
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   242
                }
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   243
                else {
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   244
                    cout << ":" << setw(2) << (unsigned int) sdo.subindex;
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   245
                }
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   246
                cout << ", " << dec << sdo.size << " byte" << endl;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   247
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   248
                cout << indent << "    " << hex;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   249
                for (i = 0; i < min((uint32_t) sdo.size,
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   250
                            (uint32_t) EC_MAX_SDO_DATA_SIZE); i++) {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   251
                    cout << setw(2) << (unsigned int) sdo.data[i];
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   252
                    if ((i + 1) % 16 == 0 && i < sdo.size - 1) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   253
                        cout << endl << indent << "    ";
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   254
                    } else {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   255
                        cout << " ";
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   256
                    }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
                }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
                cout << endl;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   260
                if (sdo.size > EC_MAX_SDO_DATA_SIZE) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   261
                    cout << indent << "    ..." << endl;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1519
diff changeset
   262
                }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
            }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        } else {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   265
            cout << indent << "  None." << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   268
        cout << indent << "IDN configuration:" << endl;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   269
        if (configIter->idn_count) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   270
            for (j = 0; j < configIter->idn_count; j++) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   271
                m.getConfigIdn(&idn, configIter->config_index, j);
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   272
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   273
                cout << indent << "  Drive " << (unsigned int) idn.drive_no
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   274
                    << ", " << outputIdn(idn.idn)
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   275
                    << ", " << dec << idn.size << " byte" << endl;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   276
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   277
                cout << indent << "    " << hex << setfill('0');
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   278
                for (i = 0; i < min((uint32_t) idn.size,
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   279
                            (uint32_t) EC_MAX_IDN_DATA_SIZE); i++) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   280
                    cout << setw(2) << (unsigned int) idn.data[i];
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   281
                    if ((i + 1) % 16 == 0 && i < idn.size - 1) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   282
                        cout << endl << indent << "    ";
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   283
                    } else {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   284
                        cout << " ";
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   285
                    }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   286
                }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   287
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   288
                cout << endl;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   289
                if (idn.size > EC_MAX_IDN_DATA_SIZE) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   290
                    cout << indent << "    ..." << endl;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   291
                }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   292
            }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   293
        } else {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   294
            cout << indent << "  None." << endl;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   295
        }
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   296
        if (configIter->dc_assign_activate) {
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   297
            int i;
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   298
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   299
            cout << indent << "DC configuration:" << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   300
                << indent << "  AssignActivate: 0x" << hex << setfill('0')
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   301
                << setw(4) << configIter->dc_assign_activate << endl;
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   302
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   303
            cout << indent << "         Cycle [ns]   Shift [ns]" << endl;
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   304
            for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   305
                cout << indent << "  SYNC" << dec << i << "  "
1456
bd1f69a429f3 Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   306
                    << setfill(' ') << right
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   307
                    << setw(11) << configIter->dc_sync[i].cycle_time
1456
bd1f69a429f3 Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   308
                    << "  "
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   309
                    << setw(11) << configIter->dc_sync[i].shift_time
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   310
                    << endl;
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   311
            }
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   312
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
        cout << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
/** Lists the bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
 */
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   321
void CommandConfig::listConfigs(
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   322
        MasterDevice &m,
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   323
        const ConfigList &configList,
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   324
        bool doIndent
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   325
        )
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
    ConfigList::const_iterator configIter;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
    Info info;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
    typedef list<Info> InfoList;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
    InfoList list;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
    InfoList::const_iterator iter;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
    unsigned int maxAliasWidth = 0, maxPosWidth = 0,
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   334
                 maxSlavePosWidth = 0, maxStateWidth = 0;
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   335
    ec_ioctl_slave_t slave;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   336
    string indent(doIndent ? "  " : "");
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
    for (configIter = configList.begin();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
            configIter != configList.end();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
            configIter++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
        str << dec << configIter->alias;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
        info.alias = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
        str.str("");
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
        str << configIter->position;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
        info.pos = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
        str.str("");
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
        str << hex << setfill('0')
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
            << "0x" << setw(8) << configIter->vendor_id
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
            << "/0x" << setw(8) << configIter->product_code;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
        info.ident = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
        str.str("");
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   359
        if (configIter->slave_position != -1) {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   360
            m.getSlave(&slave, configIter->slave_position);
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   361
1172
74ee632c3b5e Fixed attached slave position in 'ethercat config' -> decimal.
Florian Pose <fp@igh-essen.com>
parents: 1167
diff changeset
   362
            str << dec << configIter->slave_position;
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   363
            info.slavePos = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   364
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   365
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   366
1918
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   367
            info.state = alStateString(slave.al_state);
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   368
        } else {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   369
            str << "-";
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   370
            info.slavePos = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   371
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   372
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   373
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   374
            str << "-";
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   375
            info.state = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   376
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   377
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   378
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
        list.push_back(info);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
        if (info.alias.length() > maxAliasWidth)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
            maxAliasWidth = info.alias.length();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
        if (info.pos.length() > maxPosWidth)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
            maxPosWidth = info.pos.length();
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   386
        if (info.slavePos.length() > maxSlavePosWidth)
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   387
            maxSlavePosWidth = info.slavePos.length();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   388
        if (info.state.length() > maxStateWidth)
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   389
            maxStateWidth = info.state.length();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
    for (iter = list.begin(); iter != list.end(); iter++) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   393
        cout << indent << setfill(' ') << right
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
            << setw(maxAliasWidth) << iter->alias
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
            << ":" << left
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
            << setw(maxPosWidth) << iter->pos
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
            << "  "
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
            << iter->ident
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
            << "  "
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   400
            << setw(maxSlavePosWidth) << iter->slavePos << "  "
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   401
            << setw(maxStateWidth) << iter->state << "  "
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
            << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
/*****************************************************************************/