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