tool/Command.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 02 Oct 2008 07:16:17 +0000
branchstable-1.4
changeset 1645 bbdaddf33131
parent 1629 70040a399528
child 1335 09c6fce1ae45
permissions -rw-r--r--
Version 1.4.0-rc3.
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
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include "Command.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
Command::Command(const string &name, const string &briefDesc):
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
    name(name),
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
    briefDesc(briefDesc),
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
    verbosity(Normal)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
Command::~Command()
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
void Command::setVerbosity(Verbosity v)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
	verbosity = v;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
};
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    31
/*****************************************************************************/
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    32
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    33
void Command::setAlias(int a)
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    34
{
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    35
	alias = a;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    36
};
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    37
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    38
/*****************************************************************************/
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    39
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    40
void Command::setPosition(int p)
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    41
{
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    42
	position = p;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    43
};
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
    44
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    45
/*****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    46
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    47
void Command::setDomain(int d)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    48
{
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    49
	domain = d;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    50
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    51
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    52
/*****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    53
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    54
void Command::setDataType(const string &t)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    55
{
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    56
	dataType = t;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    57
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    58
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    59
/*****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    60
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    61
void Command::setForce(bool f)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    62
{
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    63
	force = f;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    64
};
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
    65
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
bool Command::matchesSubstr(const string &cmd) const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    return name.substr(0, cmd.length()) == cmd;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
bool Command::matchesAbbrev(const string &abb) const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    unsigned int i;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    size_t pos = 0;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    for (i = 0; i < abb.length(); i++) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        pos = name.find(abb[i], pos);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        if (pos == string::npos)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
            return false;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    return true;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    91
string Command::numericInfo()
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    92
{
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    93
    stringstream str;
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    94
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    95
    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
    96
        << "prefix), octal (prefix '0') or hexadecimal (prefix '0x') base."
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    97
        << endl;
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    98
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    99
    return str.str();
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   100
}
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   101
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   102
/*****************************************************************************/
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
   103
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   104
void Command::throwInvalidUsageException(const stringstream &s) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    throw InvalidUsageException(s);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   111
void Command::throwCommandException(const stringstream &s) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    throw CommandException(s);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   116
/*****************************************************************************/
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   117
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   118
void Command::throwSingleSlaveRequired(unsigned int size) const
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   119
{
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   120
    stringstream err;
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   121
1629
70040a399528 merge -c1422 trunk: Fixed output spacing.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   122
    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
   123
        << name << "' requires a single slave.";
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   124
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   125
    throwInvalidUsageException(err);
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   126
}
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   127
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   128
/*****************************************************************************/
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   129
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   130
Command::SlaveList Command::selectedSlaves(MasterDevice &m)
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   131
{
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   132
    ec_ioctl_master_t master;
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   133
    unsigned int i, aliasIndex;
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   134
    uint16_t lastAlias;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   135
    ec_ioctl_slave_t slave;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   136
    SlaveList list;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   137
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   138
    m.getMaster(&master);
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   139
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   140
    if (alias == -1) { // no alias given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   141
        if (position == -1) { // no alias and position given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   142
            // all items
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   143
            for (i = 0; i < master.slave_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   144
                m.getSlave(&slave, i);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   145
                list.push_back(slave);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   146
            }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   147
        } else { // no alias, but position given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   148
            // one item by position
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   149
            m.getSlave(&slave, position);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   150
            list.push_back(slave);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   151
        }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   152
    } else { // alias given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   153
        if (position == -1) { // alias, but no position given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   154
            // take all items with a given alias
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   155
            lastAlias = 0;
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   156
            for (i = 0; i < master.slave_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   157
                m.getSlave(&slave, i);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   158
                if (slave.alias) {
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   159
                    lastAlias = slave.alias;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   160
                }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   161
                if (lastAlias == (uint16_t) alias) {
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   162
                    list.push_back(slave);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   163
                }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   164
            }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   165
        } else { // alias and position given
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   166
            lastAlias = 0;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   167
            aliasIndex = 0;
1160
f02ff486b313 Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents: 1159
diff changeset
   168
            for (i = 0; i < master.slave_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   169
                m.getSlave(&slave, i);
1159
25cc77cf3993 Improved alias/position addressing in case od duplicated aliases.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
   170
                if (slave.alias && slave.alias == (uint16_t) alias) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   171
                    lastAlias = slave.alias;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   172
                    aliasIndex = 0;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   173
                }
1159
25cc77cf3993 Improved alias/position addressing in case od duplicated aliases.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
   174
                if (lastAlias && aliasIndex == (unsigned int) position) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   175
                    list.push_back(slave);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   176
                }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   177
                aliasIndex++;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   178
            }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   179
        }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   180
    }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   181
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   182
    return list;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   183
}
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1146
diff changeset
   184
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   185
/*****************************************************************************/
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   186
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   187
bool operator<(
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   188
        const ec_ioctl_config_t &a,
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   189
        const ec_ioctl_config_t &b
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   190
        )
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   191
{
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   192
    return a.alias < b.alias
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   193
        || (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
   194
}
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   195
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   196
/*****************************************************************************/
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   197
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   198
Command::ConfigList Command::selectedConfigs(MasterDevice &m)
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   199
{
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   200
    unsigned int i;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   201
    ec_ioctl_master_t master;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   202
    ec_ioctl_config_t config;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   203
    ConfigList list;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   204
    stringstream err;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   205
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   206
    m.getMaster(&master);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   207
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   208
    if (alias == -1) { // no alias given
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   209
        if (position == -1) { // no alias and position given
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   210
            // all items
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   211
            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
   212
                m.getConfig(&config, i);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   213
                list.push_back(config);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   214
            }
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   215
        } else { // no alias, but position given
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   216
            for (i = 0; i < master.config_count; i++) {
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   217
                m.getConfig(&config, i);
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   218
                if (!config.alias && config.position == position) {
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   219
                    list.push_back(config);
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   220
                    break; // there can be at most one matching
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   221
                }
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   222
            }
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   223
        }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   224
    } else { // alias given
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   225
        if (position == -1) { // alias, but no position given
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   226
            // take all items with a given alias
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   227
            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
   228
                m.getConfig(&config, i);
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   229
                if (config.alias == alias) {
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   230
                    list.push_back(config);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   231
                }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   232
            }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   233
        } else { // alias and position given
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   234
            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
   235
                m.getConfig(&config, i);
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1156
diff changeset
   236
                if (config.alias == alias && config.position == position) {
1156
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   237
                    list.push_back(config);
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   238
                    break; // there can be at most one matching
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   239
                }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   240
            }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   241
        }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   242
    }
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   243
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   244
    list.sort();
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   245
    return list;
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   246
}
ecaf2a896ea3 Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
   247
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
/****************************************************************************/
1146
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   249
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   250
Command::DomainList Command::selectedDomains(MasterDevice &m)
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   251
{
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   252
	ec_ioctl_domain_t d;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   253
	DomainList list;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   254
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   255
    if (domain == -1) {
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   256
		ec_ioctl_master_t master;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   257
        unsigned int i;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   258
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   259
        m.getMaster(&master);
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   260
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   261
        for (i = 0; i < master.domain_count; i++) {
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   262
			m.getDomain(&d, i);
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   263
			list.push_back(d);
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   264
        }
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   265
    } else {
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   266
		m.getDomain(&d, domain);
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   267
		list.push_back(d);
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   268
    }
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   269
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   270
	return list;
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   271
}
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   272
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   273
/****************************************************************************/
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   274
1146
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   275
string Command::alStateString(uint8_t state)
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   276
{
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   277
    switch (state) {
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   278
        case 1: return "INIT";
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   279
        case 2: return "PREOP";
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   280
        case 4: return "SAFEOP";
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   281
        case 8: return "OP";
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   282
        default: return "???";
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   283
    }
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   284
}
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   285
f18d124d7fbc Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   286
/****************************************************************************/