tool/cmd_data.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 24 Jul 2008 07:40:45 +0000
changeset 1139 074caa25365e
parent 1137 a73c0f54be42
permissions -rw-r--r--
Output requested help to stdout, help on invalid usage to stderr.
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <iostream>
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
using namespace std;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include "globals.h"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
/*****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
const char *help_data =
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
    "[OPTIONS]\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
    "\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
    "Output binary domain data.\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
    "\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
    "Command-specific options:\n"
1133
860d1c3d08fc Updated docs.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    20
    "  --domain -d <index> Positive numerical domain index, or 'all' for\n"
860d1c3d08fc Updated docs.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    21
    "                      all domains (default). In this case, data of all\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
    22
    "                      domains are concatenated.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
    23
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
    24
    "Numerical values can be specified either with decimal (no prefix),\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
    25
    "octal (prefix '0') or hexadecimal (prefix '0x') base.\n";
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
void outputDomainData(unsigned int);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
void command_data()
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
    masterDev.open(MasterDevice::Read);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
    if (domainIndex == -1) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
        unsigned int i;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
        ec_ioctl_master_t master;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
        masterDev.getMaster(&master);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
        for (i = 0; i < master.domain_count; i++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
            outputDomainData(i);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
    } else {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
        outputDomainData(domainIndex);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void outputDomainData(unsigned int domainIndex)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
    ec_ioctl_domain_t domain;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    ec_ioctl_domain_data_t data;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    unsigned char *processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    unsigned int i;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    masterDev.getDomain(&domain, domainIndex);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    if (!domain.data_size)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        return;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    processData = new unsigned char[domain.data_size];
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    try {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
        masterDev.getData(&data, domainIndex, domain.data_size, processData);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    } catch (MasterDeviceException &e) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        delete [] processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        throw e;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    for (i = 0; i < data.data_size; i++)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        cout << processData[i];
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    cout.flush();
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    delete [] processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
/****************************************************************************/