tool/CommandEoe.cpp
author Florian Pose <fp@igh-essen.com>
Tue, 01 Dec 2009 22:29:25 +0100
changeset 1573 74bf584564b8
parent 1524 e7bdab4d6189
child 1826 ec6223c3b7ec
permissions -rw-r--r--
Create tty.
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"
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
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
CommandEoe::CommandEoe():
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
    Command("eoe", "Display Ethernet over EtherCAT statictics.")
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
{
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
string CommandEoe::helpString() const
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    stringstream str;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    str << getName() << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << getBriefDescription() << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "The TxRate and RxRate are displayed in Byte/s." << endl
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << endl;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    return str.str();
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
}
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
void CommandEoe::execute(MasterDevice &m, const StringVector &args)
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    ec_ioctl_master_t master;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    unsigned int i;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    ec_ioctl_eoe_handler_t eoe;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    if (args.size()) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        stringstream err;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        err << "'" << getName() << "' takes no arguments!";
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
        throwInvalidUsageException(err);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    m.open(MasterDevice::Read);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    m.getMaster(&master);
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
    cout << "Interface  Slave  State  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        << "RxBytes  RxRate  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        << "TxBytes  TxRate  TxQueue"
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        << endl;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    for (i = 0; i < master.eoe_handler_count; i++) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
        stringstream queue;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        m.getEoeHandler(&eoe, i);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        queue << eoe.tx_queued_frames << "/" << eoe.tx_queue_size;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        cout 
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
            << setw(9) << eoe.name << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
            << setw(5) << dec << eoe.slave_position << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
            << setw(5) << (eoe.open ? "up" : "down") << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
            << setw(7) << eoe.rx_bytes << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
            << setw(6) << eoe.rx_rate << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
            << setw(7) << eoe.tx_bytes << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
            << setw(6) << eoe.tx_rate << "  "
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
            << setw(7) << queue.str()
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
            << endl;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
/*****************************************************************************/