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