tool/CommandConfig.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 02 Oct 2008 10:44:43 +0000
changeset 1245 9f52fc9562ae
parent 1188 3b4e82d9904b
child 1254 c19d273a9e76
child 1686 e206f4485f60
permissions -rw-r--r--
Minor change.
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
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <list>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#include <iostream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <iomanip>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <sstream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
using namespace std;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include "CommandConfig.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include "byteorder.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
CommandConfig::CommandConfig():
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
    Command("config", "Show slave configurations.")
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
string CommandConfig::helpString() const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    29
    str << getName() << " [OPTIONS]" << endl
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    30
    	<< endl
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    31
    	<< getBriefDescription() << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
    	<< endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
    	<< "Without the --verbose option, slave configurations are" << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
    	<< "output one-per-line. Example:" << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
    	<< endl
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    36
    	<< "1001:0  0x0000003b/0x02010000  3  OP" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
    	<< "|       |                      |  |" << endl
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    38
    	<< "|       |                      |  \\- Application-layer" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    39
    	<< "|       |                      |     state of the attached" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    40
    	<< "|       |                      |     slave, or '-', if no" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    41
    	<< "|       |                      |     slave is attached." << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    42
    	<< "|       |                      \\- Absolute decimal ring" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    43
    	<< "|       |                         position of the attached" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    44
    	<< "|       |                         slave, or '-' if none" << endl
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    45
    	<< "|       |                         attached." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    46
    	<< "|       \\- Expected vendor ID and product code (both" << endl
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    47
    	<< "|          hexadecimal)." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    48
    	<< "\\- Alias address and relative position (both decimal)." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    	<< endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    	<< "With the --verbose option given, the configured Pdos and" << endl
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    51
    	<< "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
    52
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    53
        << "Configuration selection:" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    54
        << "  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
    55
        << "  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
    56
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    57
        << "  1) If neither the --alias nor the --position option" << endl
1167
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    58
        << "     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
    59
        << "  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
    60
        << "     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
    61
        << "  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
    62
        << "     configurations with the given alias address" << endl
1167
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    63
        << "     are displayed." << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    64
        << "  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
    65
        << "     given, the selection can match a single" << endl
9e0ebb38e301 Improved help.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    66
        << "     configuration, that is displayed, if it exists." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    	<< endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    	<< "Command-specific options:" << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    69
        << "  --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
    70
        << "  --position -p <pos>    Relative position (see above)." << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    71
    	<< "  --verbose  -v          Show detailed configurations." << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    72
        << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
    73
        << numericInfo();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
	return str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
/** Lists the bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
 */
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
void CommandConfig::execute(MasterDevice &m, const StringVector &args)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
{
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
    84
    ConfigList configs;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    m.open(MasterDevice::Read);
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
    87
    configs = selectedConfigs(m);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    if (getVerbosity() == Verbose) {
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
    90
        showDetailedConfigs(m, configs);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    } else {
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
    92
        listConfigs(m, configs);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
/** Lists the complete bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
 */
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
void CommandConfig::showDetailedConfigs(
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
		MasterDevice &m,
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
		const ConfigList &configList
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
    ConfigList::const_iterator configIter;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    unsigned int j, k, l;
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   107
    ec_ioctl_slave_t slave;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    ec_ioctl_config_pdo_t pdo;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    ec_ioctl_config_pdo_entry_t entry;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    ec_ioctl_config_sdo_t sdo;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    for (configIter = configList.begin();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
            configIter != configList.end();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
            configIter++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        cout << "Alias: "
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
            << dec << configIter->alias << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
            << "Position: " << configIter->position << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
            << "Vendor Id: 0x"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
            << hex << setfill('0')
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
            << setw(8) << configIter->vendor_id << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
            << "Product code: 0x"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
            << setw(8) << configIter->product_code << endl
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   124
            << "Attached slave: ";
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   125
        
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   126
        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
   127
            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
   128
            cout << dec << configIter->slave_position
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   129
                << " (" << 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
   130
        } else {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   131
            cout << "none" << endl;
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   132
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
            if (configIter->syncs[j].pdo_count) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                cout << "SM" << dec << j << " ("
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
                    << (configIter->syncs[j].dir == EC_DIR_INPUT
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
                            ? "Input" : "Output") << ")" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
                for (k = 0; k < configIter->syncs[j].pdo_count; k++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
                    m.getConfigPdo(&pdo, configIter->config_index, j, k);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
1188
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   142
                    cout << "  Pdo 0x" << hex << setw(4) << pdo.index << endl;
1142
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
                    for (l = 0; l < pdo.entry_count; l++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
                        m.getConfigPdoEntry(&entry,
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
                                configIter->config_index, j, k, l);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
1188
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   148
                        cout << "    Pdo entry 0x" << hex << setfill('0')
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
                            << setw(4) << entry.index << ":"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
                            << 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
   151
                            << ", " << dec << setfill(' ')
3b4e82d9904b Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents: 1172
diff changeset
   152
                            << 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
   153
                            << " bit" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
                    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
            }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
        }
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
        cout << "Sdo configuration:" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        if (configIter->sdo_count) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
            for (j = 0; j < configIter->sdo_count; j++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                m.getConfigSdo(&sdo, configIter->config_index, j);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
                cout << "  0x"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
                    << hex << setfill('0')
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
                    << setw(4) << sdo.index << ":"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
                    << setw(2) << (unsigned int) sdo.subindex
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
                    << ", " << dec << sdo.size << " byte: " << hex;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
                switch (sdo.size) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
                    case 1:
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
                        cout << "0x" << setw(2)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
                            << (unsigned int) *(uint8_t *) &sdo.data;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
                        break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
                    case 2:
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
                        cout << "0x" << setw(4)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
                            << le16tocpu(*(uint16_t *) &sdo.data);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
                        break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
                    case 4:
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
                        cout << "0x" << setw(8)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
                            << le32tocpu(*(uint32_t *) &sdo.data);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
                        break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
                    default:
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
                        cout << "???";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
                }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
                cout << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
            }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        } else {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
            cout << "  None." << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
        cout << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
/** Lists the bus configuration.
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
 */
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   201
void CommandConfig::listConfigs(
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   202
        MasterDevice &m,
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   203
        const ConfigList &configList
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   204
        )
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    ConfigList::const_iterator configIter;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    Info info;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    typedef list<Info> InfoList;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
    InfoList list;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
    InfoList::const_iterator iter;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    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
   213
                 maxSlavePosWidth = 0, maxStateWidth = 0;
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   214
    ec_ioctl_slave_t slave;
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 (configIter = configList.begin();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
            configIter != configList.end();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
            configIter++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        str << dec << configIter->alias;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
        info.alias = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
        str.str("");
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        str << configIter->position;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        info.pos = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        str.str("");
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
        str << hex << setfill('0')
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
            << "0x" << setw(8) << configIter->vendor_id
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
            << "/0x" << setw(8) << configIter->product_code;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        info.ident = str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
        str.clear();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
        str.str("");
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   237
        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
   238
            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
   239
1172
74ee632c3b5e Fixed attached slave position in 'ethercat config' -> decimal.
Florian Pose <fp@igh-essen.com>
parents: 1167
diff changeset
   240
            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
   241
            info.slavePos = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   242
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   243
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   244
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   245
            str << 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
   246
            info.state = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   247
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   248
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   249
        } else {
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   250
            str << "-";
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   251
            info.slavePos = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   252
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   253
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   254
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   255
            str << "-";
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   256
            info.state = str.str();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   257
            str.clear();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   258
            str.str("");
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   259
        }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
        list.push_back(info);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
        if (info.alias.length() > maxAliasWidth)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
            maxAliasWidth = info.alias.length();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
        if (info.pos.length() > maxPosWidth)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
            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
   267
        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
   268
            maxSlavePosWidth = info.slavePos.length();
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   269
        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
   270
            maxStateWidth = info.state.length();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
    for (iter = list.begin(); iter != list.end(); iter++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
        cout << setfill(' ') << right
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
            << setw(maxAliasWidth) << iter->alias
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
            << ":" << left
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
            << setw(maxPosWidth) << iter->pos
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
            << "  "
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
            << iter->ident
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
            << "  "
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   281
            << setw(maxSlavePosWidth) << iter->slavePos << "  "
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   282
            << setw(maxStateWidth) << iter->state << "  "
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
            << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
/*****************************************************************************/