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@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@1142: string CommandDomains::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1144: str << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Without the --verbose option, the domains are displayed" << endl fp@1142: << "one-per-line. Example:" << endl fp@1142: << endl fp@1142: << "Domain0: LogBaseAddr 0x00000000, Size 6, WorkingCounter 0/1" fp@1142: << endl << endl fp@1142: << "The domain's base address for the logical datagram" << endl fp@1142: << "(LRD/LWR/LRW) is displayed followed by the domain's" << endl fp@1142: << "process data size in byte. The last values are the current" << endl fp@1142: << "datagram working counter sum and the expected working" << endl fp@1327: << "counter sum. If the values are equal, all PDOs were" << endl fp@1167: << "exchanged during the last cycle." << endl fp@1167: << endl fp@1142: << "If the --verbose option is given, the participating slave" << endl fp@1142: << "configurations/FMMUs and the current process data are" << endl fp@1142: << "additionally displayed:" << endl fp@1142: << endl fp@1142: << "Domain1: LogBaseAddr 0x00000006, Size 6, WorkingCounter 0/1" fp@1142: << endl fp@1142: << " SlaveConfig 1001:0, SM3 ( Input), LogAddr 0x00000006, Size 6" fp@1142: << endl fp@1144: << " 0x00 0x00 0x00 0x00 0x00 0x00" << endl fp@1142: << endl fp@1142: << "The process data are displayed as hexadecimal bytes." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1167: << " --domain -d Positive numerical domain index." << endl fp@1167: << " If ommitted, all domains are" << endl fp@1167: << " displayed." << endl fp@1142: << endl fp@1142: << " --verbose -v Show FMMUs and process data" << endl fp@1144: << " in addition." << endl fp@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandDomains::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1166: DomainList domains; fp@1166: DomainList::const_iterator di; fp@1166: 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@1142: m.open(MasterDevice::Read); fp@1166: domains = selectedDomains(m); fp@1142: fp@1166: for (di = domains.begin(); di != domains.end(); di++) { fp@1166: showDomain(m, *di); fp@1166: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1166: void CommandDomains::showDomain( fp@1166: MasterDevice &m, fp@1166: const ec_ioctl_domain_t &domain fp@1166: ) 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@1142: fp@1166: cout << "Domain" << dec << domain.index << ":" fp@1142: << " LogBaseAddr 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(8) << domain.logical_base_address fp@1142: << ", Size " << dec << setfill(' ') fp@1142: << setw(3) << domain.data_size fp@1142: << ", WorkingCounter " fp@1142: << domain.working_counter << "/" fp@1142: << domain.expected_working_counter << 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@1142: cout << " 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@1142: cout << " " << hex << setfill('0'); fp@1142: for (j = 0; j < fmmu.data_size; j++) { fp@1142: if (j && !(j % BreakAfterBytes)) fp@1142: cout << endl << " "; fp@1144: cout << "0x" << 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: /*****************************************************************************/