author | Florian Pose <fp@igh-essen.com> |
Wed, 23 Jul 2008 16:18:48 +0000 | |
changeset 1138 | 4149af40c0e2 |
parent 1137 | a73c0f54be42 |
child 1139 | 074caa25365e |
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 |
#include <string> |
956
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
953
diff
changeset
|
13 |
#include <vector> |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
14 |
#include <list> |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
using namespace std; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
17 |
#include "globals.h" |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
18 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
19 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
20 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
21 |
string binaryBaseName; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
22 |
unsigned int masterIndex = 0; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
23 |
int slavePosition = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
24 |
int domainIndex = -1; |
1125 | 25 |
string commandName; |
956
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
953
diff
changeset
|
26 |
vector<string> commandArgs; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
27 |
Verbosity verbosity = Normal; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
28 |
string dataTypeStr; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
29 |
bool force = false; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
30 |
|
1121 | 31 |
bool helpRequested = false; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
33 |
MasterDevice masterDev; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
34 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
35 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
36 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
37 |
struct Command { |
1125 | 38 |
const char *name; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
39 |
void (*func)(void); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
40 |
const char *helpString; |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
41 |
const char *briefDesc; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
42 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
43 |
int execute(void) const; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
44 |
void displayHelp(void) const; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
45 |
}; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
46 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
47 |
/*****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
48 |
|
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
49 |
#define DEFINE_EXTERN_COMMAND(name) \ |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
50 |
void command_##name(void); \ |
1125 | 51 |
extern const char *help_##name |
52 |
||
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
53 |
#define INIT_COMMAND(name, desc) \ |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
54 |
{#name, command_##name, help_##name, desc} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
55 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
56 |
DEFINE_EXTERN_COMMAND(alias); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
57 |
DEFINE_EXTERN_COMMAND(config); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
58 |
DEFINE_EXTERN_COMMAND(data); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
59 |
DEFINE_EXTERN_COMMAND(debug); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
60 |
DEFINE_EXTERN_COMMAND(domains); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
61 |
DEFINE_EXTERN_COMMAND(master); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
62 |
DEFINE_EXTERN_COMMAND(pdos); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
63 |
DEFINE_EXTERN_COMMAND(sdos); |
1134
3356141fa2f8
Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
1129
diff
changeset
|
64 |
DEFINE_EXTERN_COMMAND(download); |
3356141fa2f8
Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
1129
diff
changeset
|
65 |
DEFINE_EXTERN_COMMAND(upload); |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
66 |
DEFINE_EXTERN_COMMAND(slaves); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
67 |
DEFINE_EXTERN_COMMAND(sii_read); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
68 |
DEFINE_EXTERN_COMMAND(sii_write); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
69 |
DEFINE_EXTERN_COMMAND(states); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
70 |
DEFINE_EXTERN_COMMAND(xml); |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
71 |
|
1125 | 72 |
static const Command commands[] = { |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
73 |
INIT_COMMAND(alias, "Write alias addresses."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
74 |
INIT_COMMAND(config, "Show bus configuration."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
75 |
INIT_COMMAND(data, "Output binary domain process data."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
76 |
INIT_COMMAND(debug, "Set the master's debug level."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
77 |
INIT_COMMAND(domains, "Show domain information."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
78 |
INIT_COMMAND(master, "Show master information."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
79 |
INIT_COMMAND(pdos, "List Pdo assignment/mapping."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
80 |
INIT_COMMAND(sdos, "List Sdo dictionaries."), |
1134
3356141fa2f8
Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
1129
diff
changeset
|
81 |
INIT_COMMAND(download, "Write an Sdo entry."), |
3356141fa2f8
Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
1129
diff
changeset
|
82 |
INIT_COMMAND(upload, "Read an Sdo entry."), |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
83 |
INIT_COMMAND(slaves, "Show slaves."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
84 |
INIT_COMMAND(sii_read, "Output a slave's SII contents."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
85 |
INIT_COMMAND(sii_write, "Write slave's SII contents."), |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
86 |
INIT_COMMAND(states, "Request slave states."), |
1128 | 87 |
INIT_COMMAND(xml, "Generate slave information XML."), |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
88 |
}; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
89 |
|
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
90 |
static const Command *cmdEnd = commands + sizeof(commands) / sizeof(Command); |
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 |
void printUsage() |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
95 |
{ |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
96 |
const Command *cmd; |
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 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
99 |
for (cmd = commands; cmd < cmdEnd; cmd++) { |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
100 |
if (strlen(cmd->name) > maxWidth) { |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
101 |
maxWidth = strlen(cmd->name); |
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 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
105 |
cerr |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
106 |
<< "Usage: " << binaryBaseName << " <COMMAND> [OPTIONS] [ARGUMENTS]" |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
107 |
<< endl << endl |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
108 |
<< "Commands (can be abbreviated):" << endl; |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
109 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
110 |
cerr << left; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
111 |
for (cmd = commands; cmd < cmdEnd; cmd++) { |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
112 |
cerr << " " << setw(maxWidth) << cmd->name |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
113 |
<< " " << cmd->briefDesc << endl; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
114 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
115 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
116 |
cerr |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
117 |
<< endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
118 |
<< "Global options:" << endl |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
119 |
<< " --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
|
120 |
<< endl |
1137
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
121 |
<< " --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
|
122 |
<< " --quiet -q Output less information." << endl |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
123 |
<< " --verbose -v Output more information." << endl |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
124 |
<< " --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
|
125 |
<< endl |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
126 |
<< "Numerical values can be specified either with decimal " |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
127 |
<< "(no prefix)," << endl |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
128 |
<< "octal (prefix '0') or hexadecimal (prefix '0x') base." << endl |
a73c0f54be42
Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
1136
diff
changeset
|
129 |
<< endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
130 |
<< "Call '" << binaryBaseName |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
131 |
<< " <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
|
132 |
<< endl |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
133 |
<< "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
134 |
} |
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 |
void getOptions(int argc, char **argv) |
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 |
int c, argCount, optionIndex, number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
141 |
char *remainder; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
142 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
143 |
static struct option longOptions[] = { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
144 |
//name, has_arg, flag, val |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
145 |
{"master", required_argument, NULL, 'm'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
146 |
{"slave", required_argument, NULL, 's'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
147 |
{"domain", required_argument, NULL, 'd'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
148 |
{"type", required_argument, NULL, 't'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
149 |
{"force", no_argument, NULL, 'f'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
150 |
{"quiet", no_argument, NULL, 'q'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
151 |
{"verbose", no_argument, NULL, 'v'}, |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
152 |
{"help", no_argument, NULL, 'h'}, |
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 |
}; |
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 |
do { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
157 |
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
|
158 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
159 |
switch (c) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
160 |
case 'm': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
161 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
162 |
if (remainder == optarg || *remainder || number < 0) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
163 |
cerr << "Invalid master number " << optarg << "!" << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
164 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
165 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
166 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
167 |
masterIndex = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
168 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
169 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
170 |
case 's': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
171 |
if (!strcmp(optarg, "all")) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
172 |
slavePosition = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
173 |
} else { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
174 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
175 |
if (remainder == optarg || *remainder |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
176 |
|| number < 0 || number > 0xFFFF) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
177 |
cerr << "Invalid slave position " |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
178 |
<< optarg << "!" << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
179 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
180 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
181 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
182 |
slavePosition = number; |
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 |
break; |
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 |
case 'd': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
187 |
if (!strcmp(optarg, "all")) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
188 |
domainIndex = -1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
189 |
} else { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
190 |
number = strtoul(optarg, &remainder, 0); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
191 |
if (remainder == optarg || *remainder || number < 0) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
192 |
cerr << "Invalid domain index " |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
193 |
<< optarg << "!" << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
194 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
195 |
exit(1); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
196 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
197 |
domainIndex = number; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
198 |
} |
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 't': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
202 |
dataTypeStr = optarg; |
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 'f': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
206 |
force = true; |
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 'q': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
210 |
verbosity = Quiet; |
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 'v': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
214 |
verbosity = Verbose; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
215 |
break; |
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 |
case 'h': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
218 |
helpRequested = true; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
219 |
break; |
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 |
case '?': |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
222 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
223 |
exit(1); |
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 |
default: |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
226 |
break; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
227 |
} |
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 |
while (c != -1); |
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 |
argCount = argc - optind; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
232 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
233 |
if (!argCount) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
234 |
if (!helpRequested) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
235 |
cerr << "Please specify a command!" << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
236 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
237 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
238 |
exit(!helpRequested); |
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 |
|
1125 | 241 |
commandName = argv[optind]; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
242 |
while (++optind < argc) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
243 |
commandArgs.push_back(string(argv[optind])); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
244 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
245 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
246 |
/****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
247 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
248 |
int Command::execute() const |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
249 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
250 |
try { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
251 |
func(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
252 |
} catch (InvalidUsageException &e) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
253 |
cerr << e.what() << endl << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
254 |
displayHelp(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
255 |
return 1; |
1136
a0982873d655
Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents:
1134
diff
changeset
|
256 |
} catch (CommandException &e) { |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
257 |
cerr << e.what() << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
258 |
return 1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
259 |
} catch (MasterDeviceException &e) { |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
260 |
cerr << e.what() << endl; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
261 |
return 1; |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
262 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
263 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
264 |
return 0; |
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 |
void Command::displayHelp() const |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
270 |
{ |
1125 | 271 |
cerr << binaryBaseName << " " << commandName << " " << helpString; |
272 |
} |
|
273 |
||
274 |
/****************************************************************************/ |
|
275 |
||
1127 | 276 |
bool substrMatch(const string &abb, const string &full) |
277 |
{ |
|
278 |
return full.substr(0, abb.length()) == abb; |
|
279 |
} |
|
280 |
||
281 |
/****************************************************************************/ |
|
282 |
||
1125 | 283 |
bool abbrevMatch(const string &abb, const string &full) |
284 |
{ |
|
285 |
unsigned int abbIndex; |
|
286 |
size_t fullPos = 0; |
|
287 |
||
288 |
for (abbIndex = 0; abbIndex < abb.length(); abbIndex++) { |
|
289 |
fullPos = full.find(abb[abbIndex], fullPos); |
|
290 |
if (fullPos == string::npos) |
|
291 |
return false; |
|
292 |
} |
|
293 |
||
294 |
return true; |
|
295 |
} |
|
296 |
||
297 |
/****************************************************************************/ |
|
298 |
||
299 |
list<const Command *> getMatchingCommands(const string &cmdStr) |
|
300 |
{ |
|
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
301 |
const Command *cmd; |
1125 | 302 |
list<const Command *> res; |
303 |
||
1127 | 304 |
// find matching commands from beginning of the string |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
305 |
for (cmd = commands; cmd < cmdEnd; cmd++) { |
1127 | 306 |
if (substrMatch(cmdStr, cmd->name)) { |
1125 | 307 |
res.push_back(cmd); |
308 |
} |
|
309 |
} |
|
310 |
||
1127 | 311 |
if (!res.size()) { // nothing found |
312 |
// find /any/ matching commands |
|
313 |
for (cmd = commands; cmd < cmdEnd; cmd++) { |
|
314 |
if (abbrevMatch(cmdStr, cmd->name)) { |
|
315 |
res.push_back(cmd); |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
||
1125 | 320 |
return res; |
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
321 |
} |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
322 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
323 |
/****************************************************************************/ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
324 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
325 |
int main(int argc, char **argv) |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
326 |
{ |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
327 |
int retval = 0; |
1125 | 328 |
list<const Command *> commands; |
329 |
list<const Command *>::const_iterator ci; |
|
330 |
const Command *cmd; |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
331 |
|
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
332 |
binaryBaseName = basename(argv[0]); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
333 |
getOptions(argc, argv); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
334 |
|
1125 | 335 |
commands = getMatchingCommands(commandName); |
336 |
||
337 |
if (commands.size()) { |
|
338 |
if (commands.size() == 1) { |
|
339 |
cmd = commands.front(); |
|
1129
4bc1d9f9d73c
Replace abbreviation by full command.
Florian Pose <fp@igh-essen.com>
parents:
1128
diff
changeset
|
340 |
commandName = cmd->name; |
1125 | 341 |
if (!helpRequested) { |
342 |
masterDev.setIndex(masterIndex); |
|
343 |
retval = cmd->execute(); |
|
344 |
} else { |
|
345 |
cmd->displayHelp(); |
|
346 |
} |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
347 |
} else { |
1128 | 348 |
cerr << "Ambiguous command abbreviation! Matching:" << endl; |
1125 | 349 |
for (ci = commands.begin(); ci != commands.end(); ci++) { |
350 |
cerr << (*ci)->name << endl; |
|
351 |
} |
|
352 |
cerr << endl; |
|
353 |
printUsage(); |
|
354 |
retval = 1; |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
355 |
} |
1125 | 356 |
} else { |
357 |
cerr << "Unknown command " << commandName << "!" << endl << endl; |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
358 |
printUsage(); |
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
359 |
retval = 1; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
360 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
361 |
|
1122
ee305a780a02
First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
1121
diff
changeset
|
362 |
return retval; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
363 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
364 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
365 |
/****************************************************************************/ |
1126
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
366 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
367 |
void printRawData( |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
368 |
const uint8_t *data, |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
369 |
unsigned int size |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
370 |
) |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
371 |
{ |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
372 |
cout << hex << setfill('0'); |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
373 |
while (size--) { |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
374 |
cout << "0x" << setw(2) << (unsigned int) *data++; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
375 |
if (size) |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
376 |
cout << " "; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
377 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
378 |
cout << endl; |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
379 |
} |
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
380 |
|
b09fd81894cb
Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
1125
diff
changeset
|
381 |
/****************************************************************************/ |