tool/CommandEoe.cpp
author Florian Pose <fp@igh-essen.com>
Tue, 10 Jan 2012 10:11:20 +0100
changeset 2249 6dbd7594dd1d
parent 1968 4f682084c643
child 2421 bc2d4bf9cbe5
permissions -rw-r--r--
Copy missing slave_info data in kernel space.
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1524
e7bdab4d6189 Committed misteriously modified files...
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
     3
 *  $Id$
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <list>
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <string.h>
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
using namespace std;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "CommandEoe.h"
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    37
#include "MasterDevice.h"
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
CommandEoe::CommandEoe():
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
    Command("eoe", "Display Ethernet over EtherCAT statictics.")
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
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: 1869
diff changeset
    48
string CommandEoe::helpString(const string &binaryBaseName) const
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    stringstream str;
5ddc3a455059 ethercat eoe command.
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: 1869
diff changeset
    52
    str << binaryBaseName << " " << getName() << endl
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << getBriefDescription() << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << "The TxRate and RxRate are displayed in Byte/s." << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << endl;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    return str.str();
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
/****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    64
void CommandEoe::execute(const StringVector &args)
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
{
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
    66
	MasterIndexList masterIndices;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    ec_ioctl_master_t master;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    unsigned int i;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    ec_ioctl_eoe_handler_t eoe;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    70
    bool doIndent;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    71
    string indent;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    if (args.size()) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        stringstream err;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        err << "'" << getName() << "' takes no arguments!";
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        throwInvalidUsageException(err);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
    79
	masterIndices = getMasterIndices();
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
    80
    doIndent = masterIndices.size();
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    81
    indent = doIndent ? "  " : "";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    82
    MasterIndexList::const_iterator mi;
1869
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
    83
    for (mi = masterIndices.begin();
14f634f5b613 Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents: 1827
diff changeset
    84
            mi != masterIndices.end(); mi++) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    85
        MasterDevice m(*mi);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    86
        m.open(MasterDevice::Read);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    87
        m.getMaster(&master);
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
1827
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    89
        if (master.eoe_handler_count) {
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    90
            if (doIndent) {
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    91
                cout << "Master" << dec << *mi << endl;
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    92
            }
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    93
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    94
            cout << indent << "Interface  Slave  State  "
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    95
                << "RxBytes  RxRate  "
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    96
                << "TxBytes  TxRate  TxQueue"
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    97
                << endl;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    98
        }
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   100
        for (i = 0; i < master.eoe_handler_count; i++) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   101
            stringstream queue;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   103
            m.getEoeHandler(&eoe, i);
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   105
            queue << eoe.tx_queued_frames << "/" << eoe.tx_queue_size;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   106
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   107
            cout << indent
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   108
                << setw(9) << eoe.name << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   109
                << setw(5) << dec << eoe.slave_position << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   110
                << setw(5) << (eoe.open ? "up" : "down") << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   111
                << setw(7) << eoe.rx_bytes << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   112
                << setw(6) << eoe.rx_rate << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   113
                << setw(7) << eoe.tx_bytes << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   114
                << setw(6) << eoe.tx_rate << "  "
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   115
                << setw(7) << queue.str()
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   116
                << endl;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   117
        }
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
/*****************************************************************************/