author | Florian Pose <fp@igh-essen.com> |
Fri, 13 May 2011 15:34:20 +0200 | |
changeset 2068 | 3001f6523e63 |
parent 2014 | 1d2111370ad5 |
child 2421 | bc2d4bf9cbe5 |
child 2589 | 2b9c78543663 |
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 |
||
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
32 |
#include <map> |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
33 |
using namespace std; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
34 |
|
1142 | 35 |
#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
|
36 |
#include "MasterDevice.h" |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
37 |
#include "NumberListParser.h" |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
38 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
39 |
/*****************************************************************************/ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
40 |
|
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
41 |
typedef map<uint16_t, ec_ioctl_config_t> AliasMap; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
42 |
typedef map<uint16_t, AliasMap> ConfigMap; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
43 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
44 |
/*****************************************************************************/ |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
45 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
46 |
class MasterIndexParser: |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
47 |
public NumberListParser |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
48 |
{ |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
49 |
protected: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
50 |
int getMax() { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
51 |
MasterDevice dev; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
52 |
dev.setIndex(0U); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
53 |
dev.open(MasterDevice::Read); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
54 |
return (int) dev.getMasterCount() - 1; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
55 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
56 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
57 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
58 |
/*****************************************************************************/ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
59 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
60 |
class SlaveAliasParser: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
61 |
public NumberListParser |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
62 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
63 |
public: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
64 |
SlaveAliasParser(ec_ioctl_master_t &master, MasterDevice &dev): |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
65 |
master(master), dev(dev) {} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
66 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
67 |
protected: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
68 |
int getMax() { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
69 |
unsigned int i; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
70 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
71 |
uint16_t maxAlias = 0; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
72 |
for (i = 0; i < master.slave_count; i++) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
73 |
ec_ioctl_slave_t slave; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
74 |
dev.getSlave(&slave, i); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
75 |
if (slave.alias > maxAlias) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
76 |
maxAlias = slave.alias; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
77 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
78 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
79 |
return maxAlias ? maxAlias : -1; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
80 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
81 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
82 |
private: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
83 |
ec_ioctl_master_t &master; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
84 |
MasterDevice &dev; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
85 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
86 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
87 |
/*****************************************************************************/ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
88 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
89 |
class ConfigAliasParser: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
90 |
public NumberListParser |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
91 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
92 |
public: |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
93 |
ConfigAliasParser(unsigned int maxAlias): |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
94 |
maxAlias(maxAlias) {} |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
95 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
96 |
protected: |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
97 |
int getMax() { return maxAlias; }; |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
98 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
99 |
private: |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
100 |
unsigned int maxAlias; |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
101 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
102 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
103 |
/*****************************************************************************/ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
104 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
105 |
class PositionParser: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
106 |
public NumberListParser |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
107 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
108 |
public: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
109 |
PositionParser(unsigned int count): |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
110 |
count(count) {} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
111 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
112 |
protected: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
113 |
int getMax() { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
114 |
return count - 1; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
115 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
116 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
117 |
private: |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
118 |
const unsigned int count; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
119 |
}; |
1142 | 120 |
|
121 |
/*****************************************************************************/ |
|
122 |
||
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
123 |
class AliasPositionParser: |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
124 |
public NumberListParser |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
125 |
{ |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
126 |
public: |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
127 |
AliasPositionParser(const AliasMap &aliasMap): |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
128 |
aliasMap(aliasMap) {} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
129 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
130 |
protected: |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
131 |
int getMax() { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
132 |
AliasMap::const_iterator i; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
133 |
int maxPos = -1; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
134 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
135 |
for (i = aliasMap.begin(); i != aliasMap.end(); i++) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
136 |
if (i->first > maxPos) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
137 |
maxPos = i->first; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
138 |
} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
139 |
} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
140 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
141 |
return maxPos; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
142 |
}; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
143 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
144 |
private: |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
145 |
const AliasMap &aliasMap; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
146 |
}; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
147 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
148 |
/*****************************************************************************/ |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
149 |
|
1142 | 150 |
Command::Command(const string &name, const string &briefDesc): |
151 |
name(name), |
|
152 |
briefDesc(briefDesc), |
|
153 |
verbosity(Normal) |
|
154 |
{ |
|
155 |
} |
|
156 |
||
157 |
/*****************************************************************************/ |
|
158 |
||
159 |
Command::~Command() |
|
160 |
{ |
|
161 |
} |
|
162 |
||
163 |
/*****************************************************************************/ |
|
164 |
||
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
165 |
void Command::setMasters(const string &m) |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
166 |
{ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
167 |
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
|
168 |
}; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
169 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
170 |
/*****************************************************************************/ |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
171 |
|
1142 | 172 |
void Command::setVerbosity(Verbosity v) |
173 |
{ |
|
1804 | 174 |
verbosity = v; |
1142 | 175 |
}; |
176 |
||
1151 | 177 |
/*****************************************************************************/ |
178 |
||
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
179 |
void Command::setAliases(const string &a) |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
180 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
181 |
aliases = a; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
182 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
183 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
184 |
/*****************************************************************************/ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
185 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
186 |
void Command::setPositions(const string &p) |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
187 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
188 |
positions = p; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
189 |
}; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
190 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
191 |
/*****************************************************************************/ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
192 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
193 |
void Command::setDomains(const string &d) |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
194 |
{ |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
195 |
domains = d; |
1166 | 196 |
}; |
197 |
||
198 |
/*****************************************************************************/ |
|
199 |
||
200 |
void Command::setDataType(const string &t) |
|
201 |
{ |
|
1804 | 202 |
dataType = t; |
1166 | 203 |
}; |
204 |
||
205 |
/*****************************************************************************/ |
|
206 |
||
207 |
void Command::setForce(bool f) |
|
208 |
{ |
|
1804 | 209 |
force = f; |
1166 | 210 |
}; |
211 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
212 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
213 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
214 |
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
|
215 |
{ |
1804 | 216 |
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
|
217 |
}; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1199
diff
changeset
|
218 |
|
1142 | 219 |
/****************************************************************************/ |
220 |
||
221 |
bool Command::matchesSubstr(const string &cmd) const |
|
222 |
{ |
|
223 |
return name.substr(0, cmd.length()) == cmd; |
|
224 |
} |
|
225 |
||
226 |
/****************************************************************************/ |
|
227 |
||
228 |
bool Command::matchesAbbrev(const string &abb) const |
|
229 |
{ |
|
230 |
unsigned int i; |
|
231 |
size_t pos = 0; |
|
232 |
||
233 |
for (i = 0; i < abb.length(); i++) { |
|
234 |
pos = name.find(abb[i], pos); |
|
235 |
if (pos == string::npos) |
|
236 |
return false; |
|
237 |
} |
|
238 |
||
239 |
return true; |
|
240 |
} |
|
241 |
||
242 |
/*****************************************************************************/ |
|
243 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
244 |
string Command::numericInfo() |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
245 |
{ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
246 |
stringstream str; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
247 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
248 |
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
|
249 |
<< "prefix), octal (prefix '0') or hexadecimal (prefix '0x') base." |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
250 |
<< endl; |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
251 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
252 |
return str.str(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
253 |
} |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
254 |
|
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
255 |
/*****************************************************************************/ |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
256 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
257 |
void Command::throwInvalidUsageException(const stringstream &s) const |
1142 | 258 |
{ |
259 |
throw InvalidUsageException(s); |
|
260 |
} |
|
261 |
||
262 |
/*****************************************************************************/ |
|
263 |
||
1834
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
264 |
void Command::throwCommandException(const string &msg) const |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
265 |
{ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
266 |
throw CommandException(msg); |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
267 |
} |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
268 |
|
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
269 |
/*****************************************************************************/ |
67fc217d7341
Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
270 |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
271 |
void Command::throwCommandException(const stringstream &s) const |
1142 | 272 |
{ |
273 |
throw CommandException(s); |
|
274 |
} |
|
275 |
||
1151 | 276 |
/*****************************************************************************/ |
277 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
278 |
void Command::throwSingleSlaveRequired(unsigned int size) const |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
279 |
{ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
280 |
stringstream err; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
281 |
|
1199 | 282 |
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
|
283 |
<< name << "' requires a single slave."; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
284 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
285 |
throwInvalidUsageException(err); |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
286 |
} |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
287 |
|
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
288 |
/*****************************************************************************/ |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
289 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
290 |
Command::MasterIndexList Command::getMasterIndices() const |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
291 |
{ |
1880 | 292 |
MasterIndexList indices; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
293 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
294 |
try { |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
295 |
MasterIndexParser p; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
296 |
indices = p.parse(masters.c_str()); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
297 |
} catch (MasterDeviceException &e) { |
1880 | 298 |
stringstream err; |
299 |
err << "Failed to obtain number of masters: " << e.what(); |
|
300 |
throwCommandException(err); |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
301 |
} catch (runtime_error &e) { |
1880 | 302 |
stringstream err; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
303 |
err << "Invalid master argument '" << masters << "': " << e.what(); |
1880 | 304 |
throwInvalidUsageException(err); |
305 |
} |
|
306 |
||
307 |
return indices; |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
308 |
} |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
309 |
|
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
310 |
/*****************************************************************************/ |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1834
diff
changeset
|
311 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
312 |
unsigned int Command::getSingleMasterIndex() const |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
313 |
{ |
1880 | 314 |
MasterIndexList masterIndices = getMasterIndices(); |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
315 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
316 |
if (masterIndices.size() != 1) { |
1880 | 317 |
stringstream err; |
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
318 |
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
|
319 |
throwInvalidUsageException(err); |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
320 |
} |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
321 |
|
1880 | 322 |
return masterIndices.front(); |
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
323 |
} |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
324 |
|
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
325 |
/*****************************************************************************/ |
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
326 |
|
1151 | 327 |
Command::SlaveList Command::selectedSlaves(MasterDevice &m) |
328 |
{ |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
329 |
ec_ioctl_master_t master; |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
330 |
unsigned int i; |
1151 | 331 |
ec_ioctl_slave_t slave; |
332 |
SlaveList list; |
|
333 |
||
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
334 |
m.getMaster(&master); |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
335 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
336 |
if (aliases == "-") { // no alias given |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
337 |
PositionParser pp(master.slave_count); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
338 |
NumberListParser::List posList = pp.parse(positions.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
339 |
NumberListParser::List::const_iterator pi; |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
340 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
341 |
for (pi = posList.begin(); pi != posList.end(); pi++) { |
2014
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
342 |
if (*pi < master.slave_count) { |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
343 |
m.getSlave(&slave, *pi); |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
344 |
list.push_back(slave); |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
345 |
} |
1151 | 346 |
} |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
347 |
} else { // aliases given |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
348 |
SlaveAliasParser ap(master, m); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
349 |
NumberListParser::List aliasList = ap.parse(aliases.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
350 |
NumberListParser::List::const_iterator ai; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
351 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
352 |
for (ai = aliasList.begin(); ai != aliasList.end(); ai++) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
353 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
354 |
// gather slaves with that alias (and following) |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
355 |
uint16_t lastAlias = 0; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
356 |
vector<ec_ioctl_slave_t> aliasSlaves; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
357 |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1159
diff
changeset
|
358 |
for (i = 0; i < master.slave_count; i++) { |
1151 | 359 |
m.getSlave(&slave, i); |
360 |
if (slave.alias) { |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
361 |
if (lastAlias && lastAlias == *ai && slave.alias != *ai) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
362 |
// ignore multiple ocurrences of the same alias to |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
363 |
// assure consistency for the position argument |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
364 |
break; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
365 |
} |
1151 | 366 |
lastAlias = slave.alias; |
367 |
} |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
368 |
if (lastAlias == *ai) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
369 |
aliasSlaves.push_back(slave); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
370 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
371 |
} |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
372 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
373 |
PositionParser pp(aliasSlaves.size()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
374 |
NumberListParser::List posList = pp.parse(positions.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
375 |
NumberListParser::List::const_iterator pi; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
376 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
377 |
for (pi = posList.begin(); pi != posList.end(); pi++) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
378 |
if (*pi < aliasSlaves.size()) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
379 |
list.push_back(aliasSlaves[*pi]); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
380 |
} |
1151 | 381 |
} |
382 |
} |
|
383 |
} |
|
384 |
||
385 |
return list; |
|
386 |
} |
|
387 |
||
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
388 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
389 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
390 |
bool operator<( |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
391 |
const ec_ioctl_config_t &a, |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
392 |
const ec_ioctl_config_t &b |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
393 |
) |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
394 |
{ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
395 |
return a.alias < b.alias |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
396 |
|| (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
|
397 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
398 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
399 |
/*****************************************************************************/ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
400 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
401 |
Command::ConfigList Command::selectedConfigs(MasterDevice &m) |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
402 |
{ |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
403 |
unsigned int i; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
404 |
ec_ioctl_master_t master; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
405 |
ec_ioctl_config_t config; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
406 |
ConfigList list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
407 |
stringstream err; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
408 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
409 |
m.getMaster(&master); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
410 |
|
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
411 |
if (aliases == "-" && positions == "-") { // shortcut |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
412 |
for (i = 0; i < master.config_count; i++) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
413 |
m.getConfig(&config, i); |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
414 |
list.push_back(config); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
415 |
} |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
416 |
} else { // take the long way home... |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
417 |
ConfigMap configs; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
418 |
uint16_t maxAlias = 0; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
419 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
420 |
// fill cascaded map structure with all configs |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
421 |
for (i = 0; i < master.config_count; i++) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
422 |
m.getConfig(&config, i); |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
423 |
AliasMap &aliasMap = configs[config.alias]; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
424 |
aliasMap[config.position] = config; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
425 |
if (config.alias > maxAlias) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
426 |
maxAlias = config.alias; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
427 |
} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
428 |
} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
429 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
430 |
ConfigAliasParser ap(maxAlias); |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
431 |
NumberListParser::List aliasList = ap.parse(aliases.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
432 |
NumberListParser::List::const_iterator ai; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
433 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
434 |
for (ai = aliasList.begin(); ai != aliasList.end(); ai++) { |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
435 |
|
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
436 |
ConfigMap::iterator ci = configs.find(*ai); |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
437 |
if (ci == configs.end()) { |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
438 |
continue; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
439 |
} |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
440 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
441 |
AliasMap &aliasMap = configs[*ai]; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
442 |
AliasPositionParser pp(aliasMap); |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
443 |
NumberListParser::List posList = pp.parse(positions.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
444 |
NumberListParser::List::const_iterator pi; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
445 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
446 |
for (pi = posList.begin(); pi != posList.end(); pi++) { |
2013
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
447 |
AliasMap::const_iterator ci; |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
448 |
|
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
449 |
ci = aliasMap.find(*pi); |
0aea9df5fa21
Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents:
2010
diff
changeset
|
450 |
if (ci != aliasMap.end()) { |
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
451 |
list.push_back(ci->second); |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
452 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
453 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
454 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
455 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
456 |
|
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
457 |
list.sort(); |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
458 |
return list; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
459 |
} |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
460 |
|
1142 | 461 |
/****************************************************************************/ |
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
462 |
|
1166 | 463 |
Command::DomainList Command::selectedDomains(MasterDevice &m) |
464 |
{ |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
465 |
ec_ioctl_master_t master; |
1804 | 466 |
DomainList list; |
1166 | 467 |
|
2010
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
468 |
m.getMaster(&master); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
469 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
470 |
PositionParser pp(master.domain_count); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
471 |
NumberListParser::List domList = pp.parse(domains.c_str()); |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
472 |
NumberListParser::List::const_iterator di; |
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
473 |
|
87de63b19e4c
Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents:
1918
diff
changeset
|
474 |
for (di = domList.begin(); di != domList.end(); di++) { |
2014
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
475 |
if (*di < master.domain_count) { |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
476 |
ec_ioctl_domain_t d; |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
477 |
m.getDomain(&d, *di); |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
478 |
list.push_back(d); |
1d2111370ad5
Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents:
2013
diff
changeset
|
479 |
} |
1804 | 480 |
} |
481 |
||
482 |
return list; |
|
1166 | 483 |
} |
484 |
||
485 |
/****************************************************************************/ |
|
486 |
||
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
487 |
string Command::alStateString(uint8_t state) |
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
488 |
{ |
1918
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
489 |
string ret; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
490 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
491 |
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
|
492 |
case 1: ret = "INIT"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
493 |
case 2: ret = "PREOP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
494 |
case 3: ret = "BOOT"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
495 |
case 4: ret = "SAFEOP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
496 |
case 8: ret = "OP"; break; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
497 |
default: ret = "???"; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
498 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
499 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
500 |
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
|
501 |
ret += "+ERROR"; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
502 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
503 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
504 |
return ret; |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
505 |
} |
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
506 |
|
c58633eed20b
Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1880
diff
changeset
|
507 |
/****************************************************************************/ |