# HG changeset patch # User Florian Pose # Date 1488544397 -3600 # Node ID 878a657d920a6787dc52f122883f20aca4ae361c # Parent b101637f503cd93136c45728758db136e2f18917 New tool command 'ethercat crc'. diff -r b101637f503c -r 878a657d920a tool/CommandCrc.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool/CommandCrc.cpp Fri Mar 03 13:33:17 2017 +0100 @@ -0,0 +1,127 @@ +/***************************************************************************** + * + * 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 +#include +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() + << " [OPTIONS]" << 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) + +void CommandCrc::execute(const StringVector &args) +{ + + MasterDevice m(getSingleMasterIndex()); + m.open(MasterDevice::Read); + + ec_ioctl_master_t master; + m.getMaster(&master); + + + 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; + + ec_ioctl_slave_reg_t io; + io.emergency = 0; + io.address = 0x0300; + io.size = 20; + io.data = new uint8_t[20]; + + for (unsigned int i = 0; i < master.slave_count; i++) { + + io.slave_position = i; + try { + m.readReg(&io); + } catch (MasterDeviceException &e) { + delete [] io.data; + 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; + } + + delete [] io.data; +} + +/*****************************************************************************/ diff -r b101637f503c -r 878a657d920a tool/CommandCrc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool/CommandCrc.h Fri Mar 03 13:33:17 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 diff -r b101637f503c -r 878a657d920a tool/Makefile.am --- a/tool/Makefile.am Fri Sep 16 12:35:09 2016 +0200 +++ b/tool/Makefile.am Fri Mar 03 13:33:17 2017 +0100 @@ -39,6 +39,7 @@ ../master/soe_errors.c \ Command.cpp \ CommandAlias.cpp \ + CommandCrc.cpp \ CommandCStruct.cpp \ CommandConfig.cpp \ CommandData.cpp \ @@ -82,6 +83,7 @@ noinst_HEADERS = \ Command.h \ CommandAlias.h \ + CommandCrc.h \ CommandCStruct.h \ CommandConfig.h \ CommandData.h \ diff -r b101637f503c -r 878a657d920a tool/main.cpp --- a/tool/main.cpp Fri Sep 16 12:35:09 2016 +0200 +++ b/tool/main.cpp Fri Mar 03 13:33:17 2017 +0100 @@ -37,6 +37,7 @@ #include "CommandAlias.h" #include "CommandConfig.h" +#include "CommandCrc.h" #include "CommandCStruct.h" #include "CommandData.h" #include "CommandDebug.h" @@ -278,6 +279,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());