tool/CommandXml.cpp
author Martin Troxler <martin.troxler@komaxgroup.com>
Tue, 15 Dec 2009 10:55:36 +0100
changeset 1600 e36c92cf58a9
parent 1474 758a9bd3e549
child 1560 0ca50da62c52
permissions -rw-r--r--
use given send interval to limit SDO/FOE traffic
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
1222
7348d6abb6cb Applied patch by Karsten Schwinne, adding a few header files necessary
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
    32
#include <string.h>
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
using namespace std;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "CommandXml.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
CommandXml::CommandXml():
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
    Command("xml", "Generate slave information XML.")
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
string CommandXml::helpString() const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    50
    str << getName() << " [OPTIONS]" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << getBriefDescription() << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
    54
        << "Note that the PDO information can either originate" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "from the SII or from the CoE communication area. For" << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
    56
        << "slaves, that support configuring PDO assignment and" << endl
1144
7dbfdd61812c Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents: 1142
diff changeset
    57
        << "mapping, the output depends on the last configuration." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "Command-specific options:" << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
    60
        << "  --alias    -a <alias>" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
    61
        << "  --position -p <pos>    Slave selection. See the help of" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
    62
        << "                         the 'slaves' command." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        << numericInfo();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    return str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
void CommandXml::execute(MasterDevice &m, const StringVector &args)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
{
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    73
    SlaveList slaves;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    74
    SlaveList::const_iterator si;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    75
1373
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    76
    if (args.size()) {
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    77
        stringstream err;
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    78
        err << "'" << getName() << "' takes no arguments!";
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    79
        throwInvalidUsageException(err);
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    80
    }
e651000f1ff1 Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    81
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    m.open(MasterDevice::Read);
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    83
    slaves = selectedSlaves(m);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    85
    cout << "<?xml version=\"1.0\" ?>" << endl;
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    86
    if (slaves.size() > 1) {
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    87
        cout << "<EtherCATInfoList>" << endl;
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    88
    }
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    89
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    90
    for (si = slaves.begin(); si != slaves.end(); si++) {
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    91
        generateSlaveXml(m, *si, slaves.size() > 1 ? 1 : 0);
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    92
    }
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    93
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    94
    if (slaves.size() > 1) {
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
    95
        cout << "</EtherCATInfoList>" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   101
void CommandXml::generateSlaveXml(
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   102
        MasterDevice &m,
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   103
        const ec_ioctl_slave_t &slave,
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   104
        unsigned int indent
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   105
        )
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    ec_ioctl_slave_sync_t sync;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    ec_ioctl_slave_sync_pdo_t pdo;
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   109
    string pdoType, in;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    ec_ioctl_slave_sync_pdo_entry_t entry;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    unsigned int i, j, k;
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   112
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   113
    for (i = 0; i < indent; i++) {
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   114
        in += "  ";
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   115
    }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   118
        << in << "<EtherCATInfo>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   119
        << in << "  <!-- Slave " << slave.position << " -->" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   120
        << in << "  <Vendor>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   121
        << in << "    <Id>" << slave.vendor_id << "</Id>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   122
        << in << "  </Vendor>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   123
        << in << "  <Descriptions>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   124
        << in << "    <Devices>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   125
        << in << "      <Device>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   126
        << in << "        <Type ProductCode=\"#x"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
        << hex << setfill('0') << setw(8) << slave.product_code
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        << "\" RevisionNo=\"#x"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
        << hex << setfill('0') << setw(8) << slave.revision_number
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        << "\">" << slave.order << "</Type>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    if (strlen(slave.name)) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   134
            << in << "        <Name><![CDATA["
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
            << slave.name
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
            << "]]></Name>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    for (i = 0; i < slave.sync_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   140
        m.getSync(&sync, slave.position, i);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   143
            << in << "        <Sm Enable=\"" << dec << (unsigned int) sync.enable
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
            << "\" StartAddress=\"" << sync.physical_start_address
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
            << "\" ControlByte=\"" << (unsigned int) sync.control_register
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
            << "\" DefaultSize=\"" << sync.default_size
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
            << "\" />" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    for (i = 0; i < slave.sync_count; i++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   151
        m.getSync(&sync, slave.position, i);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        for (j = 0; j < sync.pdo_count; j++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   154
            m.getPdo(&pdo, slave.position, i, j);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
            pdoType = (sync.control_register & 0x04 ? "R" : "T");
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1222
diff changeset
   156
            pdoType += "xPdo"; // last 2 letters lowercase in XML!
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
            cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   159
                << in << "        <" << pdoType
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
                << " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   161
                << in << "          <Index>#x"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                << hex << setfill('0') << setw(4) << pdo.index
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
                << "</Index>" << endl
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   164
                << in << "          <Name>" << pdo.name << "</Name>" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
            for (k = 0; k < pdo.entry_count; k++) {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   167
                m.getPdoEntry(&entry, slave.position, i, j, k);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
                cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   170
                    << in << "          <Entry>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   171
                    << in << "            <Index>#x"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
                    << hex << setfill('0') << setw(4) << entry.index
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
                    << "</Index>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
                if (entry.index)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
                    cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   176
                        << in << "            <SubIndex>"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
                        << dec << (unsigned int) entry.subindex
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
                        << "</SubIndex>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
                
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
                cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   181
                    << in << "            <BitLen>"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
                    << dec << (unsigned int) entry.bit_length
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
                    << "</BitLen>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
                if (entry.index) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
                    cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   187
                        << in << "            <Name>" << entry.name
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
                        << "</Name>" << endl
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   189
                        << in << "            <DataType>";
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
                    if (entry.bit_length == 1) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
                        cout << "BOOL";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
                    } else if (!(entry.bit_length % 8)) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
                        if (entry.bit_length <= 64)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
                            cout << "UINT" << (unsigned int) entry.bit_length;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
                        else
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
                            cout << "STRING("
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
                                << (unsigned int) (entry.bit_length / 8)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
                                << ")";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
                    } else {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
                        cerr << "Invalid bit length "
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
                            << (unsigned int) entry.bit_length << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
                    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
                        cout << "</DataType>" << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
                }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   208
                cout << in << "          </Entry>" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
            }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
            cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   212
                << in << "        </" << pdoType << ">" << endl;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    cout
1474
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   217
        << in << "      </Device>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   218
        << in << "    </Devices>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   219
        << in << "  </Descriptions>" << endl
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   220
        << in << "</EtherCATInfo>" << endl;
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   221
}
758a9bd3e549 'ethercat xml' creates <EtherCATInfoList> for more than one slave.
Florian Pose <fp@igh-essen.com>
parents: 1373
diff changeset
   222
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
/*****************************************************************************/