34 |
36 |
35 struct Command { |
37 struct Command { |
36 const char *name; |
38 const char *name; |
37 void (*func)(void); |
39 void (*func)(void); |
38 const char *helpString; |
40 const char *helpString; |
|
41 const char *briefDesc; |
39 |
42 |
40 int execute(void) const; |
43 int execute(void) const; |
41 void displayHelp(void) const; |
44 void displayHelp(void) const; |
42 }; |
45 }; |
43 |
46 |
44 /*****************************************************************************/ |
47 /*****************************************************************************/ |
45 |
48 |
46 #define COMMAND(name) \ |
49 #define DEFINE_EXTERN_COMMAND(name) \ |
47 void command_##name(void); \ |
50 void command_##name(void); \ |
48 extern const char *help_##name |
51 extern const char *help_##name |
49 |
52 |
50 #define INIT_COMMAND(name) {#name, command_##name, help_##name} |
53 #define INIT_COMMAND(name, desc) \ |
51 |
54 {#name, command_##name, help_##name, desc} |
52 COMMAND(alias); |
55 |
53 COMMAND(config); |
56 DEFINE_EXTERN_COMMAND(alias); |
|
57 DEFINE_EXTERN_COMMAND(config); |
|
58 DEFINE_EXTERN_COMMAND(data); |
|
59 DEFINE_EXTERN_COMMAND(debug); |
|
60 DEFINE_EXTERN_COMMAND(domains); |
|
61 DEFINE_EXTERN_COMMAND(master); |
|
62 DEFINE_EXTERN_COMMAND(pdos); |
|
63 DEFINE_EXTERN_COMMAND(sdos); |
|
64 DEFINE_EXTERN_COMMAND(sdo_download); |
|
65 DEFINE_EXTERN_COMMAND(sdo_upload); |
|
66 DEFINE_EXTERN_COMMAND(slaves); |
|
67 DEFINE_EXTERN_COMMAND(sii_read); |
|
68 DEFINE_EXTERN_COMMAND(sii_write); |
|
69 DEFINE_EXTERN_COMMAND(states); |
|
70 DEFINE_EXTERN_COMMAND(xml); |
54 |
71 |
55 static const Command commands[] = { |
72 static const Command commands[] = { |
56 INIT_COMMAND(alias), |
73 INIT_COMMAND(alias, "Write alias addresses."), |
57 INIT_COMMAND(config), |
74 INIT_COMMAND(config, "Show bus configuration."), |
|
75 INIT_COMMAND(data, "Output binary domain process data."), |
|
76 INIT_COMMAND(debug, "Set the master's debug level."), |
|
77 INIT_COMMAND(domains, "Show domain information."), |
|
78 INIT_COMMAND(master, "Show master information."), |
|
79 INIT_COMMAND(pdos, "List Pdo assignment/mapping."), |
|
80 INIT_COMMAND(sdos, "List Sdo dictionaries."), |
|
81 INIT_COMMAND(sdo_download, "Write an Sdo entry."), |
|
82 INIT_COMMAND(sdo_upload, "Read an Sdo entry."), |
|
83 INIT_COMMAND(slaves, "Show slaves."), |
|
84 INIT_COMMAND(sii_read, "Output a slave's SII contents."), |
|
85 INIT_COMMAND(sii_write, "Write slave's SII contents."), |
|
86 INIT_COMMAND(states, "Request slave states."), |
|
87 INIT_COMMAND(xml, "Generate slave information xmls."), |
58 }; |
88 }; |
59 |
89 |
60 #if 0 |
90 static const Command *cmdEnd = commands + sizeof(commands) / sizeof(Command); |
61 } else if (command == "data") { |
|
62 master.outputData(domainIndex); |
|
63 } else if (command == "debug") { |
|
64 master.setDebug(commandArgs); |
|
65 } else if (command == "domain") { |
|
66 master.showDomains(domainIndex); |
|
67 } else if (command == "master") { |
|
68 master.showMaster(); |
|
69 } else if (command == "pdos") { |
|
70 master.listPdos(slavePosition); |
|
71 } else if (command == "sdos") { |
|
72 master.listSdos(slavePosition); |
|
73 } else if (command == "sdo_download" || command == "sd") { |
|
74 master.sdoDownload(slavePosition, dataTypeStr, commandArgs); |
|
75 } else if (command == "sdo_upload" || command == "su") { |
|
76 master.sdoUpload(slavePosition, dataTypeStr, commandArgs); |
|
77 } else if (command == "slave" || command == "slaves" |
|
78 || command == "list" || command == "ls") { |
|
79 master.showSlaves(slavePosition); |
|
80 } else if (command == "sii_read" || command == "sr") { |
|
81 master.siiRead(slavePosition); |
|
82 } else if (command == "sii_write" || command == "sw") { |
|
83 master.siiWrite(slavePosition, force, commandArgs); |
|
84 } else if (command == "state") { |
|
85 master.requestStates(slavePosition, commandArgs); |
|
86 } else if (command == "xml") { |
|
87 master.generateXml(slavePosition); |
|
88 #endif |
|
89 |
91 |
90 /*****************************************************************************/ |
92 /*****************************************************************************/ |
91 |
93 |
92 void printUsage() |
94 void printUsage() |
93 { |
95 { |
|
96 const Command *cmd; |
|
97 size_t maxWidth = 0; |
|
98 |
|
99 for (cmd = commands; cmd < cmdEnd; cmd++) { |
|
100 if (strlen(cmd->name) > maxWidth) { |
|
101 maxWidth = strlen(cmd->name); |
|
102 } |
|
103 } |
|
104 |
94 cerr |
105 cerr |
95 << "Usage: " << binaryBaseName << " <COMMAND> [OPTIONS]" << endl |
106 << "Usage: " << binaryBaseName << " <COMMAND> [OPTIONS]" << endl |
96 << "Commands:" << endl |
107 << "Commands:" << endl; |
97 << " alias Write alias addresses." << endl |
108 |
98 << " config Show bus configuration." << endl |
109 cerr << left; |
99 << " data Output binary domain process data." << endl |
110 for (cmd = commands; cmd < cmdEnd; cmd++) { |
100 << " debug Set the master's debug level." << endl |
111 cerr << " " << setw(maxWidth) << cmd->name |
101 << " domain Show domain information." << endl |
112 << " " << cmd->briefDesc << endl; |
102 << " master Show master information." << endl |
113 } |
103 << " pdos List Pdo assignment/mapping." << endl |
114 |
104 << " sdo_download Write an Sdo entry." << endl |
115 cerr |
105 << " sdos List Sdo dictionaries." << endl |
|
106 << " sdo_upload Read an Sdo entry." << endl |
|
107 << " sii_read Output a slave's SII contents." << endl |
|
108 << " sii_write Write slave's SII contents." << endl |
|
109 << " slaves Show slaves." << endl |
|
110 << " state Request slave states." << endl |
|
111 << " xml Generate slave information xmls." << endl |
|
112 << "Commands can be generously abbreviated." << endl |
116 << "Commands can be generously abbreviated." << endl |
113 << "Global options:" << endl |
117 << "Global options:" << endl |
114 << " --master -m <master> Index of the master to use. Default: 0" |
118 << " --master -m <master> Index of the master to use. Default: 0" |
115 << endl |
119 << endl |
116 << " --slave -s <index> Positive numerical ring position," |
120 << " --slave -s <index> Positive numerical ring position," |
117 << endl |
121 << endl |
118 << " or 'all' for all slaves (default)." |
122 << " or 'all' for all slaves (default)." |
119 << endl |
|
120 << " --domain -d <index> Positive numerical index," |
|
121 << endl |
123 << endl |
122 << " or 'all' for all domains (default)." |
124 << " or 'all' for all domains (default)." |
123 << endl |
125 << endl |
124 << " --type -t <type> Forced Sdo data type." << endl |
126 << " --type -t <type> Forced Sdo data type." << endl |
125 << " --force -f Force action." << endl |
127 << " --force -f Force action." << endl |