15 |
16 |
16 /*****************************************************************************/ |
17 /*****************************************************************************/ |
17 |
18 |
18 #define DEFAULT_MASTER 0 |
19 #define DEFAULT_MASTER 0 |
19 |
20 |
|
21 static string cmdName; |
20 static unsigned int masterIndex = DEFAULT_MASTER; |
22 static unsigned int masterIndex = DEFAULT_MASTER; |
21 static int slavePosition = -1; |
23 static int slavePosition = -1; |
22 static int domainIndex = -1; |
24 static int domainIndex = -1; |
23 static string command; |
25 static string command; |
24 vector<string> commandArgs; |
26 vector<string> commandArgs; |
25 static Master::Verbosity verbosity = Master::Normal; |
27 static Master::Verbosity verbosity = Master::Normal; |
26 string dataTypeStr; |
28 string dataTypeStr; |
27 bool force = false; |
29 bool force = false; |
|
30 bool helpWanted = false; |
28 |
31 |
29 /*****************************************************************************/ |
32 /*****************************************************************************/ |
30 |
33 |
31 void printUsage() |
34 void printUsage() |
32 { |
35 { |
33 cerr |
36 cerr |
34 << "Usage: ethercat <COMMAND> [OPTIONS]" << endl |
37 << "Usage: " << cmdName << " <COMMAND> [OPTIONS]" << endl |
35 << "Commands:" << endl |
38 << "Commands:" << endl |
36 << " alias Write alias addresses." << endl |
39 << " alias Write alias addresses." << endl |
37 << " config Show bus configuration." << endl |
40 << " config Show bus configuration." << endl |
38 << " data Output binary domain process data." << endl |
41 << " data Output binary domain process data." << endl |
39 << " debug Set the master's debug level." << endl |
42 << " debug Set the master's debug level." << endl |
61 << endl |
64 << endl |
62 << " --type -t <type> Forced Sdo data type." << endl |
65 << " --type -t <type> Forced Sdo data type." << endl |
63 << " --force -f Force action." << endl |
66 << " --force -f Force action." << endl |
64 << " --quiet -q Output less information." << endl |
67 << " --quiet -q Output less information." << endl |
65 << " --verbose -v Output more information." << endl |
68 << " --verbose -v Output more information." << endl |
66 << " --help -h Show this help." << endl; |
69 << " --help -h Show this help." << endl |
|
70 << "Call '" << cmdName << " <COMMAND> --help' for command-specific " |
|
71 << "help." << endl |
|
72 << "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl; |
67 } |
73 } |
68 |
74 |
69 /*****************************************************************************/ |
75 /*****************************************************************************/ |
70 |
76 |
71 void getOptions(int argc, char **argv) |
77 void getOptions(int argc, char **argv) |
146 case 'v': |
152 case 'v': |
147 verbosity = Master::Verbose; |
153 verbosity = Master::Verbose; |
148 break; |
154 break; |
149 |
155 |
150 case 'h': |
156 case 'h': |
|
157 helpWanted = true; |
|
158 break; |
|
159 |
151 case '?': |
160 case '?': |
152 printUsage(); |
161 printUsage(); |
153 exit(0); |
162 exit(1); |
154 |
163 |
155 default: |
164 default: |
156 break; |
165 break; |
157 } |
166 } |
158 } |
167 } |
159 while (c != -1); |
168 while (c != -1); |
160 |
169 |
161 argCount = argc - optind; |
170 argCount = argc - optind; |
162 |
171 |
163 if (!argCount) { |
172 if (!argCount) { |
164 cerr << "Please specify a command!" << endl; |
173 if (!helpWanted) { |
165 printUsage(); |
174 cerr << "Please specify a command!" << endl; |
166 exit(1); |
175 } |
|
176 printUsage(); |
|
177 exit(!helpWanted); |
167 } |
178 } |
168 |
179 |
169 command = argv[optind]; |
180 command = argv[optind]; |
170 while (++optind < argc) |
181 while (++optind < argc) |
171 commandArgs.push_back(string(argv[optind])); |
182 commandArgs.push_back(string(argv[optind])); |
174 /****************************************************************************/ |
185 /****************************************************************************/ |
175 |
186 |
176 int main(int argc, char **argv) |
187 int main(int argc, char **argv) |
177 { |
188 { |
178 Master master; |
189 Master master; |
|
190 |
|
191 cmdName = basename(argv[0]); |
179 |
192 |
180 getOptions(argc, argv); |
193 getOptions(argc, argv); |
181 |
194 |
182 master.setIndex(masterIndex); |
195 master.setIndex(masterIndex); |
183 master.setVerbosity(verbosity); |
196 master.setVerbosity(verbosity); |