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@1880: * vim: expandtab fp@1880: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandData.h" fp@1826: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandData::CommandData(): fp@1142: Command("data", "Output binary domain process data.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1968: string CommandData::helpString(const string &binaryBaseName) const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1968: str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl fp@1804: << endl fp@1804: << getBriefDescription() << endl fp@1144: << endl fp@1144: << "Data of multiple domains are concatenated." << endl fp@1804: << endl fp@1804: << "Command-specific options:" << endl fp@1804: << " --domain -d Positive numerical domain index." << endl fp@1804: << " If omitted, data of all domains" << endl fp@1804: << " are output." << 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 CommandData::execute(const StringVector &args) fp@1142: { fp@1880: MasterIndexList masterIndices; 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@1880: masterIndices = getMasterIndices(); fp@1827: MasterIndexList::const_iterator mi; fp@1869: for (mi = masterIndices.begin(); fp@1869: mi != masterIndices.end(); mi++) { fp@2453: ec_ioctl_master_t io; fp@1827: MasterDevice m(*mi); fp@1827: m.open(MasterDevice::Read); fp@2453: m.getMaster(&io); fp@2453: fp@2453: domains = selectedDomains(m, io); fp@1142: fp@1827: for (di = domains.begin(); di != domains.end(); di++) { fp@1827: outputDomainData(m, *di); fp@1827: } fp@1804: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1166: void CommandData::outputDomainData( fp@1804: MasterDevice &m, fp@1804: const ec_ioctl_domain_t &domain fp@1804: ) fp@1142: { fp@1142: ec_ioctl_domain_data_t data; fp@1142: unsigned char *processData; fp@1142: unsigned int i; fp@2421: fp@1142: if (!domain.data_size) 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 < data.data_size; i++) fp@1142: cout << processData[i]; fp@1142: cout.flush(); fp@1142: fp@1142: delete [] processData; fp@1142: } fp@1142: fp@1142: /****************************************************************************/