tool/CommandMaster.cpp
author Philipp Weyer <pw@igh-essen.com>
Fri, 18 Aug 2017 12:30:16 +0200
changeset 2679 33b922ec1871
parent 2589 2b9c78543663
permissions -rw-r--r--
Fixed lib include paths
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: 1166
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
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: 1166
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
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: 1166
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: 1166
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
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: 1166
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: 1166
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: 1166
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
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: 1166
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: 1166
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: 1166
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1166
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: 1166
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: 1166
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
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
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
#include <iostream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
using namespace std;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "CommandMaster.h"
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    35
#include "MasterDevice.h"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
    37
#define MAX_TIME_STR_SIZE 50
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
    38
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
CommandMaster::CommandMaster():
1143
09ee878d7214 Fixed duplicate alias command.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    42
    Command("master", "Show master and Ethernet device information.")
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1962
diff changeset
    48
string CommandMaster::helpString(const string &binaryBaseName) const
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1962
diff changeset
    52
    str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    53
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    54
        << getBriefDescription() << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    55
        << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    56
        << "Command-specific options:" << endl
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    57
        << "  --master -m <indices>  Master indices. A comma-separated" << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    58
        << "                         list with ranges is supported." << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    59
        << "                         Example: 1,4,5,7-9. Default: - (all)."
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    60
        << endl << endl
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    61
        << numericInfo();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
    63
    return str.str();
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
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
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    68
void CommandMaster::execute(const StringVector &args)
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
{
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1858
diff changeset
    70
	MasterIndexList masterIndices;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    ec_ioctl_master_t data;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    stringstream err;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
    73
    unsigned int dev_idx, j;
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
    74
    time_t epoch;
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
    75
    char time_str[MAX_TIME_STR_SIZE + 1];
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
    76
    size_t time_str_size;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
    77
1373
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    78
    if (args.size()) {
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    79
        err << "'" << getName() << "' takes no arguments!";
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    80
        throwInvalidUsageException(err);
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    81
    }
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    82
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1858
diff changeset
    83
	masterIndices = getMasterIndices();
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    84
    MasterIndexList::const_iterator mi;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1858
diff changeset
    85
    for (mi = masterIndices.begin();
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1858
diff changeset
    86
            mi != masterIndices.end(); mi++) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    87
        MasterDevice m(*mi);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    88
        m.open(MasterDevice::Read);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    89
        m.getMaster(&data);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    91
        cout
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    92
            << "Master" << m.getIndex() << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    93
            << "  Phase: ";
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    95
        switch (data.phase) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
    96
            case 0:  cout << "Waiting for device(s)..."; break;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    97
            case 1:  cout << "Idle"; break;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    98
            case 2:  cout << "Operation"; break;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    99
            default: cout << "???";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   100
        }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   101
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   102
        cout << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   103
            << "  Active: " << (data.active ? "yes" : "no") << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   104
            << "  Slaves: " << data.slave_count << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   105
            << "  Ethernet devices:" << endl;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   106
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   107
        for (dev_idx = EC_DEVICE_MAIN; dev_idx < data.num_devices;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   108
                dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   109
            cout << "    " << (dev_idx == EC_DEVICE_MAIN ? "Main" : "Backup")
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   110
                << ": ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   111
            cout << hex << setfill('0')
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   112
                << setw(2) << (unsigned int) data.devices[dev_idx].address[0]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   113
                << ":"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   114
                << setw(2) << (unsigned int) data.devices[dev_idx].address[1]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   115
                << ":"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   116
                << setw(2) << (unsigned int) data.devices[dev_idx].address[2]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   117
                << ":"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   118
                << setw(2) << (unsigned int) data.devices[dev_idx].address[3]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   119
                << ":"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   120
                << setw(2) << (unsigned int) data.devices[dev_idx].address[4]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   121
                << ":"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   122
                << setw(2) << (unsigned int) data.devices[dev_idx].address[5]
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   123
                << " ("
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   124
                << (data.devices[dev_idx].attached ?
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   125
                        "attached" : "waiting...")
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   126
                << ")" << endl << dec
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   127
                << "      Link: "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   128
                << (data.devices[dev_idx].link_state ? "UP" : "DOWN") << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   129
                << "      Tx frames:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   130
                << data.devices[dev_idx].tx_count << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   131
                << "      Tx bytes:    "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   132
                << data.devices[dev_idx].tx_bytes << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   133
                << "      Rx frames:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   134
                << data.devices[dev_idx].rx_count << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   135
                << "      Rx bytes:    "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   136
                << data.devices[dev_idx].rx_bytes << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   137
                << "      Tx errors:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   138
                << data.devices[dev_idx].tx_errors << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   139
                << "      Tx frame rate [1/s]: "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   140
                << setfill(' ') << setprecision(0) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   141
            for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   142
                cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   143
                    << data.devices[dev_idx].tx_frame_rates[j] / 1000.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   144
                if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   145
                    cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   146
                }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   147
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   148
            cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   149
                << "      Tx rate [KByte/s]:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   150
                << setprecision(1) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   151
            for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   152
                cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   153
                    << data.devices[dev_idx].tx_byte_rates[j] / 1024.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   154
                if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   155
                    cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   156
                }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   157
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   158
            cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   159
                << "      Rx frame rate [1/s]: "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   160
                << setfill(' ') << setprecision(0) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   161
            for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   162
                cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   163
                    << data.devices[dev_idx].rx_frame_rates[j] / 1000.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   164
                if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   165
                    cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   166
                }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   167
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   168
            cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   169
                << "      Rx rate [KByte/s]:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   170
                << setprecision(1) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   171
            for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   172
                cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   173
                    << data.devices[dev_idx].rx_byte_rates[j] / 1024.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   174
                if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   175
                    cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   176
                }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   177
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   178
            cout << setprecision(0) << endl;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   179
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   180
        unsigned int lost = data.tx_count - data.rx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   181
        if (lost == 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   182
            // allow one frame travelling
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   183
            lost = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   184
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   185
        cout << "    Common:" << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   186
            << "      Tx frames:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   187
            << data.tx_count << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   188
            << "      Tx bytes:    "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   189
            << data.tx_bytes << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   190
            << "      Rx frames:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   191
            << data.rx_count << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   192
            << "      Rx bytes:    "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   193
            << data.rx_bytes << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   194
            << "      Lost frames: " << lost << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   195
            << "      Tx frame rate [1/s]: "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   196
            << setfill(' ') << setprecision(0) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   197
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   198
            cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   199
                << data.tx_frame_rates[j] / 1000.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   200
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   201
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   202
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   203
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   204
        cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   205
            << "      Tx rate [KByte/s]:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   206
            << setprecision(1) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   207
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   208
            cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   209
                << data.tx_byte_rates[j] / 1024.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   210
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   211
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   212
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   213
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   214
        cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   215
            << "      Rx frame rate [1/s]: "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   216
            << setfill(' ') << setprecision(0) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   217
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   218
            cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   219
                << data.rx_frame_rates[j] / 1000.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   220
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   221
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   222
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   223
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   224
        cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   225
            << "      Rx rate [KByte/s]:   "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   226
            << setprecision(1) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   227
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   228
            cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   229
                << data.rx_byte_rates[j] / 1024.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   230
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   231
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   232
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   233
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   234
        cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   235
            << "      Loss rate [1/s]:     "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   236
            << setprecision(0) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   237
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   238
            cout << setw(ColWidth)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   239
                << data.loss_rates[j] / 1000.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   240
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   241
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   242
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   243
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   244
        cout << endl
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   245
            << "      Frame loss [%]:      "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   246
            << setprecision(1) << fixed;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   247
        for (j = 0; j < EC_RATE_COUNT; j++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   248
            double perc = 0.0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   249
            if (data.tx_frame_rates[j]) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   250
                perc = 100.0 * data.loss_rates[j] / data.tx_frame_rates[j];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   251
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   252
            cout << setw(ColWidth) << perc;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   253
            if (j < EC_RATE_COUNT - 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   254
                cout << " ";
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   255
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   256
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1968
diff changeset
   257
        cout << setprecision(0) << endl;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   258
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   259
        cout << "  Distributed clocks:" << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   260
            << "    Reference clock: ";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   261
        if (data.ref_clock != 0xffff) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   262
            cout << "Slave " << dec << data.ref_clock;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   263
        } else {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   264
            cout << "None";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   265
        }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   266
        cout << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   267
            << "    Application time: " << data.app_time << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   268
            << "                      ";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   269
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   270
        epoch = data.app_time / 1000000000 + 946684800ULL;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   271
        time_str_size = strftime(time_str, MAX_TIME_STR_SIZE,
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   272
                "%Y-%m-%d %H:%M:%S", gmtime(&epoch));
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   273
        cout << string(time_str, time_str_size) << "."
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   274
            << setfill('0') << setw(9) << data.app_time % 1000000000 << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
/*****************************************************************************/