tool/CommandEoe.cpp
changeset 1826 ec6223c3b7ec
parent 1524 e7bdab4d6189
child 1827 489be2180f71
equal deleted inserted replaced
1825:65781b048a47 1826:ec6223c3b7ec
    32 #include <list>
    32 #include <list>
    33 #include <string.h>
    33 #include <string.h>
    34 using namespace std;
    34 using namespace std;
    35 
    35 
    36 #include "CommandEoe.h"
    36 #include "CommandEoe.h"
       
    37 #include "MasterDevice.h"
    37 
    38 
    38 /*****************************************************************************/
    39 /*****************************************************************************/
    39 
    40 
    40 CommandEoe::CommandEoe():
    41 CommandEoe::CommandEoe():
    41     Command("eoe", "Display Ethernet over EtherCAT statictics.")
    42     Command("eoe", "Display Ethernet over EtherCAT statictics.")
    58     return str.str();
    59     return str.str();
    59 }
    60 }
    60 
    61 
    61 /****************************************************************************/
    62 /****************************************************************************/
    62 
    63 
    63 void CommandEoe::execute(MasterDevice &m, const StringVector &args)
    64 void CommandEoe::execute(const StringVector &args)
    64 {
    65 {
    65     ec_ioctl_master_t master;
    66     ec_ioctl_master_t master;
    66     unsigned int i;
    67     unsigned int i;
    67     ec_ioctl_eoe_handler_t eoe;
    68     ec_ioctl_eoe_handler_t eoe;
       
    69     bool doIndent;
       
    70     string indent;
    68     
    71     
    69     if (args.size()) {
    72     if (args.size()) {
    70         stringstream err;
    73         stringstream err;
    71         err << "'" << getName() << "' takes no arguments!";
    74         err << "'" << getName() << "' takes no arguments!";
    72         throwInvalidUsageException(err);
    75         throwInvalidUsageException(err);
    73     }
    76     }
    74 
    77 
    75     m.open(MasterDevice::Read);
    78     doIndent = getMasterIndices().size();
    76     m.getMaster(&master);
    79     indent = doIndent ? "  " : "";
       
    80     MasterIndexList::const_iterator mi;
       
    81     for (mi = getMasterIndices().begin();
       
    82             mi != getMasterIndices().end(); mi++) {
       
    83         MasterDevice m(*mi);
       
    84         m.open(MasterDevice::Read);
       
    85         m.getMaster(&master);
    77 
    86 
    78     cout << "Interface  Slave  State  "
    87         if (doIndent) {
    79         << "RxBytes  RxRate  "
    88             cout << "Master" << dec << *mi << endl;
    80         << "TxBytes  TxRate  TxQueue"
    89         }
    81         << endl;
       
    82 
    90 
    83     for (i = 0; i < master.eoe_handler_count; i++) {
    91         cout << indent << "Interface  Slave  State  "
    84         stringstream queue;
    92             << "RxBytes  RxRate  "
       
    93             << "TxBytes  TxRate  TxQueue"
       
    94             << endl;
    85 
    95 
    86         m.getEoeHandler(&eoe, i);
    96         for (i = 0; i < master.eoe_handler_count; i++) {
       
    97             stringstream queue;
    87 
    98 
    88         queue << eoe.tx_queued_frames << "/" << eoe.tx_queue_size;
    99             m.getEoeHandler(&eoe, i);
    89 
   100 
    90         cout 
   101             queue << eoe.tx_queued_frames << "/" << eoe.tx_queue_size;
    91             << setw(9) << eoe.name << "  "
   102 
    92             << setw(5) << dec << eoe.slave_position << "  "
   103             cout << indent
    93             << setw(5) << (eoe.open ? "up" : "down") << "  "
   104                 << setw(9) << eoe.name << "  "
    94             << setw(7) << eoe.rx_bytes << "  "
   105                 << setw(5) << dec << eoe.slave_position << "  "
    95             << setw(6) << eoe.rx_rate << "  "
   106                 << setw(5) << (eoe.open ? "up" : "down") << "  "
    96             << setw(7) << eoe.tx_bytes << "  "
   107                 << setw(7) << eoe.rx_bytes << "  "
    97             << setw(6) << eoe.tx_rate << "  "
   108                 << setw(6) << eoe.rx_rate << "  "
    98             << setw(7) << queue.str()
   109                 << setw(7) << eoe.tx_bytes << "  "
    99             << endl;
   110                 << setw(6) << eoe.tx_rate << "  "
       
   111                 << setw(7) << queue.str()
       
   112                 << endl;
       
   113         }
   100     }
   114     }
   101 }
   115 }
   102 
   116 
   103 /*****************************************************************************/
   117 /*****************************************************************************/