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 "CommandMaster.h" fp@1142: fp@1415: #define MAX_TIME_STR_SIZE 50 fp@1415: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandMaster::CommandMaster(): fp@1143: Command("master", "Show master and Ethernet device information.") fp@1142: { fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: string CommandMaster::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1142: str << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --master -m Index of the master to use. Default: 0." fp@1142: << endl << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandMaster::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1142: ec_ioctl_master_t data; fp@1142: stringstream err; fp@1142: unsigned int i; fp@1415: time_t epoch; fp@1415: char time_str[MAX_TIME_STR_SIZE + 1]; fp@1415: size_t time_str_size; fp@1142: fp@1373: if (args.size()) { fp@1373: err << "'" << getName() << "' takes no arguments!"; fp@1373: throwInvalidUsageException(err); fp@1373: } fp@1373: fp@1142: m.open(MasterDevice::Read); fp@1142: m.getMaster(&data); fp@1142: fp@1142: cout fp@1166: << "Master" << m.getIndex() << endl fp@1142: << " Phase: "; fp@1142: fp@1142: switch (data.phase) { fp@1142: case 0: cout << "Waiting for device..."; break; fp@1142: case 1: cout << "Idle"; break; fp@1142: case 2: cout << "Operation"; break; fp@1142: default: cout << "???"; fp@1142: } fp@1142: fp@1142: cout << endl fp@1415: << " Slaves: " << data.slave_count << endl fp@1415: << " Ethernet devices:" << endl; fp@1142: fp@1142: for (i = 0; i < 2; i++) { fp@1415: cout << " " << (i == 0 ? "Main" : "Backup") << ": "; fp@1142: if (data.devices[i].address[0] == 0x00 fp@1142: && data.devices[i].address[1] == 0x00 fp@1142: && data.devices[i].address[2] == 0x00 fp@1142: && data.devices[i].address[3] == 0x00 fp@1142: && data.devices[i].address[4] == 0x00 fp@1142: && data.devices[i].address[5] == 0x00) { fp@1142: cout << "None."; fp@1142: } else { fp@1142: cout << hex << setfill('0') fp@1142: << setw(2) << (unsigned int) data.devices[i].address[0] << ":" fp@1142: << setw(2) << (unsigned int) data.devices[i].address[1] << ":" fp@1142: << setw(2) << (unsigned int) data.devices[i].address[2] << ":" fp@1142: << setw(2) << (unsigned int) data.devices[i].address[3] << ":" fp@1142: << setw(2) << (unsigned int) data.devices[i].address[4] << ":" fp@1142: << setw(2) << (unsigned int) data.devices[i].address[5] << " (" fp@1142: << (data.devices[i].attached ? "attached" : "waiting...") fp@1142: << ")" << endl << dec fp@1415: << " Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl fp@1415: << " Tx count: " << data.devices[i].tx_count << endl fp@1415: << " Rx count: " << data.devices[i].rx_count; fp@1142: } fp@1142: cout << endl; fp@1142: } fp@1415: fp@1415: cout << " Distributed clocks:" << endl fp@1415: << " Reference clock: "; fp@1415: if (data.ref_clock != 0xffff) { fp@1415: cout << "Slave " << dec << data.ref_clock; fp@1415: } else { fp@1415: cout << "None"; fp@1415: } fp@1415: cout << endl fp@1415: << " Application time: " << data.app_time << endl fp@1415: << " "; fp@1415: fp@1415: epoch = data.app_time / 1000000000 + 946684800ULL; fp@1415: time_str_size = strftime(time_str, MAX_TIME_STR_SIZE, fp@1415: "%Y-%m-%d %H:%M:%S", gmtime(&epoch)); fp@1415: cout << string(time_str, time_str_size) << "." fp@1415: << setfill('0') << setw(9) << data.app_time % 1000000000 << endl; fp@1142: } fp@1142: fp@1142: /*****************************************************************************/