author | Florian Pose <fp@igh-essen.com> |
Wed, 24 Feb 2010 17:24:20 +0100 | |
changeset 1827 | 489be2180f71 |
parent 1826 | ec6223c3b7ec |
child 1834 | 67fc217d7341 |
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> |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
36 |
#include <sstream> |
1142 | 37 |
using namespace std; |
38 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
39 |
#include "../master/ioctl.h" |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
40 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
41 |
class MasterDevice; |
1142 | 42 |
|
43 |
/****************************************************************************/ |
|
44 |
||
45 |
class InvalidUsageException: |
|
46 |
public runtime_error |
|
47 |
{ |
|
48 |
friend class Command; |
|
49 |
||
50 |
protected: |
|
51 |
/** Constructor with stringstream parameter. */ |
|
52 |
InvalidUsageException( |
|
53 |
const stringstream &s /**< Message. */ |
|
54 |
): runtime_error(s.str()) {} |
|
55 |
}; |
|
56 |
||
57 |
/****************************************************************************/ |
|
58 |
||
59 |
class CommandException: |
|
60 |
public runtime_error |
|
61 |
{ |
|
62 |
friend class Command; |
|
63 |
||
64 |
protected: |
|
65 |
/** Constructor with stringstream parameter. */ |
|
66 |
CommandException( |
|
67 |
const stringstream &s /**< Message. */ |
|
68 |
): runtime_error(s.str()) {} |
|
69 |
}; |
|
70 |
||
71 |
/****************************************************************************/ |
|
72 |
||
73 |
class Command |
|
74 |
{ |
|
75 |
public: |
|
76 |
Command(const string &, const string &); |
|
1804 | 77 |
virtual ~Command(); |
1142 | 78 |
|
1151 | 79 |
const string &getName() const; |
80 |
const string &getBriefDescription() const; |
|
81 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
82 |
typedef list<unsigned int> MasterIndexList; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
83 |
void setMasterIndices(const MasterIndexList &); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
84 |
const MasterIndexList &getMasterIndices() const; |
1142 | 85 |
enum Verbosity { |
86 |
Quiet, |
|
87 |
Normal, |
|
88 |
Verbose |
|
89 |
}; |
|
90 |
void setVerbosity(Verbosity); |
|
1804 | 91 |
Verbosity getVerbosity() const; |
1151 | 92 |
void setAlias(int); |
93 |
int getAlias() const; |
|
94 |
void setPosition(int); |
|
95 |
int getPosition() const; |
|
1166 | 96 |
void setDomain(int); |
97 |
int getDomain() const; |
|
98 |
void setDataType(const string &); |
|
99 |
const string &getDataType() const; |
|
1804 | 100 |
void setForce(bool); |
101 |
bool getForce() const; |
|
102 |
void setOutputFile(const string &); |
|
103 |
const string &getOutputFile() const; |
|
1142 | 104 |
|
105 |
bool matchesSubstr(const string &) const; |
|
106 |
bool matchesAbbrev(const string &) const; |
|
107 |
||
108 |
virtual string helpString() const = 0; |
|
109 |
||
110 |
typedef vector<string> StringVector; |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
111 |
virtual void execute(const StringVector &) = 0; |
1142 | 112 |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
113 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
114 |
|
1142 | 115 |
protected: |
1804 | 116 |
enum {BreakAfterBytes = 16}; |
1151 | 117 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
118 |
void throwInvalidUsageException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
119 |
void throwCommandException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
120 |
void throwSingleSlaveRequired(unsigned int) const; |
1142 | 121 |
|
1151 | 122 |
typedef list<ec_ioctl_slave_t> SlaveList; |
123 |
SlaveList selectedSlaves(MasterDevice &); |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
124 |
typedef list<ec_ioctl_config_t> ConfigList; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
125 |
ConfigList selectedConfigs(MasterDevice &); |
1166 | 126 |
typedef list<ec_ioctl_domain_t> DomainList; |
127 |
DomainList selectedDomains(MasterDevice &); |
|
1151 | 128 |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
129 |
static string alStateString(uint8_t); |
1142 | 130 |
|
131 |
private: |
|
1804 | 132 |
string name; |
1142 | 133 |
string briefDesc; |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
134 |
MasterIndexList masterIndices; |
1142 | 135 |
Verbosity verbosity; |
1151 | 136 |
int alias; |
137 |
int position; |
|
1804 | 138 |
int domain; |
139 |
string dataType; |
|
140 |
bool force; |
|
141 |
string outputFile; |
|
1142 | 142 |
|
143 |
Command(); |
|
144 |
}; |
|
145 |
||
146 |
/****************************************************************************/ |
|
147 |
||
148 |
inline const string &Command::getName() const |
|
149 |
{ |
|
150 |
return name; |
|
151 |
} |
|
152 |
||
153 |
/****************************************************************************/ |
|
154 |
||
155 |
inline const string &Command::getBriefDescription() const |
|
156 |
{ |
|
157 |
return briefDesc; |
|
158 |
} |
|
159 |
||
160 |
/****************************************************************************/ |
|
161 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
162 |
inline const Command::MasterIndexList &Command::getMasterIndices() const |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
163 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
164 |
return masterIndices; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
165 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
166 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
167 |
/****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
168 |
|
1142 | 169 |
inline Command::Verbosity Command::getVerbosity() const |
170 |
{ |
|
171 |
return verbosity; |
|
172 |
} |
|
173 |
||
174 |
/****************************************************************************/ |
|
175 |
||
1151 | 176 |
inline int Command::getAlias() const |
177 |
{ |
|
178 |
return alias; |
|
179 |
} |
|
180 |
||
181 |
/****************************************************************************/ |
|
182 |
||
183 |
inline int Command::getPosition() const |
|
184 |
{ |
|
185 |
return position; |
|
186 |
} |
|
187 |
||
188 |
/****************************************************************************/ |
|
189 |
||
1166 | 190 |
inline int Command::getDomain() const |
191 |
{ |
|
192 |
return domain; |
|
193 |
} |
|
194 |
||
195 |
/****************************************************************************/ |
|
196 |
||
197 |
inline const string &Command::getDataType() const |
|
198 |
{ |
|
199 |
return dataType; |
|
200 |
} |
|
201 |
||
202 |
/****************************************************************************/ |
|
203 |
||
204 |
inline bool Command::getForce() const |
|
205 |
{ |
|
206 |
return force; |
|
207 |
} |
|
208 |
||
209 |
/****************************************************************************/ |
|
210 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
211 |
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
|
212 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
213 |
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
|
214 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
215 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
216 |
/****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
217 |
|
1142 | 218 |
#endif |