author | Florian Pose <fp@igh-essen.com> |
Mon, 25 Oct 2010 15:46:23 +0200 | |
changeset 1970 | 00e18cef9fc8 |
parent 1918 | c58633eed20b |
child 2010 | 87de63b19e4c |
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 |
* |
1880 | 28 |
* vim: expandtab |
29 |
* |
|
1142 | 30 |
****************************************************************************/ |
31 |
||
32 |
#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
|
33 |
#include "MasterDevice.h" |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
34 |
#include "NumberListParser.h" |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
35 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
36 |
/*****************************************************************************/ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
37 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
38 |
class MasterIndexParser: |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
39 |
public NumberListParser |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
40 |
{ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
41 |
unsigned int getMax() |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
42 |
{ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
43 |
MasterDevice dev; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
44 |
dev.setIndex(0U); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
45 |
dev.open(MasterDevice::Read); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
46 |
return dev.getMasterCount() - 1; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
47 |
}; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
48 |
}; |
1142 | 49 |
|
50 |
/*****************************************************************************/ |
|
51 |
||
52 |
Command::Command(const string &name, const string &briefDesc): |
|
53 |
name(name), |
|
54 |
briefDesc(briefDesc), |
|
55 |
verbosity(Normal) |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
/*****************************************************************************/ |
|
60 |
||
61 |
Command::~Command() |
|
62 |
{ |
|
63 |
} |
|
64 |
||
65 |
/*****************************************************************************/ |
|
66 |
||
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
67 |
void Command::setMasters(const string &m) |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
68 |
{ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
69 |
masters = m; |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
70 |
}; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
71 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
72 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
73 |
|
1142 | 74 |
void Command::setVerbosity(Verbosity v) |
75 |
{ |
|
1804 | 76 |
verbosity = v; |
1142 | 77 |
}; |
78 |
||
1151 | 79 |
/*****************************************************************************/ |
80 |
||
81 |
void Command::setAlias(int a) |
|
82 |
{ |
|
1804 | 83 |
alias = a; |
1151 | 84 |
}; |
85 |
||
86 |
/*****************************************************************************/ |
|
87 |
||
88 |
void Command::setPosition(int p) |
|
89 |
{ |
|
1804 | 90 |
position = p; |
1151 | 91 |
}; |
92 |
||
1166 | 93 |
/*****************************************************************************/ |
94 |
||
95 |
void Command::setDomain(int d) |
|
96 |
{ |
|
1804 | 97 |
domain = d; |
1166 | 98 |
}; |
99 |
||
100 |
/*****************************************************************************/ |
|
101 |
||
102 |
void Command::setDataType(const string &t) |
|
103 |
{ |
|
1804 | 104 |
dataType = t; |
1166 | 105 |
}; |
106 |
||
107 |
/*****************************************************************************/ |
|
108 |
||
109 |
void Command::setForce(bool f) |
|
110 |
{ |
|
1804 | 111 |
force = f; |
1166 | 112 |
}; |
113 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
114 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
115 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
116 |
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
|
117 |
{ |
1804 | 118 |
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
|
119 |
}; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
120 |
|
1142 | 121 |
/****************************************************************************/ |
122 |
||
123 |
bool Command::matchesSubstr(const string &cmd) const |
|
124 |
{ |
|
125 |
return name.substr(0, cmd.length()) == cmd; |
|
126 |
} |
|
127 |
||
128 |
/****************************************************************************/ |
|
129 |
||
130 |
bool Command::matchesAbbrev(const string &abb) const |
|
131 |
{ |
|
132 |
unsigned int i; |
|
133 |
size_t pos = 0; |
|
134 |
||
135 |
for (i = 0; i < abb.length(); i++) { |
|
136 |
pos = name.find(abb[i], pos); |
|
137 |
if (pos == string::npos) |
|
138 |
return false; |
|
139 |
} |
|
140 |
||
141 |
return true; |
|
142 |
} |
|
143 |
||
144 |
/*****************************************************************************/ |
|
145 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
146 |
string Command::numericInfo() |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
147 |
{ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
148 |
stringstream str; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
149 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
150 |
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
|
151 |
<< "prefix), octal (prefix '0') or hexadecimal (prefix '0x') base." |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
152 |
<< endl; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
153 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
154 |
return str.str(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
155 |
} |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
156 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
157 |
/*****************************************************************************/ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
158 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
159 |
void Command::throwInvalidUsageException(const stringstream &s) const |
1142 | 160 |
{ |
161 |
throw InvalidUsageException(s); |
|
162 |
} |
|
163 |
||
164 |
/*****************************************************************************/ |
|
165 |
||
1834
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
166 |
void Command::throwCommandException(const string &msg) const |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
167 |
{ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
168 |
throw CommandException(msg); |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
169 |
} |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
170 |
|
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
171 |
/*****************************************************************************/ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
172 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
173 |
void Command::throwCommandException(const stringstream &s) const |
1142 | 174 |
{ |
175 |
throw CommandException(s); |
|
176 |
} |
|
177 |
||
1151 | 178 |
/*****************************************************************************/ |
179 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
180 |
void Command::throwSingleSlaveRequired(unsigned int size) const |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
181 |
{ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
182 |
stringstream err; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
183 |
|
1199 | 184 |
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
|
185 |
<< name << "' requires a single slave."; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
186 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
187 |
throwInvalidUsageException(err); |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
188 |
} |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
189 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
190 |
/*****************************************************************************/ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
191 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
192 |
Command::MasterIndexList Command::getMasterIndices() const |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
193 |
{ |
1880 | 194 |
MasterIndexList indices; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
195 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
196 |
try { |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
197 |
MasterIndexParser p; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
198 |
indices = p.parse(masters.c_str()); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
199 |
} catch (MasterDeviceException &e) { |
1880 | 200 |
stringstream err; |
201 |
err << "Failed to obtain number of masters: " << e.what(); |
|
202 |
throwCommandException(err); |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
203 |
} catch (runtime_error &e) { |
1880 | 204 |
stringstream err; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
205 |
err << "Invalid master argument '" << masters << "': " << e.what(); |
1880 | 206 |
throwInvalidUsageException(err); |
207 |
} |
|
208 |
||
209 |
return indices; |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
210 |
} |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
211 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
212 |
/*****************************************************************************/ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
213 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
214 |
unsigned int Command::getSingleMasterIndex() const |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
215 |
{ |
1880 | 216 |
MasterIndexList masterIndices = getMasterIndices(); |
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
217 |
if (masterIndices.size() != 1) { |
1880 | 218 |
stringstream err; |
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
219 |
err << getName() << " requires to select a single master!"; |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
220 |
throwInvalidUsageException(err); |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
221 |
} |
1880 | 222 |
return masterIndices.front(); |
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
223 |
} |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
224 |
|
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
225 |
/*****************************************************************************/ |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
226 |
|
1151 | 227 |
Command::SlaveList Command::selectedSlaves(MasterDevice &m) |
228 |
{ |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
229 |
ec_ioctl_master_t master; |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
230 |
unsigned int i, aliasIndex; |
1151 | 231 |
uint16_t lastAlias; |
232 |
ec_ioctl_slave_t slave; |
|
233 |
SlaveList list; |
|
234 |
||
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
235 |
m.getMaster(&master); |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
236 |
|
1151 | 237 |
if (alias == -1) { // no alias given |
238 |
if (position == -1) { // no alias and position given |
|
239 |
// all items |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
240 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 241 |
m.getSlave(&slave, i); |
242 |
list.push_back(slave); |
|
243 |
} |
|
244 |
} else { // no alias, but position given |
|
245 |
// one item by position |
|
246 |
m.getSlave(&slave, position); |
|
247 |
list.push_back(slave); |
|
248 |
} |
|
249 |
} else { // alias given |
|
250 |
if (position == -1) { // alias, but no position given |
|
251 |
// take all items with a given alias |
|
252 |
lastAlias = 0; |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
253 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 254 |
m.getSlave(&slave, i); |
255 |
if (slave.alias) { |
|
256 |
lastAlias = slave.alias; |
|
257 |
} |
|
258 |
if (lastAlias == (uint16_t) alias) { |
|
259 |
list.push_back(slave); |
|
260 |
} |
|
261 |
} |
|
262 |
} else { // alias and position given |
|
263 |
lastAlias = 0; |
|
264 |
aliasIndex = 0; |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
265 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 266 |
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
|
267 |
if (slave.alias && slave.alias == (uint16_t) alias) { |
1151 | 268 |
lastAlias = slave.alias; |
269 |
aliasIndex = 0; |
|
270 |
} |
|
1159
25cc77cf3993
Improved alias/position addressing in case od duplicated aliases.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
271 |
if (lastAlias && aliasIndex == (unsigned int) position) { |
1151 | 272 |
list.push_back(slave); |
273 |
} |
|
274 |
aliasIndex++; |
|
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
return list; |
|
280 |
} |
|
281 |
||
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
282 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
283 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
284 |
bool operator<( |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
285 |
const ec_ioctl_config_t &a, |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
286 |
const ec_ioctl_config_t &b |
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 |
return a.alias < b.alias |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
290 |
|| (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
|
291 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
292 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
293 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
294 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
295 |
Command::ConfigList Command::selectedConfigs(MasterDevice &m) |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
296 |
{ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
297 |
unsigned int i; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
298 |
ec_ioctl_master_t master; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
299 |
ec_ioctl_config_t config; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
300 |
ConfigList list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
301 |
stringstream err; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
302 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
303 |
m.getMaster(&master); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
304 |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
305 |
if (alias == -1) { // no alias given |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
306 |
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
|
307 |
// all items |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
308 |
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
|
309 |
m.getConfig(&config, i); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
310 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
311 |
} |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
312 |
} else { // no alias, but position given |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
313 |
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
|
314 |
m.getConfig(&config, i); |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
315 |
if (!config.alias && config.position == position) { |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
316 |
list.push_back(config); |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
317 |
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
|
318 |
} |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
319 |
} |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
320 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
321 |
} else { // alias given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
322 |
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
|
323 |
// take all items with a given alias |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
324 |
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
|
325 |
m.getConfig(&config, i); |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
326 |
if (config.alias == alias) { |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
327 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
328 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
329 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
330 |
} else { // alias and position given |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
331 |
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
|
332 |
m.getConfig(&config, i); |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
333 |
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
|
334 |
list.push_back(config); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
335 |
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
|
336 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
337 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
338 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
339 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
340 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
341 |
list.sort(); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
342 |
return list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
343 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
344 |
|
1142 | 345 |
/****************************************************************************/ |
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
346 |
|
1166 | 347 |
Command::DomainList Command::selectedDomains(MasterDevice &m) |
348 |
{ |
|
1804 | 349 |
ec_ioctl_domain_t d; |
350 |
DomainList list; |
|
1166 | 351 |
|
352 |
if (domain == -1) { |
|
1804 | 353 |
ec_ioctl_master_t master; |
1166 | 354 |
unsigned int i; |
355 |
||
356 |
m.getMaster(&master); |
|
357 |
||
358 |
for (i = 0; i < master.domain_count; i++) { |
|
1804 | 359 |
m.getDomain(&d, i); |
360 |
list.push_back(d); |
|
1166 | 361 |
} |
362 |
} else { |
|
1804 | 363 |
m.getDomain(&d, domain); |
364 |
list.push_back(d); |
|
365 |
} |
|
366 |
||
367 |
return list; |
|
1166 | 368 |
} |
369 |
||
370 |
/****************************************************************************/ |
|
371 |
||
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
372 |
string Command::alStateString(uint8_t state) |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
373 |
{ |
1918
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
374 |
string ret; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
375 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
376 |
switch (state & EC_SLAVE_STATE_MASK) { |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
377 |
case 1: ret = "INIT"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
378 |
case 2: ret = "PREOP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
379 |
case 3: ret = "BOOT"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
380 |
case 4: ret = "SAFEOP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
381 |
case 8: ret = "OP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
382 |
default: ret = "???"; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
383 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
384 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
385 |
if (state & EC_SLAVE_STATE_ACK_ERR) { |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
386 |
ret += "+ERROR"; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
387 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
388 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
389 |
return ret; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
390 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
391 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
392 |
/****************************************************************************/ |