tool/CommandCrc.cpp
author Florian Pose <fp@igh.de>
Mon, 04 Sep 2017 17:12:59 +0200
branchstable-1.5
changeset 2681 9953c0d372ab
parent 2674 3be68a020748
permissions -rw-r--r--
Adapted vm_operations_struct for kernels >= 4.11
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  Copyright (C) 2006-2017  Florian Pose, Ingenieurgemeinschaft IgH
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  This file is part of the IgH EtherCAT Master.
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *  modify it under the terms of the GNU General Public License version 2, as
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  published by the Free Software Foundation.
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  Public License for more details.
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  You should have received a copy of the GNU General Public License along
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  with the IgH EtherCAT Master; if not, write to the Free Software
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  ---
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  The license mentioned above concerns the source code only. Using the
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  EtherCAT technology and brand is only permitted in compliance with the
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  industrial property and similar rights of Beckhoff Automation GmbH.
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 ****************************************************************************/
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#include <iostream>
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <iomanip>
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    30
#include <algorithm>
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
using namespace std;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include "CommandCrc.h"
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "MasterDevice.h"
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
/*****************************************************************************/
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
CommandCrc::CommandCrc():
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
    Command("crc", "CRC error register diagnosis.")
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
{
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
}
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/*****************************************************************************/
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
string CommandCrc::helpString(const string &binaryBaseName) const
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
{
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    stringstream str;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    49
    str
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    50
        << binaryBaseName << " " << getName() << endl
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    51
        << binaryBaseName << " " << getName() << " reset" << endl
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << endl
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << getBriefDescription() << endl
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << endl
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "CRC - CRC Error Counter                0x300, 0x302, 0x304, 0x306"
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << endl
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << "PHY - Physical Interface Error Counter 0x301, 0x303, 0x305, 0x307"
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << endl
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "FWD - Forwarded RX Error Counter       0x308, 0x309, 0x30a, 0x30b"
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        << endl
2674
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
    61
        << "NXT - Next slave" << endl
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        << endl;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    return str.str();
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
}
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
/****************************************************************************/
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    69
#define REG_SIZE  (20)
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
void CommandCrc::execute(const StringVector &args)
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
{
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    73
    bool reset = false;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    74
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    75
    if (args.size() > 1) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    76
        stringstream err;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    77
        err << "'" << getName() << "' takes either no or 'reset' argument!";
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    78
        throwInvalidUsageException(err);
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    79
    }
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    80
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    81
    if (args.size() == 1) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    82
        string arg = args[0];
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    83
        transform(arg.begin(), arg.end(),
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    84
                arg.begin(), (int (*) (int)) std::tolower);
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    85
        if (arg != "reset") {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    86
            stringstream err;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    87
            err << "'" << getName() << "' takes either no or 'reset' argument!";
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    88
            throwInvalidUsageException(err);
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    89
        }
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    90
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    91
        reset = true;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    92
    }
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    MasterDevice m(getSingleMasterIndex());
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
    95
    m.open(reset ? MasterDevice::ReadWrite : MasterDevice::Read);
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    ec_ioctl_master_t master;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    m.getMaster(&master);
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
2667
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   100
    uint8_t data[REG_SIZE];
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   101
    ec_ioctl_slave_reg_t io;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   102
    io.emergency = 0;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   103
    io.address = 0x0300;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   104
    io.size = REG_SIZE;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   105
    io.data = data;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   106
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   107
    if (reset) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   108
        for (int j = 0; j < REG_SIZE; j++) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   109
            data[j] = 0x00;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   110
        }
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   111
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   112
        for (unsigned int i = 0; i < master.slave_count; i++) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   113
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   114
            io.slave_position = i;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   115
            try {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   116
                m.writeReg(&io);
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   117
            } catch (MasterDeviceException &e) {
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   118
                throw e;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   119
            }
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   120
        }
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   121
        return;
0d7936701e60 crc reset command.
Florian Pose <fp@igh-essen.com>
parents: 2666
diff changeset
   122
    }
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    cout << "   |";
2672
b9cda70ec8b0 Using EC_MAX_PORTS.
Florian Pose <fp@igh-essen.com>
parents: 2667
diff changeset
   125
    for (unsigned int port = 0; port < EC_MAX_PORTS; port++) {
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        cout << "Port " << port << "         |";
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    }
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    cout << endl;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    cout << "   |";
2672
b9cda70ec8b0 Using EC_MAX_PORTS.
Florian Pose <fp@igh-essen.com>
parents: 2667
diff changeset
   131
    for (unsigned int port = 0; port < EC_MAX_PORTS; port++) {
2674
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   132
        cout << "CRC PHY FWD NXT|";
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    }
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    cout << endl;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    for (unsigned int i = 0; i < master.slave_count; i++) {
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
2674
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   138
        ec_ioctl_slave_t slave;
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   139
        m.getSlave(&slave, i);
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   140
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        io.slave_position = i;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        try {
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
            m.readReg(&io);
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        } catch (MasterDeviceException &e) {
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
            throw e;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
        }
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        cout << setw(3) << i << "|";
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        for (int port = 0; port < 4; port++) {
2674
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   150
            if (slave.ports[port].link.loop_closed) {
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   151
                cout << "               |";
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   152
                continue;
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   153
            }
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   154
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
            cout << setw(3) << (unsigned int) io.data[ 0 + port * 2]; // CRC
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
            cout << setw(4) << (unsigned int) io.data[ 1 + port * 2]; // PHY
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
            cout << setw(4) << (unsigned int) io.data[ 8 + port]; // FWD
2674
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   158
            if (slave.ports[port].next_slave == i - 1) {
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   159
                cout << "   ↑";
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   160
            }
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   161
            else if (slave.ports[port].next_slave == i + 1) {
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   162
                cout << "   ↓";
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   163
            }
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   164
            else if (slave.ports[port].next_slave != 0xffff) {
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   165
                cout << setw(4) << slave.ports[port].next_slave;
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   166
            }
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   167
            else {
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   168
                cout << "    ";
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   169
            }
3be68a020748 Clear unused ports; use arrows for next slaves.
Florian Pose <fp@igh-essen.com>
parents: 2672
diff changeset
   170
2666
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
            cout << "|";
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        }
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        std::string slaveName(slave.name);
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
        slaveName = slaveName.substr(0, 11);
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
        cout << slaveName << endl;
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    }
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
}
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
d9e14a0ddbd6 New tool command 'ethercat crc'.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
/*****************************************************************************/