tool/CommandCrc.cpp
branchstable-1.5
changeset 2666 d9e14a0ddbd6
child 2667 0d7936701e60
equal deleted inserted replaced
2658:7690a5df7539 2666:d9e14a0ddbd6
       
     1 /*****************************************************************************
       
     2  *
       
     3  *  Copyright (C) 2006-2017  Florian Pose, Ingenieurgemeinschaft IgH
       
     4  *
       
     5  *  This file is part of the IgH EtherCAT Master.
       
     6  *
       
     7  *  The IgH EtherCAT Master is free software; you can redistribute it and/or
       
     8  *  modify it under the terms of the GNU General Public License version 2, as
       
     9  *  published by the Free Software Foundation.
       
    10  *
       
    11  *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
       
    12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       
    14  *  Public License for more details.
       
    15  *
       
    16  *  You should have received a copy of the GNU General Public License along
       
    17  *  with the IgH EtherCAT Master; if not, write to the Free Software
       
    18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    19  *
       
    20  *  ---
       
    21  *
       
    22  *  The license mentioned above concerns the source code only. Using the
       
    23  *  EtherCAT technology and brand is only permitted in compliance with the
       
    24  *  industrial property and similar rights of Beckhoff Automation GmbH.
       
    25  *
       
    26  ****************************************************************************/
       
    27 
       
    28 #include <iostream>
       
    29 #include <iomanip>
       
    30 using namespace std;
       
    31 
       
    32 #include "CommandCrc.h"
       
    33 #include "MasterDevice.h"
       
    34 
       
    35 /*****************************************************************************/
       
    36 
       
    37 CommandCrc::CommandCrc():
       
    38     Command("crc", "CRC error register diagnosis.")
       
    39 {
       
    40 }
       
    41 
       
    42 /*****************************************************************************/
       
    43 
       
    44 string CommandCrc::helpString(const string &binaryBaseName) const
       
    45 {
       
    46     stringstream str;
       
    47 
       
    48     str << binaryBaseName << " " << getName()
       
    49         << " [OPTIONS]" << endl
       
    50         << endl
       
    51         << getBriefDescription() << endl
       
    52         << endl
       
    53         << "CRC - CRC Error Counter                0x300, 0x302, 0x304, 0x306"
       
    54         << endl
       
    55         << "PHY - Physical Interface Error Counter 0x301, 0x303, 0x305, 0x307"
       
    56         << endl
       
    57         << "FWD - Forwarded RX Error Counter       0x308, 0x309, 0x30a, 0x30b"
       
    58         << endl
       
    59         << "LNK - Lost Link Counter                0x310, 0x311, 0x312, 0x313"
       
    60         << endl
       
    61         << endl;
       
    62 
       
    63     return str.str();
       
    64 }
       
    65 
       
    66 /****************************************************************************/
       
    67 
       
    68 #define NUM_PORTS (4)
       
    69 
       
    70 void CommandCrc::execute(const StringVector &args)
       
    71 {
       
    72 
       
    73     MasterDevice m(getSingleMasterIndex());
       
    74     m.open(MasterDevice::Read);
       
    75 
       
    76     ec_ioctl_master_t master;
       
    77     m.getMaster(&master);
       
    78 
       
    79 
       
    80     cout << "   |";
       
    81     for (unsigned int port = 0; port < NUM_PORTS; port++) {
       
    82         cout << "Port " << port << "         |";
       
    83     }
       
    84     cout << endl;
       
    85 
       
    86     cout << "   |";
       
    87     for (unsigned int port = 0; port < NUM_PORTS; port++) {
       
    88         cout << "CRC PHY FWD LNK|";
       
    89     }
       
    90     cout << endl;
       
    91 
       
    92     ec_ioctl_slave_reg_t io;
       
    93     io.emergency = 0;
       
    94     io.address = 0x0300;
       
    95     io.size = 20;
       
    96     io.data = new uint8_t[20];
       
    97 
       
    98     for (unsigned int i = 0; i < master.slave_count; i++) {
       
    99 
       
   100         io.slave_position = i;
       
   101         try {
       
   102             m.readReg(&io);
       
   103         } catch (MasterDeviceException &e) {
       
   104             delete [] io.data;
       
   105             throw e;
       
   106         }
       
   107 
       
   108         cout << setw(3) << i << "|";
       
   109         for (int port = 0; port < 4; port++) {
       
   110             cout << setw(3) << (unsigned int) io.data[ 0 + port * 2]; // CRC
       
   111             cout << setw(4) << (unsigned int) io.data[ 1 + port * 2]; // PHY
       
   112             cout << setw(4) << (unsigned int) io.data[ 8 + port]; // FWD
       
   113             cout << setw(4) << (unsigned int) io.data[16 + port]; // LNK
       
   114             cout << "|";
       
   115         }
       
   116 
       
   117         ec_ioctl_slave_t slave;
       
   118         m.getSlave(&slave, i);
       
   119         std::string slaveName(slave.name);
       
   120         slaveName = slaveName.substr(0, 11);
       
   121         cout << slaveName << endl;
       
   122     }
       
   123 
       
   124     delete [] io.data;
       
   125 }
       
   126 
       
   127 /*****************************************************************************/