Merged CRC command. stable-1.5
authorFlorian Pose <fp@gh.de>
Fri, 03 Mar 2017 13:55:01 +0100
branchstable-1.5
changeset 2668 dd32f74ee76e
parent 2665 2de506e60b21 (current diff)
parent 2667 0d7936701e60 (diff)
child 2671 5d7a83195c80
Merged CRC command.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandCrc.cpp	Fri Mar 03 13:55:01 2017 +0100
@@ -0,0 +1,164 @@
+/*****************************************************************************
+ *
+ *  Copyright (C) 2006-2017  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+using namespace std;
+
+#include "CommandCrc.h"
+#include "MasterDevice.h"
+
+/*****************************************************************************/
+
+CommandCrc::CommandCrc():
+    Command("crc", "CRC error register diagnosis.")
+{
+}
+
+/*****************************************************************************/
+
+string CommandCrc::helpString(const string &binaryBaseName) const
+{
+    stringstream str;
+
+    str
+        << binaryBaseName << " " << getName() << endl
+        << binaryBaseName << " " << getName() << " reset" << endl
+        << endl
+        << getBriefDescription() << endl
+        << endl
+        << "CRC - CRC Error Counter                0x300, 0x302, 0x304, 0x306"
+        << endl
+        << "PHY - Physical Interface Error Counter 0x301, 0x303, 0x305, 0x307"
+        << endl
+        << "FWD - Forwarded RX Error Counter       0x308, 0x309, 0x30a, 0x30b"
+        << endl
+        << "LNK - Lost Link Counter                0x310, 0x311, 0x312, 0x313"
+        << endl
+        << endl;
+
+    return str.str();
+}
+
+/****************************************************************************/
+
+#define NUM_PORTS (4)
+#define REG_SIZE  (20)
+
+void CommandCrc::execute(const StringVector &args)
+{
+    bool reset = false;
+
+    if (args.size() > 1) {
+        stringstream err;
+        err << "'" << getName() << "' takes either no or 'reset' argument!";
+        throwInvalidUsageException(err);
+    }
+
+    if (args.size() == 1) {
+        string arg = args[0];
+        transform(arg.begin(), arg.end(),
+                arg.begin(), (int (*) (int)) std::tolower);
+        if (arg != "reset") {
+            stringstream err;
+            err << "'" << getName() << "' takes either no or 'reset' argument!";
+            throwInvalidUsageException(err);
+        }
+
+        reset = true;
+    }
+
+    MasterDevice m(getSingleMasterIndex());
+    m.open(reset ? MasterDevice::ReadWrite : MasterDevice::Read);
+
+    ec_ioctl_master_t master;
+    m.getMaster(&master);
+
+    uint8_t data[REG_SIZE];
+    ec_ioctl_slave_reg_t io;
+    io.emergency = 0;
+    io.address = 0x0300;
+    io.size = REG_SIZE;
+    io.data = data;
+
+    if (reset) {
+        for (int j = 0; j < REG_SIZE; j++) {
+            data[j] = 0x00;
+        }
+
+        for (unsigned int i = 0; i < master.slave_count; i++) {
+
+            io.slave_position = i;
+            try {
+                m.writeReg(&io);
+            } catch (MasterDeviceException &e) {
+                throw e;
+            }
+        }
+        return;
+    }
+
+    cout << "   |";
+    for (unsigned int port = 0; port < NUM_PORTS; port++) {
+        cout << "Port " << port << "         |";
+    }
+    cout << endl;
+
+    cout << "   |";
+    for (unsigned int port = 0; port < NUM_PORTS; port++) {
+        cout << "CRC PHY FWD LNK|";
+    }
+    cout << endl;
+
+    for (unsigned int i = 0; i < master.slave_count; i++) {
+
+        io.slave_position = i;
+        try {
+            m.readReg(&io);
+        } catch (MasterDeviceException &e) {
+            throw e;
+        }
+
+        cout << setw(3) << i << "|";
+        for (int port = 0; port < 4; port++) {
+            cout << setw(3) << (unsigned int) io.data[ 0 + port * 2]; // CRC
+            cout << setw(4) << (unsigned int) io.data[ 1 + port * 2]; // PHY
+            cout << setw(4) << (unsigned int) io.data[ 8 + port]; // FWD
+            cout << setw(4) << (unsigned int) io.data[16 + port]; // LNK
+            cout << "|";
+        }
+
+        ec_ioctl_slave_t slave;
+        m.getSlave(&slave, i);
+        std::string slaveName(slave.name);
+        slaveName = slaveName.substr(0, 11);
+        cout << slaveName << endl;
+    }
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandCrc.h	Fri Mar 03 13:55:01 2017 +0100
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ *
+ *  Copyright (C) 2006-2017  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#ifndef __COMMANDCRC_H__
+#define __COMMANDCRC_H__
+
+#include "Command.h"
+#include "DataTypeHandler.h"
+
+/****************************************************************************/
+
+class CommandCrc:
+    public Command,
+    public DataTypeHandler
+{
+    public:
+        CommandCrc();
+
+        string helpString(const string &) const;
+        void execute(const StringVector &);
+};
+
+/****************************************************************************/
+
+#endif
--- a/tool/Makefile.am	Fri Jan 13 16:47:27 2017 +0100
+++ b/tool/Makefile.am	Fri Mar 03 13:55:01 2017 +0100
@@ -39,6 +39,7 @@
 	../master/soe_errors.c \
 	Command.cpp \
 	CommandAlias.cpp \
+	CommandCrc.cpp \
 	CommandCStruct.cpp \
 	CommandConfig.cpp \
 	CommandData.cpp \
@@ -81,6 +82,7 @@
 noinst_HEADERS = \
 	Command.h \
 	CommandAlias.h \
+	CommandCrc.h \
 	CommandCStruct.h \
 	CommandConfig.h \
 	CommandData.h \
--- a/tool/main.cpp	Fri Jan 13 16:47:27 2017 +0100
+++ b/tool/main.cpp	Fri Mar 03 13:55:01 2017 +0100
@@ -37,6 +37,7 @@
 
 #include "CommandAlias.h"
 #include "CommandConfig.h"
+#include "CommandCrc.h"
 #include "CommandCStruct.h"
 #include "CommandData.h"
 #include "CommandDebug.h"
@@ -277,6 +278,7 @@
 
     commandList.push_back(new CommandAlias());
     commandList.push_back(new CommandConfig());
+    commandList.push_back(new CommandCrc());
     commandList.push_back(new CommandCStruct());
     commandList.push_back(new CommandData());
     commandList.push_back(new CommandDebug());