tool/CommandGraph.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 05 Nov 2009 09:25:25 +0100
changeset 1554 e07a0f8de03d
parent 1426 af45bba80d85
child 1804 742607c464c4
permissions -rw-r--r--
Print complete Ethernet frame during debug.
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <map>
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
using namespace std;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "CommandGraph.h"
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
/*****************************************************************************/
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
CommandGraph::CommandGraph():
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
    Command("graph", "Output the bus topology as a graph.")
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
{
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
}
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/*****************************************************************************/
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
string CommandGraph::helpString() const
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
{
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    stringstream str;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    str << getName() << " [OPTIONS]" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        << getBriefDescription() << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << "The bus is output in DOT language (see" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << "http://www.graphviz.org/doc/info/lang.html), which can" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "be processed with the tools from the Graphviz" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << "package. Example:" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << "  ethercat graph | dot -Tsvg > bus.svg" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        << "See 'man dot' for more information." << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    return str.str();
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
}
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
/****************************************************************************/
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
void CommandGraph::execute(MasterDevice &m, const StringVector &args)
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
{
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    ec_ioctl_master_t master;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    unsigned int i;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    typedef vector<ec_ioctl_slave_t> SlaveVector;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    SlaveVector slaves;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    ec_ioctl_slave_t slave;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    SlaveVector::const_iterator si;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    map<int, string> portMedia;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    map<int, string>::const_iterator mi;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    map<int, int> mediaWeights;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    map<int, int>::const_iterator wi;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    portMedia[EC_PORT_MII] = "MII";
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    mediaWeights[EC_PORT_MII] = 1;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    portMedia[EC_PORT_EBUS] = "EBUS";
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    mediaWeights[EC_PORT_EBUS] = 5;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    if (args.size()) {
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        stringstream err;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        err << "'" << getName() << "' takes no arguments!";
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        throwInvalidUsageException(err);
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    m.open(MasterDevice::Read);
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    m.getMaster(&master);
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    for (i = 0; i < master.slave_count; i++) {
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
        m.getSlave(&slave, i);
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        slaves.push_back(slave);
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    cout << "/* EtherCAT bus graph. Generated by 'ethercat graph'. */" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        << "strict graph bus {" << endl
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        << "    rankdir=\"LR\"" << endl
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   104
        << "    ranksep=0.8" << endl
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   105
        << "    nodesep=0.8" << endl
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   106
        << "    node [fontname=\"Helvetica\"]" << endl
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   107
        << "    edge [fontname=\"Helvetica\",fontsize=\"10\"]" << endl
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        << endl
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   109
        << "    master [label=\"EtherCAT\\nMaster\"]" << endl;
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    if (slaves.size()) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   112
        cout << "    master -- slave0"; 
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   113
        mi = portMedia.find(slaves.front().ports[0].desc);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   114
        if (mi != portMedia.end())
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   115
            cout << "[label=\"" << mi->second << "\"]";
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   117
        cout << endl;
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    cout << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    for (si = slaves.begin(); si != slaves.end(); si++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   122
	    cout << "    slave" << si->position << " [shape=\"box\""
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   123
            << ",label=\"" << si->position;
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        if (string(si->order).size())
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
            cout << "\\n" << si->order;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   126
        if (si->dc_supported) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   127
            cout << "\\nDC: ";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   128
            if (si->has_dc_system_time) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   129
                switch (si->dc_range) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   130
                    case EC_DC_32:
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   131
                        cout << "32 bit";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   132
                        break;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   133
                    case EC_DC_64:
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   134
                        cout << "64 bit";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   135
                        break;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   136
                    default:
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   137
                        break;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   138
                }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   139
            } else {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   140
                cout << "Delay meas.";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   141
            }
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
   142
            cout << "\\nDelay: " << si->transmission_delay << " ns";
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   143
        }
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        cout << "\"]" << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
        for (i = 1; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   147
            uint16_t next_pos = si->ports[i].next_slave;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   148
            ec_ioctl_slave_t *next = NULL;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   149
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   150
            if (next_pos == 0xffff)
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
                continue;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   153
            if (next_pos < slaves.size()) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   154
                next = &slaves[next_pos];
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   155
            } else {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   156
                cerr << "Invalid next slave pointer." << endl;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   157
            }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   158
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
            cout << "    slave" << si->position << " -- "
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   160
                << "slave" << next_pos << " [taillabel=\"" << i;
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   162
            if (si->dc_supported) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   163
                cout << " [" << si->ports[i].delay_to_next_dc << "]";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   164
            }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   165
            cout << "\",headlabel=\"0";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   166
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   167
            if (next && next->dc_supported) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   168
                cout << " [" << next->ports[0].delay_to_next_dc << "]";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   169
            }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   170
            cout << "\"";
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   171
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   172
            mi = portMedia.find(si->ports[i].desc);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   173
            if (mi == portMedia.end() && next) {
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
                /* Try medium of next-hop slave. */
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   175
                mi = portMedia.find(next->ports[0].desc);
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
            }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
            
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
            if (mi != portMedia.end())
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
                cout << ",label=\"" << mi->second << "\"";
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1422
diff changeset
   181
            wi = mediaWeights.find(si->ports[i].desc);
1422
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
            if (wi != mediaWeights.end())
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
                cout << ",weight=\"" << wi->second << "\"";
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
            
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
            cout << "]" << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
        }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        cout << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    }
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    cout << "}" << endl;
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
}
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
d41e4537b75f Added 'ethercat graph' command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
/*****************************************************************************/