tool/CommandMaster.cpp
author Martin Troxler <ch1010277@ch10lt194>
Mon, 14 Mar 2011 11:20:05 +0100
changeset 2042 8b358effa78b
parent 1968 4f682084c643
child 2156 71425e6120d8
child 2589 2b9c78543663
permissions -rw-r--r--
merged
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;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    73
    unsigned int i, 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;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
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) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    96
            case 0:  cout << "Waiting for device..."; break;
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
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   107
        for (i = 0; i < 2; i++) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   108
            cout << "    " << (i == 0 ? "Main" : "Backup") << ": ";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   109
            if (data.devices[i].address[0] == 0x00
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   110
                    && data.devices[i].address[1] == 0x00
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   111
                    && data.devices[i].address[2] == 0x00
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   112
                    && data.devices[i].address[3] == 0x00
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   113
                    && data.devices[i].address[4] == 0x00
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   114
                    && data.devices[i].address[5] == 0x00) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   115
                cout << "None.";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   116
            } else {
1858
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   117
                unsigned int lost =
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   118
                    data.devices[i].tx_count - data.devices[i].rx_count;
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   119
                if (lost == 1) {
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   120
                    // allow one frame travelling
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   121
                    lost = 0;
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   122
                }
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   123
                cout << hex << setfill('0')
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   124
                    << setw(2) << (unsigned int) data.devices[i].address[0]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   125
                    << ":"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   126
                    << setw(2) << (unsigned int) data.devices[i].address[1]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   127
                    << ":"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   128
                    << setw(2) << (unsigned int) data.devices[i].address[2]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   129
                    << ":"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   130
                    << setw(2) << (unsigned int) data.devices[i].address[3]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   131
                    << ":"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   132
                    << setw(2) << (unsigned int) data.devices[i].address[4]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   133
                    << ":"
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   134
                    << setw(2) << (unsigned int) data.devices[i].address[5]
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   135
                    << " ("
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   136
                    << (data.devices[i].attached ? "attached" : "waiting...")
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   137
                    << ")" << endl << dec
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   138
                    << "      Link: "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   139
                    << (data.devices[i].link_state ? "UP" : "DOWN") << endl
1858
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   140
                    << "      Tx frames:   "
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   141
                    << data.devices[i].tx_count << endl
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   142
                    << "      Rx frames:   "
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   143
                    << data.devices[i].rx_count << endl
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   144
                    << "      Lost frames: " << lost << endl
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   145
                    << "      Tx bytes:    "
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   146
                    << data.devices[i].tx_bytes << endl
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   147
                    << "      Tx errors:   "
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   148
                    << data.devices[i].tx_errors << endl
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   149
                    << "      Tx frame rate [1/s]: "
1853
e0b9c4611f0a Improved frame statistics output.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   150
                    << setfill(' ') << setprecision(0) << fixed;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   151
                for (j = 0; j < EC_RATE_COUNT; j++) {
1962
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   152
                    cout << setw(ColWidth)
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   153
                        << data.devices[i].tx_frame_rates[j] / 1000.0;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   154
                    if (j < EC_RATE_COUNT - 1) {
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   155
                        cout << " ";
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   156
                    }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   157
                }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   158
                cout << endl
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   159
                    << "      Tx rate [KByte/s]:   "
1858
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   160
                    << setprecision(1) << fixed;
4d4aa4c0fc1e Improved frame statistics output again.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
   161
                for (j = 0; j < EC_RATE_COUNT; j++) {
1962
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   162
                    cout << setw(ColWidth)
1956
f461dc0d145a Fixed frame statistics overflow (to be verified).
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   163
                        << data.devices[i].tx_byte_rates[j] / 1024.0;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   164
                    if (j < EC_RATE_COUNT - 1) {
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   165
                        cout << " ";
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   166
                    }
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   167
                }
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   168
                cout << endl
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   169
                    << "      Loss rate [1/s]:     "
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   170
                    << setprecision(0) << fixed;
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   171
                for (j = 0; j < EC_RATE_COUNT; j++) {
1962
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   172
                    cout << setw(ColWidth)
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   173
                        << data.devices[i].loss_rates[j] / 1000.0;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   174
                    if (j < EC_RATE_COUNT - 1) {
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   175
                        cout << " ";
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   176
                    }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   177
                }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   178
                cout << endl
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   179
                    << "      Frame loss [%]:      "
1853
e0b9c4611f0a Improved frame statistics output.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   180
                    << setprecision(1) << fixed;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   181
                for (j = 0; j < EC_RATE_COUNT; j++) {
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   182
                    double perc = 0.0;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   183
                    if (data.devices[i].tx_frame_rates[j]) {
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   184
                        perc = 100.0 * data.devices[i].loss_rates[j] /
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1853
diff changeset
   185
                            data.devices[i].tx_frame_rates[j];
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   186
                    }
1962
df9b00bda8dc Set master stats colum with to 6.
Florian Pose <fp@igh-essen.com>
parents: 1956
diff changeset
   187
                    cout << setw(ColWidth) << perc;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   188
                    if (j < EC_RATE_COUNT - 1) {
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   189
                        cout << " ";
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   190
                    }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   191
                }
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   192
                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
   193
            }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   194
            cout << endl;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   195
        }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   196
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   197
        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
   198
            << "    Reference clock: ";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   199
        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
   200
            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
   201
        } else {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   202
            cout << "None";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   203
        }
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   204
        cout << endl
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   205
            << "    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
   206
            << "                      ";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   207
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   208
        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
   209
        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
   210
                "%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
   211
        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
   212
            << setfill('0') << setw(9) << data.app_time % 1000000000 << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
/*****************************************************************************/