tool/main.cpp
author Florian Pose <fp@igh-essen.com>
Mon, 21 Oct 2013 19:27:50 +0200
branchstable-1.5
changeset 2532 bdadf6da4914
parent 2529 c7e1f2616a9d
child 2666 d9e14a0ddbd6
permissions -rw-r--r--
Added configure switch --disable-rt-syslog.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
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: 1335
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
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: 1335
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: 1335
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
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: 1335
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: 1335
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: 1335
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
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: 1335
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: 1335
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: 1335
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
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: 1335
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: 1335
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <getopt.h>
1118
9487162e4d4d helpWanted; cmdName.
Florian Pose <fp@igh-essen.com>
parents: 1099
diff changeset
    31
#include <libgen.h> // basename()
1222
7348d6abb6cb Applied patch by Karsten Schwinne, adding a few header files necessary
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    32
#include <stdlib.h>
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <iostream>
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
    35
#include <iomanip>
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
using namespace std;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    38
#include "CommandAlias.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    39
#include "CommandConfig.h"
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
    40
#include "CommandCStruct.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    41
#include "CommandData.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    42
#include "CommandDebug.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    43
#include "CommandDomains.h"
1165
c5d6e28eec91 Added 'ethercat version' command.
Florian Pose <fp@igh-essen.com>
parents: 1158
diff changeset
    44
#include "CommandDownload.h"
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
    45
#ifdef EC_EOE
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
    46
# include "CommandEoe.h"
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
    47
#endif
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
    48
#include "CommandFoeRead.h"
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
    49
#include "CommandFoeWrite.h"
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    50
#include "CommandGraph.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    51
#include "CommandMaster.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    52
#include "CommandPdos.h"
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    53
#include "CommandRegRead.h"
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    54
#include "CommandRegWrite.h"
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
    55
#include "CommandRescan.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    56
#include "CommandSdos.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    57
#include "CommandSiiRead.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    58
#include "CommandSiiWrite.h"
1165
c5d6e28eec91 Added 'ethercat version' command.
Florian Pose <fp@igh-essen.com>
parents: 1158
diff changeset
    59
#include "CommandSlaves.h"
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    60
#include "CommandSoeRead.h"
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    61
#include "CommandSoeWrite.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    62
#include "CommandStates.h"
1165
c5d6e28eec91 Added 'ethercat version' command.
Florian Pose <fp@igh-essen.com>
parents: 1158
diff changeset
    63
#include "CommandUpload.h"
c5d6e28eec91 Added 'ethercat version' command.
Florian Pose <fp@igh-essen.com>
parents: 1158
diff changeset
    64
#include "CommandVersion.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    65
#include "CommandXml.h"
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    66
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    67
#include "MasterDevice.h"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    68
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    69
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    70
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    71
typedef list<Command *> CommandList;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    72
CommandList commandList;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    73
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    74
string binaryBaseName;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    75
string commandName;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    76
Command::StringVector commandArgs;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    77
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    78
// option variables
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    79
string masters = "-"; // all masters
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
    80
string positions = "-"; // all positions
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
    81
string aliases = "-"; // all aliases
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
    82
string domains = "-"; // all domains
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    83
string dataTypeStr;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    84
Command::Verbosity verbosity = Command::Normal;
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
    85
bool force = false;
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
    86
bool emergency = false;
1121
52a005ffd011 helpRequested.
Florian Pose <fp@igh-essen.com>
parents: 1120
diff changeset
    87
bool helpRequested = false;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
    88
string outputFile;
2436
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
    89
string skin;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    91
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    92
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    93
string usage()
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
    94
{
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    95
    stringstream str;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    96
    CommandList::const_iterator ci;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
    97
    size_t maxWidth = 0;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
    98
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
    99
    for (ci = commandList.begin(); ci != commandList.end(); ci++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   100
        if ((*ci)->getName().length() > maxWidth) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   101
            maxWidth = (*ci)->getName().length();
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   102
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   103
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   104
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   105
    str << "Usage: " << binaryBaseName << " <COMMAND> [OPTIONS] [ARGUMENTS]"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   106
        << endl << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   107
        << "Commands (can be abbreviated):" << endl;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   108
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   109
    str << left;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   110
    for (ci = commandList.begin(); ci != commandList.end(); ci++) {
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   111
        str << "  " << setw(maxWidth) << (*ci)->getName()
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   112
            << "  " << (*ci)->getBriefDescription() << endl;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   113
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1125
diff changeset
   114
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   115
    str << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   116
        << "Global options:" << endl
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   117
        << "  --master  -m <master>  Comma separated list of masters" << endl
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   118
        << "                         to select, ranges are allowed." << endl
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   119
        << "                         Examples: '1,3', '5-7,9', '-3'." << endl
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   120
        << "                         Default: '-' (all)."
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   121
        << endl
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   122
        << "  --force   -f           Force a command." << endl
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   123
        << "  --quiet   -q           Output less information." << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   124
        << "  --verbose -v           Output more information." << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   125
        << "  --help    -h           Show this help." << endl
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   126
        << endl
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   127
        << Command::numericInfo()
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   128
        << endl
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   129
        << "Call '" << binaryBaseName
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   130
        << " <COMMAND> --help' for command-specific help." << endl
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   131
        << endl
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   132
        << "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl;
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   133
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   134
    return str.str();
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   135
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   136
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   137
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   138
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   139
void getOptions(int argc, char **argv)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   140
{
1158
f65164fa4a58 Removed parameter values 'all'.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   141
    int c, argCount;
f65164fa4a58 Removed parameter values 'all'.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   142
    stringstream str;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   143
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   144
    static struct option longOptions[] = {
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   145
        //name,         has_arg,           flag, val
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   146
        {"master",      required_argument, NULL, 'm'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   147
        {"alias",       required_argument, NULL, 'a'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   148
        {"position",    required_argument, NULL, 'p'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   149
        {"domain",      required_argument, NULL, 'd'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   150
        {"type",        required_argument, NULL, 't'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   151
        {"output-file", required_argument, NULL, 'o'},
2436
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   152
        {"skin",        required_argument, NULL, 's'},
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   153
        {"emergency",   no_argument,       NULL, 'e'},
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   154
        {"force",       no_argument,       NULL, 'f'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   155
        {"quiet",       no_argument,       NULL, 'q'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   156
        {"verbose",     no_argument,       NULL, 'v'},
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   157
        {"help",        no_argument,       NULL, 'h'},
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   158
        {}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   159
    };
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   160
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   161
    do {
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   162
        c = getopt_long(argc, argv, "m:a:p:d:t:o:s:efqvh", longOptions, NULL);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   163
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   164
        switch (c) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   165
            case 'm':
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   166
                masters = optarg;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   167
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   168
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   169
            case 'a':
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   170
                aliases = optarg;
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   171
                break;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   172
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   173
            case 'p':
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   174
                positions = optarg;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   175
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   176
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   177
            case 'd':
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   178
                domains = optarg;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   179
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   180
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   181
            case 't':
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   182
                dataTypeStr = optarg;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   183
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   184
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   185
            case 'o':
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   186
                outputFile = optarg;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   187
                break;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   188
2436
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   189
            case 's':
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   190
                skin = optarg;
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   191
                break;
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   192
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   193
            case 'e':
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   194
                emergency = true;
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   195
                break;
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   196
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   197
            case 'f':
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   198
                force = true;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   199
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   200
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   201
            case 'q':
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   202
                verbosity = Command::Quiet;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   203
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   204
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   205
            case 'v':
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   206
                verbosity = Command::Verbose;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   207
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   208
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   209
            case 'h':
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   210
                helpRequested = true;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   211
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   212
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   213
            case '?':
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   214
                cerr << endl << usage();
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   215
                exit(1);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   216
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   217
            default:
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   218
                break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   219
        }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   220
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   221
    while (c != -1);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   222
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   223
    argCount = argc - optind;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   224
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   225
    if (!argCount) {
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   226
        if (helpRequested) {
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   227
            cout << usage();
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   228
            exit(0);
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   229
        } else {
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   230
            cerr << "Please specify a command!" << endl
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   231
                << endl << usage();
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   232
            exit(1);
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   233
        }
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   234
    }
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   235
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   236
    commandName = argv[optind];
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   237
    while (++optind < argc)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   238
        commandArgs.push_back(string(argv[optind]));
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   239
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   240
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   241
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   242
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   243
list<Command *> getMatchingCommands(const string &cmdStr)
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   244
{
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   245
    CommandList::iterator ci;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   246
    list<Command *> res;
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   247
1127
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   248
    // find matching commands from beginning of the string
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   249
    for (ci = commandList.begin(); ci != commandList.end(); ci++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   250
        if ((*ci)->matchesSubstr(cmdStr)) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   251
            res.push_back(*ci);
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   252
        }
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   253
    }
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   254
1127
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   255
    if (!res.size()) { // nothing found
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   256
        // find /any/ matching commands
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   257
        for (ci = commandList.begin(); ci != commandList.end(); ci++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   258
            if ((*ci)->matchesAbbrev(cmdStr)) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   259
                res.push_back(*ci);
1127
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   260
            }
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   261
        }
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   262
    }
bd7aef6c310c Improved abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   263
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   264
    return res;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   265
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   266
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   267
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   268
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   269
int main(int argc, char **argv)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   270
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   271
    int retval = 0;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   272
    list<Command *> matchingCommands;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   273
    list<Command *>::const_iterator ci;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   274
    Command *cmd;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   275
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   276
    binaryBaseName = basename(argv[0]);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   277
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   278
    commandList.push_back(new CommandAlias());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   279
    commandList.push_back(new CommandConfig());
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
   280
    commandList.push_back(new CommandCStruct());
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   281
    commandList.push_back(new CommandData());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   282
    commandList.push_back(new CommandDebug());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   283
    commandList.push_back(new CommandDomains());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   284
    commandList.push_back(new CommandDownload());
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
   285
#ifdef EC_EOE
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   286
    commandList.push_back(new CommandEoe());
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
   287
#endif
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   288
    commandList.push_back(new CommandFoeRead());
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   289
    commandList.push_back(new CommandFoeWrite());
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   290
    commandList.push_back(new CommandGraph());
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   291
    commandList.push_back(new CommandMaster());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   292
    commandList.push_back(new CommandPdos());
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   293
    commandList.push_back(new CommandRegRead());
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   294
    commandList.push_back(new CommandRegWrite());
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   295
    commandList.push_back(new CommandRescan());
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   296
    commandList.push_back(new CommandSdos());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   297
    commandList.push_back(new CommandSiiRead());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   298
    commandList.push_back(new CommandSiiWrite());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   299
    commandList.push_back(new CommandSlaves());
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   300
    commandList.push_back(new CommandSoeRead());
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
   301
    commandList.push_back(new CommandSoeWrite());
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   302
    commandList.push_back(new CommandStates());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   303
    commandList.push_back(new CommandUpload());
1165
c5d6e28eec91 Added 'ethercat version' command.
Florian Pose <fp@igh-essen.com>
parents: 1158
diff changeset
   304
    commandList.push_back(new CommandVersion());
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   305
    commandList.push_back(new CommandXml());
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   306
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   307
    getOptions(argc, argv);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   308
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   309
    matchingCommands = getMatchingCommands(commandName);
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   310
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   311
    if (matchingCommands.size()) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   312
        if (matchingCommands.size() == 1) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   313
            cmd = matchingCommands.front();
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   314
            if (!helpRequested) {
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   315
                try {
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   316
                    cmd->setMasters(masters);
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   317
                    cmd->setVerbosity(verbosity);
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   318
                    cmd->setAliases(aliases);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   319
                    cmd->setPositions(positions);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   320
                    cmd->setDomains(domains);
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1165
diff changeset
   321
                    cmd->setDataType(dataTypeStr);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   322
                    cmd->setOutputFile(outputFile);
2436
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2011
diff changeset
   323
                    cmd->setSkin(skin);
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   324
                    cmd->setEmergency(emergency);
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1165
diff changeset
   325
                    cmd->setForce(force);
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   326
                    cmd->execute(commandArgs);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   327
                } catch (InvalidUsageException &e) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   328
                    cerr << e.what() << endl << endl;
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   329
                    cerr << cmd->helpString(binaryBaseName);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   330
                    retval = 1;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   331
                } catch (CommandException &e) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   332
                    cerr << e.what() << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   333
                    retval = 1;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   334
                } catch (MasterDeviceException &e) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   335
                    cerr << e.what() << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   336
                    retval = 1;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   337
                }
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   338
            } else {
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
   339
                cout << cmd->helpString(binaryBaseName);
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   340
            }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   341
        } else {
1128
b69b2c850160 Fixed typos.
Florian Pose <fp@igh-essen.com>
parents: 1127
diff changeset
   342
            cerr << "Ambiguous command abbreviation! Matching:" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   343
            for (ci = matchingCommands.begin();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   344
                    ci != matchingCommands.end();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   345
                    ci++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents: 1139
diff changeset
   346
                cerr << (*ci)->getName() << endl;
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   347
            }
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   348
            cerr << endl << usage();
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   349
            retval = 1;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   350
        }
1125
9976f7b9fe66 Command abbreviation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   351
    } else {
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   352
        cerr << "Unknown command " << commandName << "!" << endl
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   353
            << endl << usage();
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents: 1121
diff changeset
   354
        retval = 1;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   357
    return retval;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
/****************************************************************************/