tool/CommandEoe.cpp
author Florian Pose <fp@igh-essen.com>
Fri, 05 Mar 2010 13:44:57 +0100
changeset 1836 52036efdf1e3
parent 1827 489be2180f71
child 1869 14f634f5b613
permissions -rw-r--r--
TODO.
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
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
string CommandEoe::helpString() const
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
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    str << getName() << endl
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
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    ec_ioctl_master_t master;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    unsigned int i;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    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
    69
    bool doIndent;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    70
    string indent;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    if (args.size()) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
        stringstream err;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        err << "'" << getName() << "' takes no arguments!";
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        throwInvalidUsageException(err);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    78
    doIndent = getMasterIndices().size();
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    79
    indent = doIndent ? "  " : "";
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    80
    MasterIndexList::const_iterator mi;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    81
    for (mi = getMasterIndices().begin();
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    82
            mi != getMasterIndices().end(); mi++) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    83
        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
    84
        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
    85
        m.getMaster(&master);
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
1827
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    87
        if (master.eoe_handler_count) {
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    88
            if (doIndent) {
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    89
                cout << "Master" << dec << *mi << endl;
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    90
            }
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    91
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    92
            cout << indent << "Interface  Slave  State  "
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    93
                << "RxBytes  RxRate  "
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    94
                << "TxBytes  TxRate  TxQueue"
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
    95
                << endl;
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    96
        }
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    98
        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
    99
            stringstream queue;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   101
            m.getEoeHandler(&eoe, i);
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
            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
   104
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   105
            cout << indent
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   106
                << 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
   107
                << 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
   108
                << 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
   109
                << 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
   110
                << 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
   111
                << 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
   112
                << 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
   113
                << 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
   114
                << endl;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
   115
        }
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
}
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
/*****************************************************************************/