tool/cmd_sdos.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
#include "coe_datatypes.h"
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
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
const char *help_sdos =
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
    "[OPTIONS]\n"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    19
    "Displays the Sdo dictionary with Sdos and Sdo entries.\n"
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    21
    "Sdo dictionary information is displayed in two layers, with are\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    22
    "indented accordingly:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    23
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    24
    "1) Sdos - Hexadecimal Sdo index and the name. Example:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    25
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    26
    "   Sdo 0x1018, \"Identity object\"\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    27
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    28
    "2) Sdo entries - Sdo index and Sdo entry subindex (both hexadecimal)\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    29
    "   followed by the data type, the length in bit, and the description.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    30
    "   Example:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    31
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    32
    "   0x1018:01, uint32, 32 bit, \"Vendor id\"\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    33
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    34
    "If the --quiet option is given, only the Sdos are printed.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    35
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    36
    "Command-specific options:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    37
    "  --slave -s <index>  Positive numerical ring position, or 'all' for\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    38
    "                      all slaves (default).\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    39
    "  --quiet -q          Print only Sdos (without Sdo entries).\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    40
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1130
diff changeset
    41
    "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: 1130
diff changeset
    42
    "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
    43
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/****************************************************************************/
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
void listSlaveSdos(uint16_t, bool);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
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
void command_sdos(void)
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
    masterDev.open(MasterDevice::Read);
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
    if (slavePosition == -1) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        unsigned int numSlaves = masterDev.slaveCount(), i;
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
        for (i = 0; i < numSlaves; i++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
            listSlaveSdos(i, true);
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
    } else {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        listSlaveSdos(slavePosition, false);
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
}
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
/****************************************************************************/
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
void listSlaveSdos(
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
		uint16_t slavePosition,
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
		bool withHeader
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
    ec_ioctl_slave_t slave;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    ec_ioctl_slave_sdo_t sdo;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    ec_ioctl_slave_sdo_entry_t entry;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    unsigned int i, j;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    const CoEDataType *d;
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
    masterDev.getSlave(&slave, slavePosition);
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
    if (withHeader)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        cout << "=== Slave " << slavePosition << " ===" << endl;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    for (i = 0; i < slave.sdo_count; i++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
        masterDev.getSdo(&sdo, slavePosition, i);
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 << "Sdo 0x"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
            << hex << setfill('0')
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
            << setw(4) << sdo.sdo_index
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
            << ", \"" << sdo.name << "\"" << endl;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        if (verbosity == Quiet)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
            continue;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        for (j = 0; j <= sdo.max_subindex; j++) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
            masterDev.getSdoEntry(&entry, slavePosition, -i, j);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
            cout << "  0x" << hex << setfill('0')
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
                << setw(4) << sdo.sdo_index << ":"
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
                << setw(2) << (unsigned int) entry.sdo_entry_subindex
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
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
            if ((d = findDataType(entry.data_type))) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
                cout << d->name;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            } else {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
                cout << "type " << setw(4) << entry.data_type;
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
            cout << ", " << dec << entry.bit_length << " bit, \""
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
                << entry.description << "\"" << endl;
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
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
/*****************************************************************************/