21 static int slavePosition = -1; |
21 static int slavePosition = -1; |
22 static int domainIndex = -1; |
22 static int domainIndex = -1; |
23 static string command; |
23 static string command; |
24 vector<string> commandArgs; |
24 vector<string> commandArgs; |
25 static bool quiet = false; |
25 static bool quiet = false; |
|
26 static bool verbose = false; |
26 string dataTypeStr; |
27 string dataTypeStr; |
27 bool force = false; |
28 bool force = false; |
28 |
29 |
29 /*****************************************************************************/ |
30 /*****************************************************************************/ |
30 |
31 |
31 void printUsage() |
32 void printUsage() |
32 { |
33 { |
33 cerr |
34 cerr |
34 << "Usage: ethercat <COMMAND> [OPTIONS]" << endl |
35 << "Usage: ethercat <COMMAND> [OPTIONS]" << endl |
35 << "Commands:" << endl |
36 << "Commands:" << endl |
36 << " alias Write alias address(es)." << endl |
37 << " alias Write alias addresses." << endl |
37 << " config Show slave configurations." << endl |
38 << " config Show bus configuration." << endl |
38 << " data Output binary domain process data." << endl |
39 << " data Output binary domain process data." << endl |
39 << " debug Set the master debug level." << endl |
40 << " debug Set the master's debug level." << endl |
40 << " domain Show domain information." << endl |
41 << " domain Show domain information." << endl |
41 << " list (ls) List all slaves (former 'lsec')." << endl |
42 << " master Show master information." << endl |
42 << " master Show master information." << endl |
43 << " pdos List Pdo assignment/mapping." << endl |
43 << " pdos List Pdo mapping." << endl |
44 << " sdo_download Write an Sdo entry." << endl |
44 << " sdos List Sdo dictionaries." << endl |
45 << " sdos List Sdo dictionaries." << endl |
45 << " sdo_download (sd) Write an Sdo entry." << endl |
46 << " sdo_upload Read an Sdo entry." << endl |
46 << " sdo_upload (su) Read an Sdo entry." << endl |
47 << " sii_read Output a slave's SII contents." << endl |
47 << " slave Show slave information." << endl |
48 << " sii_write Write slave's SII contents." << endl |
48 << " sii_read (sr) Output a slave's SII contents." << endl |
49 << " slaves Show slaves." << endl |
49 << " sii_write (sw) Write slave's SII contents." << endl |
50 << " state Request slave states." << endl |
50 << " state Request slave states." << endl |
51 << " xml Generate slave information xmls." << endl |
51 << " xml Generate slave information xmls." << endl |
|
52 << "Global options:" << endl |
52 << "Global options:" << endl |
53 << " --master -m <master> Index of the master to use. Default: " |
53 << " --master -m <master> Index of the master to use. Default: " |
54 << DEFAULT_MASTER << endl |
54 << DEFAULT_MASTER << endl |
55 << " --slave -s <index> Positive numerical ring position," |
55 << " --slave -s <index> Positive numerical ring position," |
56 << endl |
56 << endl |
60 << endl |
60 << endl |
61 << " or 'all' for all domains (default)." |
61 << " or 'all' for all domains (default)." |
62 << endl |
62 << endl |
63 << " --type -t <type> Forced Sdo data type." << endl |
63 << " --type -t <type> Forced Sdo data type." << endl |
64 << " --force -f Force action." << endl |
64 << " --force -f Force action." << endl |
65 << " --quiet -q Show less output." << endl |
65 << " --quiet -q Output less information." << endl |
|
66 << " --verbose -v Output more information." << endl |
66 << " --help -h Show this help." << endl; |
67 << " --help -h Show this help." << endl; |
67 } |
68 } |
68 |
69 |
69 /*****************************************************************************/ |
70 /*****************************************************************************/ |
70 |
71 |
72 { |
73 { |
73 int c, argCount, optionIndex, number; |
74 int c, argCount, optionIndex, number; |
74 char *remainder; |
75 char *remainder; |
75 |
76 |
76 static struct option longOptions[] = { |
77 static struct option longOptions[] = { |
77 //name, has_arg, flag, val |
78 //name, has_arg, flag, val |
78 {"master", required_argument, NULL, 'm'}, |
79 {"master", required_argument, NULL, 'm'}, |
79 {"slave", required_argument, NULL, 's'}, |
80 {"slave", required_argument, NULL, 's'}, |
80 {"domain", required_argument, NULL, 'd'}, |
81 {"domain", required_argument, NULL, 'd'}, |
81 {"type", required_argument, NULL, 't'}, |
82 {"type", required_argument, NULL, 't'}, |
82 {"force", no_argument, NULL, 'f'}, |
83 {"force", no_argument, NULL, 'f'}, |
83 {"quiet", no_argument, NULL, 'q'}, |
84 {"quiet", no_argument, NULL, 'q'}, |
84 {"help", no_argument, NULL, 'h'}, |
85 {"verbose", no_argument, NULL, 'v'}, |
|
86 {"help", no_argument, NULL, 'h'}, |
85 {} |
87 {} |
86 }; |
88 }; |
87 |
89 |
88 do { |
90 do { |
89 c = getopt_long(argc, argv, "m:s:d:t:fqh", longOptions, &optionIndex); |
91 c = getopt_long(argc, argv, "m:s:d:t:fqvh", longOptions, &optionIndex); |
90 |
92 |
91 switch (c) { |
93 switch (c) { |
92 case 'm': |
94 case 'm': |
93 number = strtoul(optarg, &remainder, 0); |
95 number = strtoul(optarg, &remainder, 0); |
94 if (remainder == optarg || *remainder || number < 0) { |
96 if (remainder == optarg || *remainder || number < 0) { |
185 master.outputData(domainIndex); |
193 master.outputData(domainIndex); |
186 } else if (command == "debug") { |
194 } else if (command == "debug") { |
187 master.setDebug(commandArgs); |
195 master.setDebug(commandArgs); |
188 } else if (command == "domain") { |
196 } else if (command == "domain") { |
189 master.showDomains(domainIndex); |
197 master.showDomains(domainIndex); |
190 } else if (command == "list" || command == "ls") { |
|
191 master.listSlaves(); |
|
192 } else if (command == "master") { |
198 } else if (command == "master") { |
193 master.showMaster(); |
199 master.showMaster(); |
194 } else if (command == "pdos") { |
200 } else if (command == "pdos") { |
195 master.listPdos(slavePosition, quiet); |
201 master.listPdos(slavePosition, quiet); |
196 } else if (command == "sdos") { |
202 } else if (command == "sdos") { |
197 master.listSdos(slavePosition, quiet); |
203 master.listSdos(slavePosition, quiet); |
198 } else if (command == "sdo_download" || command == "sd") { |
204 } else if (command == "sdo_download" || command == "sd") { |
199 master.sdoDownload(slavePosition, dataTypeStr, commandArgs); |
205 master.sdoDownload(slavePosition, dataTypeStr, commandArgs); |
200 } else if (command == "sdo_upload" || command == "su") { |
206 } else if (command == "sdo_upload" || command == "su") { |
201 master.sdoUpload(slavePosition, dataTypeStr, commandArgs); |
207 master.sdoUpload(slavePosition, dataTypeStr, commandArgs); |
202 } else if (command == "slave") { |
208 } else if (command == "slave" || command == "slaves" |
203 master.showSlaves(slavePosition); |
209 || command == "list" || command == "ls") { |
|
210 master.showSlaves(slavePosition, verbose); |
204 } else if (command == "sii_read" || command == "sr") { |
211 } else if (command == "sii_read" || command == "sr") { |
205 master.siiRead(slavePosition); |
212 master.siiRead(slavePosition); |
206 } else if (command == "sii_write" || command == "sw") { |
213 } else if (command == "sii_write" || command == "sw") { |
207 master.siiWrite(slavePosition, force, commandArgs); |
214 master.siiWrite(slavePosition, force, commandArgs); |
208 } else if (command == "state") { |
215 } else if (command == "state") { |