tool/cmd_domain.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
#include <iomanip>
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
using namespace std;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include "globals.h"
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
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
const char *help_domains =
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
    "[OPTIONS]\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
    "\n"
1130
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    18
    "Show information about the application's configured domains.\n"
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    20
    "Without the --verbose option, the domains are displayed one-per-line.\n"
1130
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    21
    "Example:\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    22
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    23
    "Domain0: LogBaseAddr 0x00000000, Size   6, WorkingCounter 0/1\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    24
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    25
    "The domain's base address for the logical datagram (LRD/LWR/LRW)\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    26
    "is displayed followed by the domain's process data size in byte.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    27
    "The last values are the current datagram working counter sum and\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    28
    "the expected working counter sum. If the values are equal, all\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    29
    "Pdos are exchanged.\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    30
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    31
    "If the --verbose option is given, the participating slave\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    32
    "configurations/FMMUs and the current process data are additionally\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    33
    "displayed:\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    34
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    35
    "Domain1: LogBaseAddr 0x00000006, Size   6, WorkingCounter 0/1\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    36
    "  SlaveConfig 1001:0, SM3 ( Input), LogAddr 0x00000006, Size 6\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    37
    "    00 00 00 00 00 00\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    38
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    39
    "The process data are displayed as hexadecimal bytes.\n"
1130
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    40
    "\n"
bb1c11adb2db Updated first part of command documentation.
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
    41
    "Command-specific options:\n"
1133
860d1c3d08fc Updated docs.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    42
    "  --domain   -d <index> Positive numerical domain index, or 'all'\n"
860d1c3d08fc Updated docs.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    43
    "                        for all domains (default).\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    44
    "  --verbose  -v         Show FMMUs and process data additionally.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    45
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    46
    "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: 1136
diff changeset
    47
    "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
    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
void showDomain(unsigned int);
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
/****************************************************************************/
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
void command_domains(void)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    masterDev.open(MasterDevice::Read);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    if (domainIndex == -1) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        unsigned int i;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        ec_ioctl_master_t master;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        masterDev.getMaster(&master);
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
        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
    66
            showDomain(i);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    } else {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
        showDomain(domainIndex);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
}
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
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
void showDomain(unsigned int domainIndex)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    ec_ioctl_domain_t domain;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    unsigned char *processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    ec_ioctl_domain_data_t data;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    unsigned int i, j;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    ec_ioctl_domain_fmmu_t fmmu;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    unsigned int dataOffset;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    masterDev.getDomain(&domain, domainIndex);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
	cout << "Domain" << dec << domainIndex << ":"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
		<< " LogBaseAddr 0x"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
		<< hex << setfill('0')
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        << setw(8) << domain.logical_base_address
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
		<< ", Size " << dec << setfill(' ')
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        << setw(3) << domain.data_size
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
		<< ", WorkingCounter "
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
		<< domain.working_counter << "/"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        << domain.expected_working_counter << endl;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    if (!domain.data_size || verbosity != Verbose)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        return;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    processData = new unsigned char[domain.data_size];
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    try {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        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
   103
    } catch (MasterDeviceException &e) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        delete [] processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        throw e;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    for (i = 0; i < domain.fmmu_count; i++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        masterDev.getFmmu(&fmmu, domainIndex, i);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        cout << "  SlaveConfig "
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            << dec << fmmu.slave_config_alias
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
            << ":" << fmmu.slave_config_position
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
            << ", SM" << (unsigned int) fmmu.sync_index << " ("
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
            << setfill(' ') << setw(6)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
            << (fmmu.dir == EC_DIR_INPUT ? "Input" : "Output")
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
            << "), LogAddr 0x"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
            << hex << setfill('0')
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
            << setw(8) << fmmu.logical_address
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
            << ", Size " << dec << fmmu.data_size << endl;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        dataOffset = fmmu.logical_address - domain.logical_base_address;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        if (dataOffset + fmmu.data_size > domain.data_size) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
            stringstream err;
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
   125
            delete [] processData;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
            err << "Fmmu information corrupted!";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1133
diff changeset
   127
            throw CommandException(err);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        cout << "    " << hex << setfill('0');
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        for (j = 0; j < fmmu.data_size; j++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
            if (j && !(j % BreakAfterBytes))
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
                cout << endl << "    ";
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
            cout << setw(2)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
                << (unsigned int) *(processData + dataOffset + j) << " ";
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
        cout << endl;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    delete [] processData;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
/*****************************************************************************/