tool/CommandCStruct.cpp
author Florian Pose <fp@igh-essen.com>
Fri, 05 Mar 2010 16:30:51 +0100
changeset 1840 06fcb795525b
parent 1827 489be2180f71
child 1869 14f634f5b613
permissions -rw-r--r--
Fixed reading error code from write response.
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1524
e7bdab4d6189 Committed misteriously modified files...
Florian Pose <fp@igh-essen.com>
parents: 1514
diff changeset
     3
 *  $Id$
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <string.h>
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
using namespace std;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "CommandCStruct.h"
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    36
#include "MasterDevice.h"
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
CommandCStruct::CommandCStruct():
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
    Command("cstruct", "Generate slave PDO information in C language.")
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
{
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
}
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
string CommandCStruct::helpString() const
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
{
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    stringstream str;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    str << getName() << " [OPTIONS]" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << getBriefDescription() << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "The output C code can be used directly with the" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << "ecrt_slave_config_pdos() function of the application" << endl
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1524
diff changeset
    57
        << "interface." << endl
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "Command-specific options:" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        << "  --alias    -a <alias>" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        << "  --position -p <pos>    Slave selection. See the help of" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        << "                         the 'slaves' command." << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        << numericInfo();
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    return str.str();
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
}
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
/****************************************************************************/
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    71
void CommandCStruct::execute(const StringVector &args)
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
{
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    SlaveList slaves;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    SlaveList::const_iterator si;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    if (args.size()) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        stringstream err;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        err << "'" << getName() << "' takes no arguments!";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        throwInvalidUsageException(err);
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    82
    MasterIndexList::const_iterator mi;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    83
    for (mi = getMasterIndices().begin();
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    84
            mi != getMasterIndices().end(); mi++) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    85
        MasterDevice m(*mi);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    86
        m.open(MasterDevice::Read);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    87
        slaves = selectedSlaves(m);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    88
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    89
        for (si = slaves.begin(); si != slaves.end(); si++) {
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    90
            generateSlaveCStruct(m, *si);
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    91
        }
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
}
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/****************************************************************************/
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
void CommandCStruct::generateSlaveCStruct(
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        MasterDevice &m,
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        const ec_ioctl_slave_t &slave
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        )
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
{
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    ec_ioctl_slave_sync_t sync;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    ec_ioctl_slave_sync_pdo_t pdo;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    ec_ioctl_slave_sync_pdo_entry_t entry;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    unsigned int i, j, k, pdo_pos = 0, entry_pos = 0;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    stringstream id, syncs, pdos, entries;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    if (!slave.sync_count)
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        return;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    id << "slave_" << dec << slave.position << "_";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    for (i = 0; i < slave.sync_count; i++) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
        m.getSync(&sync, slave.position, i);
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        syncs << "   {" << dec << sync.sync_index
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
            << ", " << (EC_READ_BIT(&sync.control_register, 2) ?
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
                    "EC_DIR_OUTPUT" : "EC_DIR_INPUT")
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
            << ", " << dec << (unsigned int) sync.pdo_count
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
            << ", ";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        if (sync.pdo_count) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
            syncs << id.str() << "pdos + " << dec << pdo_pos;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        } else {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
            syncs << "NULL";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        syncs << ", " << (EC_READ_BIT(&sync.control_register, 6) ?
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
                "EC_WD_ENABLE" : "EC_WD_DISABLE")
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
            << "},";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
        syncs << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        pdo_pos += sync.pdo_count;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        for (j = 0; j < sync.pdo_count; j++) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
            m.getPdo(&pdo, slave.position, i, j);
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
            pdos << "   {0x" << hex << setfill('0')
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                << setw(4) << pdo.index
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
                << ", " << dec << (unsigned int) pdo.entry_count
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
                << ", ";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
                if (pdo.entry_count) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
                    pdos << id.str() << "pdo_entries + " << dec << entry_pos;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
                } else {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
                    pdos << "NULL";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
                }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
            pdos << "},";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
            if (strlen((const char *) pdo.name)) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
                pdos << " /* " << pdo.name << " */";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
            }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
            pdos << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
            entry_pos += pdo.entry_count;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
            for (k = 0; k < pdo.entry_count; k++) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
                m.getPdoEntry(&entry, slave.position, i, j, k);
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
                entries << "   {0x" << hex << setfill('0')
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                    << setw(4) << entry.index
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
                    << ", 0x" << setw(2) << (unsigned int) entry.subindex
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
                    << ", " << dec << (unsigned int) entry.bit_length
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
                    << "},";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
                if (strlen((const char *) entry.name)) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
                    entries << " /* " << entry.name << " */";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
                }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                entries << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
            }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    cout
1827
489be2180f71 Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   168
        << "/* Master " << m.getIndex() << ", Slave " << slave.position;
1514
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    if (strlen(slave.order)) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        cout << ", \"" << slave.order << "\"";
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    cout << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        << " * Vendor ID:       0x" << hex << setfill('0')
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
        << setw(8) << slave.vendor_id << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
        << " * Product code:    0x" << hex << setfill('0')
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        << setw(8) << slave.product_code << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        << " * Revision number: 0x" << hex << setfill('0')
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        << setw(8) << slave.revision_number << endl 
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
        << " */" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    if (entry_pos) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
        cout << "ec_pdo_entry_info_t " << id.str()
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
            << "pdo_entries[] = {" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
            << entries.str()
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
            << "};" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
            << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    if (pdo_pos) {
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        cout << "ec_pdo_info_t " << id.str() << "pdos[] = {" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
            << pdos.str()
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
            << "};" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
            << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    }
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    cout << "ec_sync_info_t " << id.str() << "syncs[] = {" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
        << syncs.str()
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        << "};" << endl
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        << endl;
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
}
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
85ac1c91045d Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/*****************************************************************************/