author | Florian Pose <fp@igh-essen.com> |
Fri, 05 Mar 2010 17:48:50 +0100 | |
changeset 1842 | 6d3190b9d464 |
parent 1834 | 67fc217d7341 |
child 1869 | 14f634f5b613 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
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:
1337
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
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:
1337
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:
1337
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
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:
1337
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:
1337
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:
1337
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
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:
1337
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:
1337
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:
1337
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1337
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:
1337
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:
1337
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1142 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#include "Command.h" |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
31 |
#include "MasterDevice.h" |
1142 | 32 |
|
33 |
/*****************************************************************************/ |
|
34 |
||
35 |
Command::Command(const string &name, const string &briefDesc): |
|
36 |
name(name), |
|
37 |
briefDesc(briefDesc), |
|
38 |
verbosity(Normal) |
|
39 |
{ |
|
40 |
} |
|
41 |
||
42 |
/*****************************************************************************/ |
|
43 |
||
44 |
Command::~Command() |
|
45 |
{ |
|
46 |
} |
|
47 |
||
48 |
/*****************************************************************************/ |
|
49 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
50 |
void Command::setMasterIndices(const MasterIndexList &indices) |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
51 |
{ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
52 |
masterIndices = indices; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
53 |
}; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
54 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
55 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
56 |
|
1142 | 57 |
void Command::setVerbosity(Verbosity v) |
58 |
{ |
|
1804 | 59 |
verbosity = v; |
1142 | 60 |
}; |
61 |
||
1151 | 62 |
/*****************************************************************************/ |
63 |
||
64 |
void Command::setAlias(int a) |
|
65 |
{ |
|
1804 | 66 |
alias = a; |
1151 | 67 |
}; |
68 |
||
69 |
/*****************************************************************************/ |
|
70 |
||
71 |
void Command::setPosition(int p) |
|
72 |
{ |
|
1804 | 73 |
position = p; |
1151 | 74 |
}; |
75 |
||
1166 | 76 |
/*****************************************************************************/ |
77 |
||
78 |
void Command::setDomain(int d) |
|
79 |
{ |
|
1804 | 80 |
domain = d; |
1166 | 81 |
}; |
82 |
||
83 |
/*****************************************************************************/ |
|
84 |
||
85 |
void Command::setDataType(const string &t) |
|
86 |
{ |
|
1804 | 87 |
dataType = t; |
1166 | 88 |
}; |
89 |
||
90 |
/*****************************************************************************/ |
|
91 |
||
92 |
void Command::setForce(bool f) |
|
93 |
{ |
|
1804 | 94 |
force = f; |
1166 | 95 |
}; |
96 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
97 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
98 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
99 |
void Command::setOutputFile(const string &f) |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
100 |
{ |
1804 | 101 |
outputFile = f; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
102 |
}; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
103 |
|
1142 | 104 |
/****************************************************************************/ |
105 |
||
106 |
bool Command::matchesSubstr(const string &cmd) const |
|
107 |
{ |
|
108 |
return name.substr(0, cmd.length()) == cmd; |
|
109 |
} |
|
110 |
||
111 |
/****************************************************************************/ |
|
112 |
||
113 |
bool Command::matchesAbbrev(const string &abb) const |
|
114 |
{ |
|
115 |
unsigned int i; |
|
116 |
size_t pos = 0; |
|
117 |
||
118 |
for (i = 0; i < abb.length(); i++) { |
|
119 |
pos = name.find(abb[i], pos); |
|
120 |
if (pos == string::npos) |
|
121 |
return false; |
|
122 |
} |
|
123 |
||
124 |
return true; |
|
125 |
} |
|
126 |
||
127 |
/*****************************************************************************/ |
|
128 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
129 |
string Command::numericInfo() |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
130 |
{ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
131 |
stringstream str; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
132 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
133 |
str << "Numerical values can be specified either with decimal (no" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
134 |
<< "prefix), octal (prefix '0') or hexadecimal (prefix '0x') base." |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
135 |
<< endl; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
136 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
137 |
return str.str(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
138 |
} |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
139 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
140 |
/*****************************************************************************/ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
141 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
142 |
void Command::throwInvalidUsageException(const stringstream &s) const |
1142 | 143 |
{ |
144 |
throw InvalidUsageException(s); |
|
145 |
} |
|
146 |
||
147 |
/*****************************************************************************/ |
|
148 |
||
1834
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
149 |
void Command::throwCommandException(const string &msg) const |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
150 |
{ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
151 |
throw CommandException(msg); |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
152 |
} |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
153 |
|
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
154 |
/*****************************************************************************/ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
155 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
156 |
void Command::throwCommandException(const stringstream &s) const |
1142 | 157 |
{ |
158 |
throw CommandException(s); |
|
159 |
} |
|
160 |
||
1151 | 161 |
/*****************************************************************************/ |
162 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
163 |
void Command::throwSingleSlaveRequired(unsigned int size) const |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
164 |
{ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
165 |
stringstream err; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
166 |
|
1199 | 167 |
err << "The slave selection matches " << size << " slaves. '" |
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
168 |
<< name << "' requires a single slave."; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
169 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
170 |
throwInvalidUsageException(err); |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
171 |
} |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
172 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
173 |
/*****************************************************************************/ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
174 |
|
1151 | 175 |
Command::SlaveList Command::selectedSlaves(MasterDevice &m) |
176 |
{ |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
177 |
ec_ioctl_master_t master; |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
178 |
unsigned int i, aliasIndex; |
1151 | 179 |
uint16_t lastAlias; |
180 |
ec_ioctl_slave_t slave; |
|
181 |
SlaveList list; |
|
182 |
||
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
183 |
m.getMaster(&master); |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
184 |
|
1151 | 185 |
if (alias == -1) { // no alias given |
186 |
if (position == -1) { // no alias and position given |
|
187 |
// all items |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
188 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 189 |
m.getSlave(&slave, i); |
190 |
list.push_back(slave); |
|
191 |
} |
|
192 |
} else { // no alias, but position given |
|
193 |
// one item by position |
|
194 |
m.getSlave(&slave, position); |
|
195 |
list.push_back(slave); |
|
196 |
} |
|
197 |
} else { // alias given |
|
198 |
if (position == -1) { // alias, but no position given |
|
199 |
// take all items with a given alias |
|
200 |
lastAlias = 0; |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
201 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 202 |
m.getSlave(&slave, i); |
203 |
if (slave.alias) { |
|
204 |
lastAlias = slave.alias; |
|
205 |
} |
|
206 |
if (lastAlias == (uint16_t) alias) { |
|
207 |
list.push_back(slave); |
|
208 |
} |
|
209 |
} |
|
210 |
} else { // alias and position given |
|
211 |
lastAlias = 0; |
|
212 |
aliasIndex = 0; |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
213 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 214 |
m.getSlave(&slave, i); |
1159
25cc77cf3993
Improved alias/position addressing in case od duplicated aliases.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
215 |
if (slave.alias && slave.alias == (uint16_t) alias) { |
1151 | 216 |
lastAlias = slave.alias; |
217 |
aliasIndex = 0; |
|
218 |
} |
|
1159
25cc77cf3993
Improved alias/position addressing in case od duplicated aliases.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
219 |
if (lastAlias && aliasIndex == (unsigned int) position) { |
1151 | 220 |
list.push_back(slave); |
221 |
} |
|
222 |
aliasIndex++; |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
return list; |
|
228 |
} |
|
229 |
||
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
230 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
231 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
232 |
bool operator<( |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
233 |
const ec_ioctl_config_t &a, |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
234 |
const ec_ioctl_config_t &b |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
235 |
) |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
236 |
{ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
237 |
return a.alias < b.alias |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
238 |
|| (a.alias == b.alias && a.position < b.position); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
239 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
240 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
241 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
242 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
243 |
Command::ConfigList Command::selectedConfigs(MasterDevice &m) |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
244 |
{ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
245 |
unsigned int i; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
246 |
ec_ioctl_master_t master; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
247 |
ec_ioctl_config_t config; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
248 |
ConfigList list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
249 |
stringstream err; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
250 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
251 |
m.getMaster(&master); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
252 |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
253 |
if (alias == -1) { // no alias given |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
254 |
if (position == -1) { // no alias and position given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
255 |
// all items |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
256 |
for (i = 0; i < master.config_count; i++) { |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
257 |
m.getConfig(&config, i); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
258 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
259 |
} |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
260 |
} else { // no alias, but position given |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
261 |
for (i = 0; i < master.config_count; i++) { |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
262 |
m.getConfig(&config, i); |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
263 |
if (!config.alias && config.position == position) { |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
264 |
list.push_back(config); |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
265 |
break; // there can be at most one matching |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
266 |
} |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
267 |
} |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
268 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
269 |
} else { // alias given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
270 |
if (position == -1) { // alias, but no position given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
271 |
// take all items with a given alias |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
272 |
for (i = 0; i < master.config_count; i++) { |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
273 |
m.getConfig(&config, i); |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
274 |
if (config.alias == alias) { |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
275 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
276 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
277 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
278 |
} else { // alias and position given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
279 |
for (i = 0; i < master.config_count; i++) { |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
280 |
m.getConfig(&config, i); |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
281 |
if (config.alias == alias && config.position == position) { |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
282 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
283 |
break; // there can be at most one matching |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
284 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
285 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
286 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
287 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
288 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
289 |
list.sort(); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
290 |
return list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
291 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
292 |
|
1142 | 293 |
/****************************************************************************/ |
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
294 |
|
1166 | 295 |
Command::DomainList Command::selectedDomains(MasterDevice &m) |
296 |
{ |
|
1804 | 297 |
ec_ioctl_domain_t d; |
298 |
DomainList list; |
|
1166 | 299 |
|
300 |
if (domain == -1) { |
|
1804 | 301 |
ec_ioctl_master_t master; |
1166 | 302 |
unsigned int i; |
303 |
||
304 |
m.getMaster(&master); |
|
305 |
||
306 |
for (i = 0; i < master.domain_count; i++) { |
|
1804 | 307 |
m.getDomain(&d, i); |
308 |
list.push_back(d); |
|
1166 | 309 |
} |
310 |
} else { |
|
1804 | 311 |
m.getDomain(&d, domain); |
312 |
list.push_back(d); |
|
313 |
} |
|
314 |
||
315 |
return list; |
|
1166 | 316 |
} |
317 |
||
318 |
/****************************************************************************/ |
|
319 |
||
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
320 |
string Command::alStateString(uint8_t state) |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
321 |
{ |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
322 |
switch (state) { |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
323 |
case 1: return "INIT"; |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
324 |
case 2: return "PREOP"; |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
325 |
case 3: return "BOOT"; |
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
326 |
case 4: return "SAFEOP"; |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
327 |
case 8: return "OP"; |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
328 |
default: return "???"; |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
329 |
} |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
330 |
} |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
331 |
|
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
332 |
/****************************************************************************/ |