author | Florian Pose <fp@igh-essen.com> |
Fri, 25 Jul 2008 14:10:04 +0000 | |
changeset 1149 | f1fce286d53b |
parent 1144 | 7dbfdd61812c |
child 1151 | 1fc1535dec29 |
permissions | -rw-r--r-- |
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 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
#include <getopt.h> |
1118 | 8 |
#include <libgen.h> // basename() |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
#include <iostream> |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
11 |
#include <iomanip> |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
using namespace std; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
14 |
#include "CommandAlias.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
15 |
#include "CommandConfig.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
16 |
#include "CommandData.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
17 |
#include "CommandDebug.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
18 |
#include "CommandDomains.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
19 |
#include "CommandMaster.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
20 |
#include "CommandPdos.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
21 |
#include "CommandSdos.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
22 |
#include "CommandDownload.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
23 |
#include "CommandUpload.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
24 |
#include "CommandSlaves.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
25 |
#include "CommandSiiRead.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
26 |
#include "CommandSiiWrite.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
27 |
#include "CommandStates.h" |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
28 |
#include "CommandXml.h" |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
29 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
30 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
31 |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
32 |
typedef list<Command *> CommandList; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
33 |
CommandList commandList; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
34 |
|
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
35 |
MasterDevice masterDev; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
36 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
37 |
string binaryBaseName; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
38 |
string commandName; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
39 |
Command::StringVector commandArgs; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
40 |
|
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
41 |
// option variables |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
42 |
unsigned int masterIndex = 0; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
43 |
int slavePosition = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
44 |
int domainIndex = -1; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
45 |
string dataTypeStr; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
46 |
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
|
47 |
bool force = false; |
1121 | 48 |
bool helpRequested = false; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
50 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
51 |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
52 |
string usage() |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
53 |
{ |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
54 |
stringstream str; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
55 |
CommandList::const_iterator ci; |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
56 |
size_t maxWidth = 0; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
57 |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
58 |
for (ci = commandList.begin(); ci != commandList.end(); ci++) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
59 |
if ((*ci)->getName().length() > maxWidth) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
60 |
maxWidth = (*ci)->getName().length(); |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
61 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
62 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
63 |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
64 |
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
|
65 |
<< endl << endl |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
66 |
<< "Commands (can be abbreviated):" << endl; |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
67 |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
68 |
str << left; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
69 |
for (ci = commandList.begin(); ci != commandList.end(); ci++) { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
70 |
str << " " << setw(maxWidth) << (*ci)->getName() |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
71 |
<< " " << (*ci)->getBriefDescription() << endl; |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
72 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
73 |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
74 |
str << endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
75 |
<< "Global options:" << endl |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
76 |
<< " --master -m <master> Index of the master to use. Default: 0." |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
77 |
<< endl |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
78 |
<< " --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
|
79 |
<< " --quiet -q Output less information." << endl |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
80 |
<< " --verbose -v Output more information." << endl |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
81 |
<< " --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
|
82 |
<< endl |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
83 |
<< Command::numericInfo() |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
84 |
<< endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
85 |
<< "Call '" << binaryBaseName |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
86 |
<< " <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
|
87 |
<< endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
88 |
<< "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl; |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
89 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
90 |
return str.str(); |
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 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
93 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
94 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
95 |
void getOptions(int argc, char **argv) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
96 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
97 |
int c, argCount, optionIndex, number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
98 |
char *remainder; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
99 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
100 |
static struct option longOptions[] = { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
101 |
//name, has_arg, flag, val |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
102 |
{"master", required_argument, NULL, 'm'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
103 |
{"slave", required_argument, NULL, 's'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
104 |
{"domain", required_argument, NULL, 'd'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
105 |
{"type", required_argument, NULL, 't'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
106 |
{"force", no_argument, NULL, 'f'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
107 |
{"quiet", no_argument, NULL, 'q'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
108 |
{"verbose", no_argument, NULL, 'v'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
109 |
{"help", no_argument, NULL, 'h'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
110 |
{} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
111 |
}; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
112 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
113 |
do { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
114 |
c = getopt_long(argc, argv, "m:s:d:t:fqvh", longOptions, &optionIndex); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
115 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
116 |
switch (c) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
117 |
case 'm': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
118 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
119 |
if (remainder == optarg || *remainder || number < 0) { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
120 |
cerr << "Invalid master number " << optarg << "!" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
121 |
<< endl << usage(); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
122 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
123 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
124 |
masterIndex = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
125 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
126 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
127 |
case 's': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
128 |
if (!strcmp(optarg, "all")) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
129 |
slavePosition = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
130 |
} else { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
131 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
132 |
if (remainder == optarg || *remainder |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
133 |
|| number < 0 || number > 0xFFFF) { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
134 |
cerr << "Invalid slave position " << optarg << "!" |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
135 |
<< endl << endl << usage(); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
136 |
exit(1); |
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 |
slavePosition = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
139 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
140 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
141 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
142 |
case 'd': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
143 |
if (!strcmp(optarg, "all")) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
144 |
domainIndex = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
145 |
} else { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
146 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
147 |
if (remainder == optarg || *remainder || number < 0) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
148 |
cerr << "Invalid domain index " |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
149 |
<< optarg << "!" << endl << endl << usage(); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
150 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
151 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
152 |
domainIndex = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
153 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
154 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
155 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
156 |
case 't': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
157 |
dataTypeStr = optarg; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
158 |
break; |
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 |
case 'f': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
161 |
force = true; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
162 |
break; |
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 |
case 'q': |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
165 |
verbosity = Command::Quiet; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
166 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
167 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
168 |
case 'v': |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
169 |
verbosity = Command::Verbose; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
170 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
171 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
172 |
case 'h': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
173 |
helpRequested = true; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
174 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
175 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
176 |
case '?': |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
177 |
cerr << endl << usage(); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
178 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
179 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
180 |
default: |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
181 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
182 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
183 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
184 |
while (c != -1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
185 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
186 |
argCount = argc - optind; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
187 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
188 |
if (!argCount) { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
189 |
if (helpRequested) { |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
190 |
cout << usage(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
191 |
exit(0); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
192 |
} else { |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
193 |
cerr << "Please specify a command!" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
194 |
<< endl << usage(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
195 |
exit(1); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
196 |
} |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
197 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
198 |
|
1125 | 199 |
commandName = argv[optind]; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
200 |
while (++optind < argc) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
201 |
commandArgs.push_back(string(argv[optind])); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
202 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
203 |
|
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 |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
206 |
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
|
207 |
{ |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
208 |
CommandList::iterator ci; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
209 |
list<Command *> res; |
1125 | 210 |
|
1127 | 211 |
// find matching commands from beginning of the string |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
212 |
for (ci = commandList.begin(); ci != commandList.end(); ci++) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
213 |
if ((*ci)->matchesSubstr(cmdStr)) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
214 |
res.push_back(*ci); |
1125 | 215 |
} |
216 |
} |
|
217 |
||
1127 | 218 |
if (!res.size()) { // nothing found |
219 |
// find /any/ matching commands |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
220 |
for (ci = commandList.begin(); ci != commandList.end(); ci++) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
221 |
if ((*ci)->matchesAbbrev(cmdStr)) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
222 |
res.push_back(*ci); |
1127 | 223 |
} |
224 |
} |
|
225 |
} |
|
226 |
||
1125 | 227 |
return res; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
228 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
229 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
230 |
/****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
231 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
232 |
int main(int argc, char **argv) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
233 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
234 |
int retval = 0; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
235 |
list<Command *> matchingCommands; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
236 |
list<Command *>::const_iterator ci; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
237 |
Command *cmd; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
238 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
239 |
binaryBaseName = basename(argv[0]); |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
240 |
|
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
241 |
commandList.push_back(new CommandAlias()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
242 |
commandList.push_back(new CommandConfig()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
243 |
commandList.push_back(new CommandData()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
244 |
commandList.push_back(new CommandDebug()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
245 |
commandList.push_back(new CommandDomains()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
246 |
commandList.push_back(new CommandDownload()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
247 |
commandList.push_back(new CommandMaster()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
248 |
commandList.push_back(new CommandPdos()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
249 |
commandList.push_back(new CommandSdos()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
250 |
commandList.push_back(new CommandSiiRead()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
251 |
commandList.push_back(new CommandSiiWrite()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
252 |
commandList.push_back(new CommandSlaves()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
253 |
commandList.push_back(new CommandStates()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
254 |
commandList.push_back(new CommandUpload()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
255 |
commandList.push_back(new CommandXml()); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
256 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
257 |
getOptions(argc, argv); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
258 |
|
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
259 |
matchingCommands = getMatchingCommands(commandName); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
260 |
masterDev.setIndex(masterIndex); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
261 |
|
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
262 |
if (matchingCommands.size()) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
263 |
if (matchingCommands.size() == 1) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
264 |
cmd = matchingCommands.front(); |
1125 | 265 |
if (!helpRequested) { |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
266 |
try { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
267 |
cmd->setVerbosity(verbosity); |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
268 |
cmd->execute(masterDev, commandArgs); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
269 |
} catch (InvalidUsageException &e) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
270 |
cerr << e.what() << endl << endl; |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
271 |
cerr << binaryBaseName << " " << cmd->helpString(); |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
272 |
retval = 1; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
273 |
} catch (CommandException &e) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
274 |
cerr << e.what() << endl; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
275 |
retval = 1; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
276 |
} catch (MasterDeviceException &e) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
277 |
cerr << e.what() << endl; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
278 |
retval = 1; |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
279 |
} |
1125 | 280 |
} else { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
281 |
cout << binaryBaseName << " " << cmd->helpString(); |
1125 | 282 |
} |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
283 |
} else { |
1128 | 284 |
cerr << "Ambiguous command abbreviation! Matching:" << endl; |
1142
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
285 |
for (ci = matchingCommands.begin(); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
286 |
ci != matchingCommands.end(); |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
287 |
ci++) { |
59be91dfcbe1
Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
1139
diff
changeset
|
288 |
cerr << (*ci)->getName() << endl; |
1125 | 289 |
} |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
290 |
cerr << endl << usage(); |
1125 | 291 |
retval = 1; |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
292 |
} |
1125 | 293 |
} else { |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
294 |
cerr << "Unknown command " << commandName << "!" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
295 |
<< endl << usage(); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
296 |
retval = 1; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
297 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
298 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
299 |
return retval; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
300 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
301 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
302 |
/****************************************************************************/ |