tool/cmd_config.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 24 Jul 2008 08:11:07 +0000
changeset 1140 cc779f7d2496
parent 1130 bb1c11adb2db
permissions -rw-r--r--
Command-line help in the docs.
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <list>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#include <iostream>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <iomanip>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <sstream>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
using namespace std;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include "globals.h"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
const char *help_config =
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
    "[OPTIONS]\n"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
    "\n"
1130
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    20
    "Output information about the slave configurations supplied by the\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    21
    "application.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    22
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    23
    "Without the --verbose option, each line of output shows one slave\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    24
    "configuration. Example:\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    25
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    26
    "1001:0  0x0000003b/0x02010000  -  -\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    27
    "|       |                      |  |\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    28
    "|       |                      |  \\- Slave is operational.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    29
    "|       |                      \\- Slave has been found.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    30
    "|       \\- Hexadecimal vendor ID and product code, separated by a\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    31
    "|          slash.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    32
    "\\- Decimal alias and position, separated by a colon.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    33
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    34
    "With the --verbose option given, the configured Pdos and Sdos are\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    35
    "additionally printed.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    36
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    37
    "Command-specific options:\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    38
    "  --verbose  -v  Show detailed configurations.\n";
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
struct ConfigInfo {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
    string alias;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
    string pos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
    string ident;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
    string att;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    string op;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
};
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
typedef list<ec_ioctl_config_t> ConfigList;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void showDetailedConfigs(const ConfigList &configList);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void listConfigs(const ConfigList &configList);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
bool operator<(const ec_ioctl_config_t &a, const ec_ioctl_config_t &b)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    return a.alias < b.alias
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        || (a.alias == b.alias && a.position < b.position);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
/** Lists the bus configuration.
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
 */
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
void command_config(void)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    ec_ioctl_master_t master;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    unsigned int i;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    ec_ioctl_config_t config;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    ConfigList configList;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    masterDev.open(MasterDevice::Read);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    masterDev.getMaster(&master);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    for (i = 0; i < master.config_count; i++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        masterDev.getConfig(&config, i);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        configList.push_back(config);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    configList.sort();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    if (verbosity == Verbose) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
        showDetailedConfigs(configList);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    } else {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        listConfigs(configList);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
/** Lists the complete bus configuration.
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
 */
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
void showDetailedConfigs(const ConfigList &configList)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    ConfigList::const_iterator configIter;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    unsigned int j, k, l;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    ec_ioctl_config_pdo_t pdo;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    ec_ioctl_config_pdo_entry_t entry;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    ec_ioctl_config_sdo_t sdo;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    for (configIter = configList.begin();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            configIter != configList.end();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
            configIter++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        cout << "Alias: "
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
            << dec << configIter->alias << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
            << "Position: " << configIter->position << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
            << "Vendor Id: 0x"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
            << hex << setfill('0')
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            << setw(8) << configIter->vendor_id << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
            << "Product code: 0x"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
            << setw(8) << configIter->product_code << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
            << "Attached: " << (configIter->attached ? "yes" : "no") << endl
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
            << "Operational: " << (configIter->operational ? "yes" : "no") << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
            if (configIter->syncs[j].pdo_count) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
                cout << "SM" << dec << j << " ("
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
                    << (configIter->syncs[j].dir == EC_DIR_INPUT
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
                            ? "Input" : "Output") << ")" << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
                for (k = 0; k < configIter->syncs[j].pdo_count; k++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
                    masterDev.getConfigPdo(&pdo, configIter->config_index, j, k);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
                    cout << "  Pdo 0x" << hex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
                        << setw(4) << pdo.index
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
                        << " \"" << pdo.name << "\"" << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
                    for (l = 0; l < pdo.entry_count; l++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
                        masterDev.getConfigPdoEntry(&entry,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
                                configIter->config_index, j, k, l);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
                        cout << "    Pdo entry 0x" << hex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
                            << setw(4) << entry.index << ":"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                            << setw(2) << (unsigned int) entry.subindex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
                            << ", " << dec << (unsigned int) entry.bit_length
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
                            << " bit, \"" << entry.name << "\"" << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
                    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
                }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
            }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        cout << "Sdo configuration:" << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
        if (configIter->sdo_count) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
            for (j = 0; j < configIter->sdo_count; j++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
                masterDev.getConfigSdo(&sdo, configIter->config_index, j);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
                cout << "  0x"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
                    << hex << setfill('0')
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
                    << setw(4) << sdo.index << ":"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
                    << setw(2) << (unsigned int) sdo.subindex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
                    << ", " << dec << sdo.size << " byte: " << hex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                switch (sdo.size) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
                    case 1:
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
                        cout << "0x" << setw(2)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
                            << (unsigned int) *(uint8_t *) &sdo.data;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
                        break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
                    case 2:
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
                        cout << "0x" << setw(4)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                            << le16tocpu(*(uint16_t *) &sdo.data);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
                        break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
                    case 4:
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
                        cout << "0x" << setw(8)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
                            << le32tocpu(*(uint32_t *) &sdo.data);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
                        break;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
                    default:
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
                        cout << "???";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
                }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
                cout << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
            }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        } else {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
            cout << "  None." << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
        }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        cout << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
/*****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
/** Lists the bus configuration.
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
 */
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
void listConfigs(const ConfigList &configList)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    ConfigList::const_iterator configIter;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    stringstream str;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    ConfigInfo info;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    typedef list<ConfigInfo> ConfigInfoList;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
    ConfigInfoList list;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    ConfigInfoList::const_iterator iter;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    unsigned int maxAliasWidth = 0, maxPosWidth = 0,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
                 maxAttWidth = 0, maxOpWidth = 0;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    for (configIter = configList.begin();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
            configIter != configList.end();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
            configIter++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        str << dec << configIter->alias;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
        info.alias = str.str();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
        str.clear();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
        str.str("");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        str << configIter->position;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        info.pos = str.str();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        str.clear();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        str.str("");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        str << hex << setfill('0')
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
            << "0x" << setw(8) << configIter->vendor_id
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
            << "/0x" << setw(8) << configIter->product_code;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
        info.ident = str.str();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        str.clear();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        str.str("");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
        str << (configIter->attached ? "attached" : "-");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
        info.att = str.str();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        str.clear();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
        str.str("");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
        str << (configIter->operational ? "operational" : "-");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
        info.op = str.str();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        str.clear();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        str.str("");
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        list.push_back(info);
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
        if (info.alias.length() > maxAliasWidth)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
            maxAliasWidth = info.alias.length();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
        if (info.pos.length() > maxPosWidth)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
            maxPosWidth = info.pos.length();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
        if (info.att.length() > maxAttWidth)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
            maxAttWidth = info.att.length();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
        if (info.op.length() > maxOpWidth)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
            maxOpWidth = info.op.length();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    for (iter = list.begin(); iter != list.end(); iter++) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        cout << setfill(' ') << right
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
            << setw(maxAliasWidth) << iter->alias
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
            << ":" << left
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
            << setw(maxPosWidth) << iter->pos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
            << "  "
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
            << iter->ident
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
            << "  "
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
            << setw(maxAttWidth) << iter->att << "  "
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
            << setw(maxOpWidth) << iter->op << "  "
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
            << endl;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
/*****************************************************************************/