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 string dataTypeStr; |
26 string dataTypeStr; |
|
27 bool force = false; |
27 |
28 |
28 /*****************************************************************************/ |
29 /*****************************************************************************/ |
29 |
30 |
30 void printUsage() |
31 void printUsage() |
31 { |
32 { |
32 cerr |
33 cerr |
33 << "Usage: ethercat <COMMAND> [OPTIONS]" << endl |
34 << "Usage: ethercat <COMMAND> [OPTIONS]" << endl |
34 << "Commands:" << endl |
35 << "Commands:" << endl |
|
36 << " alias Write alias address(es)." << endl |
35 << " data Output binary domain process data." << endl |
37 << " data Output binary domain process data." << endl |
36 << " debug Set the master debug level." << endl |
38 << " debug Set the master debug level." << endl |
37 << " domain Show domain information." << endl |
39 << " domain Show domain information." << endl |
38 << " list (ls, slaves) List all slaves (former 'lsec')." << endl |
40 << " list (ls, slaves) List all slaves (former 'lsec')." << endl |
39 << " master Show master information." << endl |
41 << " master Show master information." << endl |
40 << " pdos List Pdo mapping." << endl |
42 << " pdos List Pdo mapping." << endl |
41 << " sdos List Sdo dictionaries." << endl |
43 << " sdos List Sdo dictionaries." << endl |
42 << " sdo_download (sd) Write an Sdo entry." << endl |
44 << " sdo_download (sd) Write an Sdo entry." << endl |
43 << " sdo_upload (su) Read an Sdo entry." << endl |
45 << " sdo_upload (su) Read an Sdo entry." << endl |
44 << " sii_read (sr) Output a slave's SII contents." << endl |
46 << " sii_read (sr) Output a slave's SII contents." << endl |
|
47 << " sii_write (sw) Write slave's SII contents." << endl |
45 << " state Request slave states." << endl |
48 << " state Request slave states." << endl |
46 << " xml Generate slave information xmls." << endl |
49 << " xml Generate slave information xmls." << endl |
47 << "Global options:" << endl |
50 << "Global options:" << endl |
48 << " --master -m <master> Index of the master to use. Default: " |
51 << " --master -m <master> Index of the master to use. Default: " |
49 << DEFAULT_MASTER << endl |
52 << DEFAULT_MASTER << endl |
54 << " --domain -d <index> Positive numerical index," |
57 << " --domain -d <index> Positive numerical index," |
55 << endl |
58 << endl |
56 << " or 'all' for all domains (default)." |
59 << " or 'all' for all domains (default)." |
57 << endl |
60 << endl |
58 << " --type -t <type> Forced Sdo data type." << endl |
61 << " --type -t <type> Forced Sdo data type." << endl |
|
62 << " --force -f Force action." << endl |
59 << " --quiet -q Show less output." << endl |
63 << " --quiet -q Show less output." << endl |
60 << " --help -h Show this help." << endl; |
64 << " --help -h Show this help." << endl; |
61 } |
65 } |
62 |
66 |
63 /*****************************************************************************/ |
67 /*****************************************************************************/ |
71 //name, has_arg, flag, val |
75 //name, has_arg, flag, val |
72 {"master", required_argument, NULL, 'm'}, |
76 {"master", required_argument, NULL, 'm'}, |
73 {"slave", required_argument, NULL, 's'}, |
77 {"slave", required_argument, NULL, 's'}, |
74 {"domain", required_argument, NULL, 'd'}, |
78 {"domain", required_argument, NULL, 'd'}, |
75 {"type", required_argument, NULL, 't'}, |
79 {"type", required_argument, NULL, 't'}, |
|
80 {"force", no_argument, NULL, 'f'}, |
76 {"quiet", no_argument, NULL, 'q'}, |
81 {"quiet", no_argument, NULL, 'q'}, |
77 {"help", no_argument, NULL, 'h'}, |
82 {"help", no_argument, NULL, 'h'}, |
78 {} |
83 {} |
79 }; |
84 }; |
80 |
85 |
81 do { |
86 do { |
82 c = getopt_long(argc, argv, "m:s:d:t:qh", longOptions, &optionIndex); |
87 c = getopt_long(argc, argv, "m:s:d:t:fqh", longOptions, &optionIndex); |
83 |
88 |
84 switch (c) { |
89 switch (c) { |
85 case 'm': |
90 case 'm': |
86 number = strtoul(optarg, &remainder, 0); |
91 number = strtoul(optarg, &remainder, 0); |
87 if (remainder == optarg || *remainder || number < 0) { |
92 if (remainder == optarg || *remainder || number < 0) { |
164 getOptions(argc, argv); |
173 getOptions(argc, argv); |
165 |
174 |
166 try { |
175 try { |
167 master.setIndex(masterIndex); |
176 master.setIndex(masterIndex); |
168 |
177 |
169 if (command == "data") { |
178 if (command == "alias") { |
|
179 master.writeAlias(slavePosition, force, commandArgs); |
|
180 } else if (command == "data") { |
170 master.outputData(domainIndex); |
181 master.outputData(domainIndex); |
171 } else if (command == "debug") { |
182 } else if (command == "debug") { |
172 master.setDebug(commandArgs); |
183 master.setDebug(commandArgs); |
173 } else if (command == "domain") { |
184 } else if (command == "domain") { |
174 master.showDomains(domainIndex); |
185 master.showDomains(domainIndex); |
184 master.sdoDownload(slavePosition, dataTypeStr, commandArgs); |
195 master.sdoDownload(slavePosition, dataTypeStr, commandArgs); |
185 } else if (command == "sdo_upload" || command == "su") { |
196 } else if (command == "sdo_upload" || command == "su") { |
186 master.sdoUpload(slavePosition, dataTypeStr, commandArgs); |
197 master.sdoUpload(slavePosition, dataTypeStr, commandArgs); |
187 } else if (command == "sii_read" || command == "sr") { |
198 } else if (command == "sii_read" || command == "sr") { |
188 master.siiRead(slavePosition); |
199 master.siiRead(slavePosition); |
|
200 } else if (command == "sii_write" || command == "sw") { |
|
201 master.siiWrite(slavePosition, force, commandArgs); |
189 } else if (command == "state") { |
202 } else if (command == "state") { |
190 master.requestStates(slavePosition, commandArgs); |
203 master.requestStates(slavePosition, commandArgs); |
191 } else if (command == "xml") { |
204 } else if (command == "xml") { |
192 master.generateXml(slavePosition); |
205 master.generateXml(slavePosition); |
193 } else { |
206 } else { |