author | Martin Troxler <martin.troxler@komaxgroup.com> |
Thu, 26 Nov 2009 15:33:48 +0100 | |
changeset 1583 | 017fa8fd9ac1 |
parent 1363 | 11c0b2caa253 |
child 1804 | 742607c464c4 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1142 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#ifndef __COMMAND_H__ |
|
31 |
#define __COMMAND_H__ |
|
32 |
||
33 |
#include <stdexcept> |
|
34 |
#include <vector> |
|
1151 | 35 |
#include <list> |
1142 | 36 |
using namespace std; |
37 |
||
38 |
#include "MasterDevice.h" |
|
39 |
||
40 |
/****************************************************************************/ |
|
41 |
||
42 |
class InvalidUsageException: |
|
43 |
public runtime_error |
|
44 |
{ |
|
45 |
friend class Command; |
|
46 |
||
47 |
protected: |
|
48 |
/** Constructor with stringstream parameter. */ |
|
49 |
InvalidUsageException( |
|
50 |
const stringstream &s /**< Message. */ |
|
51 |
): runtime_error(s.str()) {} |
|
52 |
}; |
|
53 |
||
54 |
/****************************************************************************/ |
|
55 |
||
56 |
class CommandException: |
|
57 |
public runtime_error |
|
58 |
{ |
|
59 |
friend class Command; |
|
60 |
||
61 |
protected: |
|
62 |
/** Constructor with stringstream parameter. */ |
|
63 |
CommandException( |
|
64 |
const stringstream &s /**< Message. */ |
|
65 |
): runtime_error(s.str()) {} |
|
66 |
}; |
|
67 |
||
68 |
/****************************************************************************/ |
|
69 |
||
70 |
class Command |
|
71 |
{ |
|
72 |
public: |
|
73 |
Command(const string &, const string &); |
|
74 |
virtual ~Command(); |
|
75 |
||
1151 | 76 |
const string &getName() const; |
77 |
const string &getBriefDescription() const; |
|
78 |
||
1142 | 79 |
enum Verbosity { |
80 |
Quiet, |
|
81 |
Normal, |
|
82 |
Verbose |
|
83 |
}; |
|
84 |
void setVerbosity(Verbosity); |
|
85 |
Verbosity getVerbosity() const; |
|
1151 | 86 |
void setAlias(int); |
87 |
int getAlias() const; |
|
88 |
void setPosition(int); |
|
89 |
int getPosition() const; |
|
1166 | 90 |
void setDomain(int); |
91 |
int getDomain() const; |
|
92 |
void setDataType(const string &); |
|
93 |
const string &getDataType() const; |
|
94 |
void setForce(bool); |
|
95 |
bool getForce() const; |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
96 |
void setOutputFile(const string &); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
97 |
const string &getOutputFile() const; |
1142 | 98 |
|
99 |
bool matchesSubstr(const string &) const; |
|
100 |
bool matchesAbbrev(const string &) const; |
|
101 |
||
102 |
virtual string helpString() const = 0; |
|
103 |
||
104 |
typedef vector<string> StringVector; |
|
105 |
virtual void execute(MasterDevice &, const StringVector &) = 0; |
|
106 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
107 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
108 |
|
1142 | 109 |
protected: |
1151 | 110 |
enum {BreakAfterBytes = 16}; |
111 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
112 |
void throwInvalidUsageException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
113 |
void throwCommandException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
114 |
void throwSingleSlaveRequired(unsigned int) const; |
1142 | 115 |
|
1151 | 116 |
typedef list<ec_ioctl_slave_t> SlaveList; |
117 |
SlaveList selectedSlaves(MasterDevice &); |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
118 |
typedef list<ec_ioctl_config_t> ConfigList; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
119 |
ConfigList selectedConfigs(MasterDevice &); |
1166 | 120 |
typedef list<ec_ioctl_domain_t> DomainList; |
121 |
DomainList selectedDomains(MasterDevice &); |
|
1151 | 122 |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
123 |
static string alStateString(uint8_t); |
1142 | 124 |
|
125 |
private: |
|
126 |
string name; |
|
127 |
string briefDesc; |
|
128 |
Verbosity verbosity; |
|
1151 | 129 |
int alias; |
130 |
int position; |
|
1166 | 131 |
int domain; |
132 |
string dataType; |
|
133 |
bool force; |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
134 |
string outputFile; |
1142 | 135 |
|
136 |
Command(); |
|
137 |
}; |
|
138 |
||
139 |
/****************************************************************************/ |
|
140 |
||
141 |
inline const string &Command::getName() const |
|
142 |
{ |
|
143 |
return name; |
|
144 |
} |
|
145 |
||
146 |
/****************************************************************************/ |
|
147 |
||
148 |
inline const string &Command::getBriefDescription() const |
|
149 |
{ |
|
150 |
return briefDesc; |
|
151 |
} |
|
152 |
||
153 |
/****************************************************************************/ |
|
154 |
||
155 |
inline Command::Verbosity Command::getVerbosity() const |
|
156 |
{ |
|
157 |
return verbosity; |
|
158 |
} |
|
159 |
||
160 |
/****************************************************************************/ |
|
161 |
||
1151 | 162 |
inline int Command::getAlias() const |
163 |
{ |
|
164 |
return alias; |
|
165 |
} |
|
166 |
||
167 |
/****************************************************************************/ |
|
168 |
||
169 |
inline int Command::getPosition() const |
|
170 |
{ |
|
171 |
return position; |
|
172 |
} |
|
173 |
||
174 |
/****************************************************************************/ |
|
175 |
||
1166 | 176 |
inline int Command::getDomain() const |
177 |
{ |
|
178 |
return domain; |
|
179 |
} |
|
180 |
||
181 |
/****************************************************************************/ |
|
182 |
||
183 |
inline const string &Command::getDataType() const |
|
184 |
{ |
|
185 |
return dataType; |
|
186 |
} |
|
187 |
||
188 |
/****************************************************************************/ |
|
189 |
||
190 |
inline bool Command::getForce() const |
|
191 |
{ |
|
192 |
return force; |
|
193 |
} |
|
194 |
||
195 |
/****************************************************************************/ |
|
196 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
197 |
inline const string &Command::getOutputFile() const |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
198 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
199 |
return outputFile; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
200 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
201 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
202 |
/****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
203 |
|
1142 | 204 |
#endif |