tool/Command.cpp
author Patrick Bruenn <p.bruenn@beckhoff.com>
Wed, 23 Apr 2014 13:15:10 +0200
branchstable-1.5
changeset 2552 6e419c23b1b3
parent 2453 d461b1f07296
child 2529 c7e1f2616a9d
permissions -rw-r--r--
added ccat support for kernel 2.6.32
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     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
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
    28
 *  vim: expandtab
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
    29
 *
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    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
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    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
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   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
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
Command::Command(const string &name, const string &briefDesc):
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    name(name),
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    briefDesc(briefDesc),
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    verbosity(Normal)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
Command::~Command()
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   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
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
void Command::setVerbosity(Verbosity v)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   174
    verbosity = v;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
};
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   177
/*****************************************************************************/
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   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
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   196
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   197
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   198
/*****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   199
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   200
void Command::setDataType(const string &t)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   201
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   202
    dataType = t;
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   203
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   204
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   205
/*****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   206
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   207
void Command::setForce(bool f)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   208
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   209
    force = f;
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   210
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   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
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   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
2436
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   219
/*****************************************************************************/
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   220
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   221
void Command::setSkin(const string &s)
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   222
{
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   223
    skin = s;
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   224
};
960cc1bb6b4a EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   225
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
bool Command::matchesSubstr(const string &cmd) const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    return name.substr(0, cmd.length()) == cmd;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
}
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2014
diff changeset
   232
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
bool Command::matchesAbbrev(const string &abb) const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    unsigned int i;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    size_t pos = 0;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    for (i = 0; i < abb.length(); i++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        pos = name.find(abb[i], pos);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
        if (pos == string::npos)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
            return false;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
    return true;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
}
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2014
diff changeset
   248
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   251
string Command::numericInfo()
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   252
{
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   253
    stringstream str;
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
    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
   256
        << "prefix), octal (prefix '0') or hexadecimal (prefix '0x') base."
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   257
        << endl;
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   258
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   259
    return str.str();
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   260
}
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   261
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   262
/*****************************************************************************/
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   263
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   264
void Command::throwInvalidUsageException(const stringstream &s) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    throw InvalidUsageException(s);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
1834
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   271
void Command::throwCommandException(const string &msg) const
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   272
{
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   273
    throw CommandException(msg);
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   274
}
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   275
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   276
/*****************************************************************************/
67fc217d7341 Overloaded throwCommandException().
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   277
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   278
void Command::throwCommandException(const stringstream &s) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    throw CommandException(s);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   283
/*****************************************************************************/
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   284
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   285
void Command::throwSingleSlaveRequired(unsigned int size) const
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
    stringstream err;
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   288
1199
30714bab3a04 Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   289
    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
   290
        << name << "' requires a single slave.";
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   291
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   292
    throwInvalidUsageException(err);
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   293
}
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   294
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   295
/*****************************************************************************/
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   296
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   297
Command::MasterIndexList Command::getMasterIndices() const
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   298
{
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   299
    MasterIndexList indices;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   300
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   301
    try {
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   302
        MasterIndexParser p;
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   303
        indices = p.parse(masters.c_str());
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   304
    } catch (MasterDeviceException &e) {
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   305
        stringstream err;
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   306
        err << "Failed to obtain number of masters: " << e.what();
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   307
        throwCommandException(err);
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   308
    } catch (runtime_error &e) {
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   309
        stringstream err;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   310
        err << "Invalid master argument '" << masters << "': " << e.what();
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   311
        throwInvalidUsageException(err);
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   312
    }
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   313
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   314
    return indices;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   315
}
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   316
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   317
/*****************************************************************************/
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1834
diff changeset
   318
1870
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   319
unsigned int Command::getSingleMasterIndex() const
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   320
{
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   321
    MasterIndexList masterIndices = getMasterIndices();
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   322
1870
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   323
    if (masterIndices.size() != 1) {
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   324
        stringstream err;
1870
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   325
        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
   326
        throwInvalidUsageException(err);
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   327
    }
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   328
1880
f46bec1b5f21 Removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
   329
    return masterIndices.front();
1870
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   330
}
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   331
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   332
/*****************************************************************************/
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   333
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   334
Command::SlaveList Command::selectedSlaves(MasterDevice &m)
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   335
{
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   336
    ec_ioctl_master_t master;
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   337
    unsigned int i;
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   338
    ec_ioctl_slave_t slave;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   339
    SlaveList list;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   340
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   341
    m.getMaster(&master);
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   342
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   343
    if (aliases == "-") { // no alias given
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   344
        PositionParser pp(master.slave_count);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   345
        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
   346
        NumberListParser::List::const_iterator pi;
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   347
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   348
        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
   349
            if (*pi < master.slave_count) {
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   350
                m.getSlave(&slave, *pi);
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   351
                list.push_back(slave);
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   352
            }
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   353
        }
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   354
    } else { // aliases given
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   355
        SlaveAliasParser ap(master, m);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   356
        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
   357
        NumberListParser::List::const_iterator ai;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   358
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   359
        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
   360
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   361
            // 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
   362
            uint16_t lastAlias = 0;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   363
            vector<ec_ioctl_slave_t> aliasSlaves;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   364
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   365
            for (i = 0; i < master.slave_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   366
                m.getSlave(&slave, i);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   367
                if (slave.alias) {
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   368
                    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
   369
                        // 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
   370
                        // assure consistency for the position argument
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   371
                        break;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   372
                    }
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   373
                    lastAlias = slave.alias;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   374
                }
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   375
                if (lastAlias == *ai) {
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   376
                    aliasSlaves.push_back(slave);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   377
                }
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   378
            }
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   379
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   380
            PositionParser pp(aliasSlaves.size());
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   381
            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
   382
            NumberListParser::List::const_iterator pi;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   383
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   384
            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
   385
                if (*pi < aliasSlaves.size()) {
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   386
                    list.push_back(aliasSlaves[*pi]);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   387
                }
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   388
            }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   389
        }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   390
    }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   391
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   392
    return list;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   393
}
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   394
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   395
/*****************************************************************************/
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   396
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   397
bool operator<(
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   398
        const ec_ioctl_config_t &a,
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   399
        const ec_ioctl_config_t &b
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
{
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   402
    return a.alias < b.alias
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   403
        || (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
   404
}
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   405
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   406
/*****************************************************************************/
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   407
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   408
Command::ConfigList Command::selectedConfigs(MasterDevice &m)
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   409
{
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   410
    unsigned int i;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   411
    ec_ioctl_master_t master;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   412
    ec_ioctl_config_t config;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   413
    ConfigList list;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   414
    stringstream err;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   415
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   416
    m.getMaster(&master);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   417
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   418
    if (aliases == "-" && positions == "-") { // shortcut
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   419
        for (i = 0; i < master.config_count; i++) {
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   420
            m.getConfig(&config, i);
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   421
            list.push_back(config);
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   422
        }
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   423
    } else { // take the long way home...
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   424
        ConfigMap configs;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   425
        uint16_t maxAlias = 0;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   426
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   427
        // fill cascaded map structure with all configs
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   428
        for (i = 0; i < master.config_count; i++) {
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   429
            m.getConfig(&config, i);
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   430
            AliasMap &aliasMap = configs[config.alias];
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   431
            aliasMap[config.position] = config;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   432
            if (config.alias > maxAlias) {
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   433
                maxAlias = config.alias;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   434
            }
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   435
        }
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   436
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   437
        ConfigAliasParser ap(maxAlias);
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   438
        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
   439
        NumberListParser::List::const_iterator ai;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   440
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   441
        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
   442
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   443
            ConfigMap::iterator ci = configs.find(*ai);
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   444
            if (ci == configs.end()) {
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   445
                continue;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   446
            }
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   447
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   448
            AliasMap &aliasMap = configs[*ai];
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   449
            AliasPositionParser pp(aliasMap);
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   450
            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
   451
            NumberListParser::List::const_iterator pi;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   452
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   453
            for (pi = posList.begin(); pi != posList.end(); pi++) {
2013
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   454
                AliasMap::const_iterator ci;
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   455
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   456
                ci = aliasMap.find(*pi);
0aea9df5fa21 Fixed / improved config selection.
Florian Pose <fp@igh-essen.com>
parents: 2010
diff changeset
   457
                if (ci != aliasMap.end()) {
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   458
                    list.push_back(ci->second);
1156
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
            }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   461
        }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   462
    }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   463
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   464
    list.sort();
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   465
    return list;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   466
}
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   467
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
/****************************************************************************/
1146
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   469
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   470
Command::DomainList Command::selectedDomains(MasterDevice &m,
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   471
        const ec_ioctl_master_t &io)
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   472
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   473
    DomainList list;
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   474
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   475
    PositionParser pp(io.domain_count);
2010
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   476
    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
   477
    NumberListParser::List::const_iterator di;
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   478
87de63b19e4c Implemented ranges for slaves, configs and domains.
Florian Pose <fp@igh-essen.com>
parents: 1918
diff changeset
   479
    for (di = domList.begin(); di != domList.end(); di++) {
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2436
diff changeset
   480
        if (*di < io.domain_count) {
2014
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   481
            ec_ioctl_domain_t d;
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   482
            m.getDomain(&d, *di);
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   483
            list.push_back(d);
1d2111370ad5 Be more tolerant when selecting slaves and domains.
Florian Pose <fp@igh-essen.com>
parents: 2013
diff changeset
   484
        }
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   485
    }
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   486
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   487
    return list;
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   488
}
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   489
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   490
/****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   491
1146
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   492
string Command::alStateString(uint8_t state)
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   493
{
1918
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   494
    string ret;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   495
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   496
    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
   497
        case 1: ret = "INIT"; break;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   498
        case 2: ret = "PREOP"; break;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   499
        case 3: ret = "BOOT"; break;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   500
        case 4: ret = "SAFEOP"; break;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   501
        case 8: ret = "OP"; break;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   502
        default: ret = "???";
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
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2014
diff changeset
   505
    if (state & EC_SLAVE_STATE_ACK_ERR) {
1918
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   506
        ret += "+ERROR";
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   507
    }
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   508
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   509
    return ret;
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   510
}
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   511
c58633eed20b Fixed AL state display in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1880
diff changeset
   512
/****************************************************************************/