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