tools/main.cpp
author Florian Pose <fp@igh-essen.com>
Wed, 02 Jul 2008 14:28:30 +0000
changeset 1083 1322dc34cb37
parent 1066 7ece00bd6559
child 1099 eb8d16507d88
permissions -rw-r--r--
Updated header docs, features and news file.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <getopt.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <iostream>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <string>
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
    11
#include <vector>
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
using namespace std;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include "Master.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#define DEFAULT_MASTER 0
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
static unsigned int masterIndex = DEFAULT_MASTER;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    21
static int slavePosition = -1;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    22
static int domainIndex = -1;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    23
static string command;
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
    24
vector<string> commandArgs;
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
    25
static bool quiet = false;
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    26
static bool verbose = false;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    27
string dataTypeStr;
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
    28
bool force = false;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
void printUsage()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
    cerr
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
        << "Usage: ethercat <COMMAND> [OPTIONS]" << endl
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
		<< "Commands:" << endl
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    37
        << "  alias         Write alias addresses." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    38
        << "  config        Show bus configuration." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    39
        << "  data          Output binary domain process data." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    40
        << "  debug         Set the master's debug level." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    41
        << "  domain        Show domain information." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    42
        << "  master        Show master information." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    43
        << "  pdos          List Pdo assignment/mapping." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    44
        << "  sdo_download  Write an Sdo entry." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    45
        << "  sdos          List Sdo dictionaries." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    46
        << "  sdo_upload    Read an Sdo entry." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    47
        << "  sii_read      Output a slave's SII contents." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    48
        << "  sii_write     Write slave's SII contents." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    49
        << "  slaves        Show slaves." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    50
        << "  state         Request slave states." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    51
        << "  xml           Generate slave information xmls." << endl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
		<< "Global options:" << endl
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << "  --master  -m <master>  Index of the master to use. Default: "
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    54
		<< DEFAULT_MASTER << endl
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    55
        << "  --slave   -s <index>   Positive numerical ring position,"
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    56
        << endl
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    57
        << "                         or 'all' for all slaves (default)."
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    58
        << endl
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    59
        << "  --domain  -d <index>   Positive numerical index,"
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    60
        << endl
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    61
        << "                         or 'all' for all domains (default)."
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    62
        << endl
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    63
        << "  --type    -t <type>    Forced Sdo data type." << endl
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
    64
        << "  --force   -f           Force action." << endl
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    65
        << "  --quiet   -q           Output less information." << endl
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    66
        << "  --verbose -v           Output more information." << endl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
        << "  --help    -h           Show this help." << endl;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
void getOptions(int argc, char **argv)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    int c, argCount, optionIndex, number;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
	char *remainder;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    static struct option longOptions[] = {
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    78
        //name,     has_arg,           flag, val
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    79
        {"master",  required_argument, NULL, 'm'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    80
        {"slave",   required_argument, NULL, 's'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    81
        {"domain",  required_argument, NULL, 'd'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    82
        {"type",    required_argument, NULL, 't'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    83
        {"force",   no_argument,       NULL, 'f'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    84
        {"quiet",   no_argument,       NULL, 'q'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    85
        {"verbose", no_argument,       NULL, 'v'},
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    86
        {"help",    no_argument,       NULL, 'h'},
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        {}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    };
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    do {
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
    91
        c = getopt_long(argc, argv, "m:s:d:t:fqvh", longOptions, &optionIndex);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        switch (c) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
            case 'm':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
                number = strtoul(optarg, &remainder, 0);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
                if (remainder == optarg || *remainder || number < 0) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
                    cerr << "Invalid master number " << optarg << "!" << endl;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
                    printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
                    exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
                }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
				masterIndex = number;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            case 's':
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   105
                if (!strcmp(optarg, "all")) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   106
                    slavePosition = -1;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   107
                } else {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   108
                    number = strtoul(optarg, &remainder, 0);
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   109
                    if (remainder == optarg || *remainder
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   110
                            || number < 0 || number > 0xFFFF) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   111
                        cerr << "Invalid slave position "
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   112
                            << optarg << "!" << endl;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   113
                        printUsage();
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   114
                        exit(1);
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   115
                    }
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   116
                    slavePosition = number;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   117
                }
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   120
            case 'd':
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   121
                if (!strcmp(optarg, "all")) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   122
                    domainIndex = -1;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   123
                } else {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   124
                    number = strtoul(optarg, &remainder, 0);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   125
                    if (remainder == optarg || *remainder || number < 0) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   126
                        cerr << "Invalid domain index "
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   127
							<< optarg << "!" << endl;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   128
                        printUsage();
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   129
                        exit(1);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   130
                    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   131
                    domainIndex = number;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   132
                }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   133
                break;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   134
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   135
            case 't':
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   136
                dataTypeStr = optarg;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   137
                break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   138
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   139
            case 'f':
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   140
                force = true;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   141
                break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   142
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   143
            case 'q':
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   144
                quiet = true;
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   145
                verbose = false;
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   146
                break;
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   147
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   148
            case 'v':
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   149
                verbose = true;
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   150
                quiet = false;
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   151
                break;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   152
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
            case 'h':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
            case '?':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
                exit(0);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
            default:
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    while (c != -1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
	argCount = argc - optind;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
	if (!argCount) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        cerr << "Please specify a command!" << endl;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
		printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
	}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    command = argv[optind];
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   173
    while (++optind < argc)
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   174
        commandArgs.push_back(string(argv[optind]));
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
int main(int argc, char **argv)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    Master master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
	getOptions(argc, argv);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   185
    try {
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   186
        master.setIndex(masterIndex);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   188
        if (command == "alias") {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   189
            master.writeAlias(slavePosition, force, commandArgs);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   190
        } else if (command == "config") {
1066
7ece00bd6559 Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents: 1065
diff changeset
   191
            master.showConfigs(verbose);
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   192
        } else if (command == "data") {
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   193
            master.outputData(domainIndex);
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   194
        } else if (command == "debug") {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   195
            master.setDebug(commandArgs);
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   196
        } else if (command == "domain") {
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   197
            master.showDomains(domainIndex);
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   198
		} else if (command == "master") {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   199
            master.showMaster();
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   200
        } else if (command == "pdos") {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   201
            master.listPdos(slavePosition, quiet);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   202
        } else if (command == "sdos") {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   203
            master.listSdos(slavePosition, quiet);
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   204
        } else if (command == "sdo_download" || command == "sd") {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   205
            master.sdoDownload(slavePosition, dataTypeStr, commandArgs);
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   206
        } else if (command == "sdo_upload" || command == "su") {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   207
            master.sdoUpload(slavePosition, dataTypeStr, commandArgs);
1065
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   208
		} else if (command == "slave" || command == "slaves"
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   209
                || command == "list" || command == "ls") {
d1d2aa556344 United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   210
            master.showSlaves(slavePosition, verbose);
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   211
        } else if (command == "sii_read" || command == "sr") {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   212
            master.siiRead(slavePosition);
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   213
        } else if (command == "sii_write" || command == "sw") {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   214
            master.siiWrite(slavePosition, force, commandArgs);
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   215
        } else if (command == "state") {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   216
            master.requestStates(slavePosition, commandArgs);
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   217
        } else if (command == "xml") {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   218
            master.generateXml(slavePosition);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   219
        } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   220
            cerr << "Unknown command " << command << "!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   221
            printUsage();
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   222
            exit(1);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   223
        }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   224
    } catch (MasterException &e) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   225
        cerr << e.what() << endl;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
	return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
/****************************************************************************/