fp@1142: /***************************************************************************** fp@1142: * fp@1363: * $Id$ fp@1363: * fp@1363: * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH fp@1363: * fp@1363: * This file is part of the IgH EtherCAT Master. fp@1363: * fp@1363: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1363: * modify it under the terms of the GNU General Public License version 2, as fp@1363: * published by the Free Software Foundation. fp@1363: * fp@1363: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1363: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1363: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1363: * Public License for more details. fp@1363: * fp@1363: * You should have received a copy of the GNU General Public License along fp@1363: * with the IgH EtherCAT Master; if not, write to the Free Software fp@1363: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1363: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandDomains.h" fp@1826: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandDomains::CommandDomains(): fp@1142: Command("domains", "Show configured domains.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1968: string CommandDomains::helpString(const string &binaryBaseName) const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1968: str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1804: << getBriefDescription() << endl fp@1804: << endl fp@1804: << "Without the --verbose option, the domains are displayed" << endl fp@1142: << "one-per-line. Example:" << endl fp@1804: << endl fp@1804: << "Domain0: LogBaseAddr 0x00000000, Size 6, WorkingCounter 0/1" fp@1804: << endl << endl fp@1804: << "The domain's base address for the logical datagram" << endl fp@1804: << "(LRD/LWR/LRW) is displayed followed by the domain's" << endl fp@1804: << "process data size in byte. The last values are the current" << endl fp@1804: << "datagram working counter sum and the expected working" << endl fp@1804: << "counter sum. If the values are equal, all PDOs were" << endl fp@1167: << "exchanged during the last cycle." << endl fp@1167: << endl fp@1804: << "If the --verbose option is given, the participating slave" << endl fp@1804: << "configurations/FMMUs and the current process data are" << endl fp@1804: << "additionally displayed:" << endl fp@1804: << endl fp@1804: << "Domain1: LogBaseAddr 0x00000006, Size 6, WorkingCounter 0/1" fp@1804: << endl fp@1804: << " SlaveConfig 1001:0, SM3 ( Input), LogAddr 0x00000006, Size 6" fp@1804: << endl fp@1955: << " 00 00 00 00 00 00" << endl fp@1804: << endl fp@1804: << "The process data are displayed as hexadecimal bytes." << endl fp@1804: << endl fp@1804: << "Command-specific options:" << endl fp@1804: << " --domain -d Positive numerical domain index." << endl fp@1804: << " If ommitted, all domains are" << endl fp@1167: << " displayed." << endl fp@1804: << endl fp@1804: << " --verbose -v Show FMMUs and process data" << endl fp@1804: << " in addition." << endl fp@1804: << endl fp@1804: << numericInfo(); fp@1142: fp@1804: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1826: void CommandDomains::execute(const StringVector &args) fp@1142: { fp@1869: MasterIndexList masterIndices; fp@1869: bool doIndent; fp@1804: DomainList domains; fp@1804: DomainList::const_iterator di; fp@1804: fp@1373: if (args.size()) { fp@1373: stringstream err; fp@1373: err << "'" << getName() << "' takes no arguments!"; fp@1373: throwInvalidUsageException(err); fp@1373: } fp@1373: fp@1869: masterIndices = getMasterIndices(); fp@1869: doIndent = masterIndices.size() > 1; fp@1826: MasterIndexList::const_iterator mi; fp@1869: for (mi = masterIndices.begin(); fp@1869: mi != masterIndices.end(); mi++) { fp@1826: MasterDevice m(*mi); fp@1826: m.open(MasterDevice::Read); fp@1826: domains = selectedDomains(m); fp@1142: fp@1827: if (domains.size() && doIndent) { fp@1826: cout << "Master" << dec << *mi << endl; fp@1826: } fp@1826: fp@1826: for (di = domains.begin(); di != domains.end(); di++) { fp@1826: showDomain(m, *di, doIndent); fp@1826: } fp@1804: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1166: void CommandDomains::showDomain( fp@1804: MasterDevice &m, fp@1826: const ec_ioctl_domain_t &domain, fp@1826: bool doIndent fp@1804: ) fp@1142: { fp@1142: unsigned char *processData; fp@1142: ec_ioctl_domain_data_t data; fp@1142: unsigned int i, j; fp@1142: ec_ioctl_domain_fmmu_t fmmu; fp@1142: unsigned int dataOffset; fp@1826: string indent(doIndent ? " " : ""); fp@2369: unsigned int wc_sum = 0, dev_idx; fp@2369: fp@2369: for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) { fp@2369: wc_sum += domain.working_counter[dev_idx]; fp@2369: } fp@1804: fp@1826: cout << indent << "Domain" << dec << domain.index << ":" fp@1804: << " LogBaseAddr 0x" fp@1804: << hex << setfill('0') fp@1142: << setw(8) << domain.logical_base_address fp@1804: << ", Size " << dec << setfill(' ') fp@1142: << setw(3) << domain.data_size fp@1804: << ", WorkingCounter " fp@2369: << wc_sum << "/" fp@2369: << domain.expected_working_counter; fp@2369: if (EC_NUM_DEVICES == 2) { fp@2369: cout << " (" << domain.working_counter[EC_DEVICE_MAIN] fp@2369: << "+" << domain.working_counter[EC_DEVICE_BACKUP] fp@2369: << ")"; fp@2369: } fp@2369: cout << endl; fp@1142: fp@1142: if (!domain.data_size || getVerbosity() != Verbose) fp@1142: return; fp@1142: fp@1142: processData = new unsigned char[domain.data_size]; fp@1142: fp@1142: try { fp@1166: m.getData(&data, domain.index, domain.data_size, processData); fp@1142: } catch (MasterDeviceException &e) { fp@1142: delete [] processData; fp@1142: throw e; fp@1142: } fp@1142: fp@1142: for (i = 0; i < domain.fmmu_count; i++) { fp@1166: m.getFmmu(&fmmu, domain.index, i); fp@1142: fp@1826: cout << indent << " SlaveConfig " fp@1142: << dec << fmmu.slave_config_alias fp@1142: << ":" << fmmu.slave_config_position fp@1142: << ", SM" << (unsigned int) fmmu.sync_index << " (" fp@1142: << setfill(' ') << setw(6) fp@1142: << (fmmu.dir == EC_DIR_INPUT ? "Input" : "Output") fp@1142: << "), LogAddr 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(8) << fmmu.logical_address fp@1142: << ", Size " << dec << fmmu.data_size << endl; fp@1142: fp@1142: dataOffset = fmmu.logical_address - domain.logical_base_address; fp@1142: if (dataOffset + fmmu.data_size > domain.data_size) { fp@1142: stringstream err; fp@1142: delete [] processData; fp@1142: err << "Fmmu information corrupted!"; fp@1142: throwCommandException(err); fp@1142: } fp@1142: fp@1826: cout << indent << " " << hex << setfill('0'); fp@1142: for (j = 0; j < fmmu.data_size; j++) { fp@1142: if (j && !(j % BreakAfterBytes)) fp@1826: cout << endl << indent << " "; fp@1955: cout << setw(2) fp@1142: << (unsigned int) *(processData + dataOffset + j) << " "; fp@1142: } fp@1142: cout << endl; fp@1142: } fp@1142: fp@1142: delete [] processData; fp@1142: } fp@1142: fp@1142: /*****************************************************************************/