fp@2666: /***************************************************************************** fp@2666: * fp@2666: * Copyright (C) 2006-2017 Florian Pose, Ingenieurgemeinschaft IgH fp@2666: * fp@2666: * This file is part of the IgH EtherCAT Master. fp@2666: * fp@2666: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@2666: * modify it under the terms of the GNU General Public License version 2, as fp@2666: * published by the Free Software Foundation. fp@2666: * fp@2666: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@2666: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@2666: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@2666: * Public License for more details. fp@2666: * fp@2666: * You should have received a copy of the GNU General Public License along fp@2666: * with the IgH EtherCAT Master; if not, write to the Free Software fp@2666: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@2666: * fp@2666: * --- fp@2666: * fp@2666: * The license mentioned above concerns the source code only. Using the fp@2666: * EtherCAT technology and brand is only permitted in compliance with the fp@2666: * industrial property and similar rights of Beckhoff Automation GmbH. fp@2666: * fp@2666: ****************************************************************************/ fp@2666: fp@2666: #include fp@2666: #include fp@2667: #include fp@2666: using namespace std; fp@2666: fp@2666: #include "CommandCrc.h" fp@2666: #include "MasterDevice.h" fp@2666: fp@2666: /*****************************************************************************/ fp@2666: fp@2666: CommandCrc::CommandCrc(): fp@2666: Command("crc", "CRC error register diagnosis.") fp@2666: { fp@2666: } fp@2666: fp@2666: /*****************************************************************************/ fp@2666: fp@2666: string CommandCrc::helpString(const string &binaryBaseName) const fp@2666: { fp@2666: stringstream str; fp@2666: fp@2667: str fp@2667: << binaryBaseName << " " << getName() << endl fp@2667: << binaryBaseName << " " << getName() << " reset" << endl fp@2666: << endl fp@2666: << getBriefDescription() << endl fp@2666: << endl fp@2666: << "CRC - CRC Error Counter 0x300, 0x302, 0x304, 0x306" fp@2666: << endl fp@2666: << "PHY - Physical Interface Error Counter 0x301, 0x303, 0x305, 0x307" fp@2666: << endl fp@2666: << "FWD - Forwarded RX Error Counter 0x308, 0x309, 0x30a, 0x30b" fp@2666: << endl fp@2674: << "NXT - Next slave" << endl fp@2666: << endl; fp@2666: fp@2666: return str.str(); fp@2666: } fp@2666: fp@2666: /****************************************************************************/ fp@2666: fp@2667: #define REG_SIZE (20) fp@2666: fp@2666: void CommandCrc::execute(const StringVector &args) fp@2666: { fp@2667: bool reset = false; fp@2667: fp@2667: if (args.size() > 1) { fp@2667: stringstream err; fp@2667: err << "'" << getName() << "' takes either no or 'reset' argument!"; fp@2667: throwInvalidUsageException(err); fp@2667: } fp@2667: fp@2667: if (args.size() == 1) { fp@2667: string arg = args[0]; fp@2667: transform(arg.begin(), arg.end(), fp@2667: arg.begin(), (int (*) (int)) std::tolower); fp@2667: if (arg != "reset") { fp@2667: stringstream err; fp@2667: err << "'" << getName() << "' takes either no or 'reset' argument!"; fp@2667: throwInvalidUsageException(err); fp@2667: } fp@2667: fp@2667: reset = true; fp@2667: } fp@2666: fp@2666: MasterDevice m(getSingleMasterIndex()); fp@2667: m.open(reset ? MasterDevice::ReadWrite : MasterDevice::Read); fp@2666: fp@2666: ec_ioctl_master_t master; fp@2666: m.getMaster(&master); fp@2666: fp@2667: uint8_t data[REG_SIZE]; fp@2667: ec_ioctl_slave_reg_t io; fp@2667: io.emergency = 0; fp@2667: io.address = 0x0300; fp@2667: io.size = REG_SIZE; fp@2667: io.data = data; fp@2667: fp@2667: if (reset) { fp@2667: for (int j = 0; j < REG_SIZE; j++) { fp@2667: data[j] = 0x00; fp@2667: } fp@2667: fp@2667: for (unsigned int i = 0; i < master.slave_count; i++) { fp@2667: fp@2667: io.slave_position = i; fp@2667: try { fp@2667: m.writeReg(&io); fp@2667: } catch (MasterDeviceException &e) { fp@2667: throw e; fp@2667: } fp@2667: } fp@2667: return; fp@2667: } fp@2666: fp@2666: cout << " |"; fp@2672: for (unsigned int port = 0; port < EC_MAX_PORTS; port++) { fp@2666: cout << "Port " << port << " |"; fp@2666: } fp@2666: cout << endl; fp@2666: fp@2666: cout << " |"; fp@2672: for (unsigned int port = 0; port < EC_MAX_PORTS; port++) { fp@2674: cout << "CRC PHY FWD NXT|"; fp@2666: } fp@2666: cout << endl; fp@2666: fp@2666: for (unsigned int i = 0; i < master.slave_count; i++) { fp@2666: fp@2674: ec_ioctl_slave_t slave; fp@2674: m.getSlave(&slave, i); fp@2674: fp@2666: io.slave_position = i; fp@2666: try { fp@2666: m.readReg(&io); fp@2666: } catch (MasterDeviceException &e) { fp@2666: throw e; fp@2666: } fp@2666: fp@2666: cout << setw(3) << i << "|"; fp@2666: for (int port = 0; port < 4; port++) { fp@2674: if (slave.ports[port].link.loop_closed) { fp@2674: cout << " |"; fp@2674: continue; fp@2674: } fp@2674: fp@2666: cout << setw(3) << (unsigned int) io.data[ 0 + port * 2]; // CRC fp@2666: cout << setw(4) << (unsigned int) io.data[ 1 + port * 2]; // PHY fp@2666: cout << setw(4) << (unsigned int) io.data[ 8 + port]; // FWD fp@2674: if (slave.ports[port].next_slave == i - 1) { fp@2674: cout << " ↑"; fp@2674: } fp@2674: else if (slave.ports[port].next_slave == i + 1) { fp@2674: cout << " ↓"; fp@2674: } fp@2674: else if (slave.ports[port].next_slave != 0xffff) { fp@2674: cout << setw(4) << slave.ports[port].next_slave; fp@2674: } fp@2674: else { fp@2674: cout << " "; fp@2674: } fp@2674: fp@2666: cout << "|"; fp@2666: } fp@2666: fp@2666: std::string slaveName(slave.name); fp@2666: slaveName = slaveName.substr(0, 11); fp@2666: cout << slaveName << endl; fp@2666: } fp@2666: } fp@2666: fp@2666: /*****************************************************************************/