tools/main.cpp
author Florian Pose <fp@igh-essen.com>
Mon, 09 Jun 2008 12:11:19 +0000
changeset 974 5868944a6456
parent 972 ad59641a68c8
child 978 2962baf7e6d1
permissions -rw-r--r--
Implemented Sdo download via ethercat command.
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;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    26
string dataTypeStr;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
/*****************************************************************************/
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
void printUsage()
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
    cerr
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
        << "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
    34
		<< "Commands:" << endl
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
    35
        << "  data               Output binary domain process data." << endl
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
    36
        << "  debug              Set the master debug level." << endl
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    37
        << "  domain             Show domain information." << endl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
        << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
    39
        << "  master             Show master information." << endl
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
    40
        << "  pdos               List Pdo mapping." << endl
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
    41
        << "  sdos               List Sdo dictionaries." << endl
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    42
        << "  sdo_download (sd)  Write an Sdo entry." << endl
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    43
        << "  sdo_upload (su)    Read an Sdo entry." << endl
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
    44
        << "  state              Request slave states." << endl
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
    45
        << "  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
    46
		<< "Global options:" << endl
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
        << "  --master  -m <master>  Index of the master to use. Default: "
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    48
		<< DEFAULT_MASTER << endl
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    49
        << "  --slave   -s <index>   Positive numerical ring position,"
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    50
        << endl
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    51
        << "                         or 'all' for all slaves (default)."
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    52
        << endl
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    53
        << "  --domain  -d <index>   Positive numerical index,"
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    54
        << endl
953
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    55
        << "                         or 'all' for all domains (default)."
3ed51c088582 Nicer usage.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    56
        << endl
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    57
        << "  --type    -t <type>    Forced Sdo data type." << endl
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
    58
        << "  --quiet   -q           Show less output." << endl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "  --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
    60
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
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
    65
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    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
    67
	char *remainder;
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
    static struct option longOptions[] = {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        //name,    has_arg,           flag, val
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        {"master", required_argument, NULL, 'm'},
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
        {"slave",  required_argument, NULL, 's'},
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
    73
        {"domain", required_argument, NULL, 'd'},
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    74
        {"type",   required_argument, NULL, 't'},
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
    75
        {"quiet",  no_argument,       NULL, 'q'},
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        {"help",   no_argument,       NULL, 'h'},
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        {}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    };
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    do {
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    81
        c = getopt_long(argc, argv, "m:s:d:t:qh", longOptions, &optionIndex);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
        switch (c) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
            case 'm':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
                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
    86
                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
    87
                    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
    88
                    printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
                    exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
                }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
				masterIndex = number;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
            case 's':
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    95
                if (!strcmp(optarg, "all")) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    96
                    slavePosition = -1;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    97
                } else {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    98
                    number = strtoul(optarg, &remainder, 0);
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
    99
                    if (remainder == optarg || *remainder
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   100
                            || number < 0 || number > 0xFFFF) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   101
                        cerr << "Invalid slave position "
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   102
                            << optarg << "!" << endl;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   103
                        printUsage();
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   104
                        exit(1);
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   105
                    }
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   106
                    slavePosition = number;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   107
                }
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   110
            case 'd':
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   111
                if (!strcmp(optarg, "all")) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   112
                    domainIndex = -1;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   113
                } else {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   114
                    number = strtoul(optarg, &remainder, 0);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   115
                    if (remainder == optarg || *remainder || number < 0) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   116
                        cerr << "Invalid domain index "
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   117
							<< optarg << "!" << endl;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   118
                        printUsage();
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   119
                        exit(1);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   120
                    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   121
                    domainIndex = number;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   122
                }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   123
                break;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   124
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   125
            case 't':
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   126
                dataTypeStr = optarg;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   127
                break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   128
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   129
            case 'q':
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   130
                quiet = true;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   131
                break;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   132
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
            case 'h':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
            case '?':
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
                printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                exit(0);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
            default:
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
                break;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    while (c != -1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
	argCount = argc - optind;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
	if (!argCount) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
        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
   148
		printUsage();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
	}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    command = argv[optind];
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   153
    while (++optind < argc)
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   154
        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
   155
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
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
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
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
   160
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    Master master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
	getOptions(argc, argv);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   165
    try {
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   166
        master.setIndex(masterIndex);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   168
        if (command == "data") {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   169
            master.outputData(domainIndex);
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   170
        } else if (command == "debug") {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 953
diff changeset
   171
            master.setDebug(commandArgs);
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   172
        } else if (command == "domain") {
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   173
            master.showDomains(domainIndex);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   174
		} else if (command == "list" || command == "ls" || command == "slaves") {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   175
            master.listSlaves();
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   176
		} 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
   177
            master.showMaster();
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   178
        } else if (command == "pdos") {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   179
            master.listPdos(slavePosition, quiet);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   180
        } else if (command == "sdos") {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   181
            master.listSdos(slavePosition, quiet);
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   182
        } else if (command == "sdo_download" || command == "sd") {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   183
            master.sdoDownload(slavePosition, dataTypeStr, commandArgs);
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   184
        } else if (command == "sdo_upload" || command == "su") {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   185
            master.sdoUpload(slavePosition, dataTypeStr, commandArgs);
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   186
        } 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
   187
            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
   188
        } 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
   189
            master.generateXml(slavePosition);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   190
        } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   191
            cerr << "Unknown command " << command << "!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   192
            printUsage();
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   193
            exit(1);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   194
        }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   195
    } catch (MasterException &e) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   196
        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
   197
        exit(1);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
	return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
/****************************************************************************/