tools/main.cpp
changeset 956 d9b9bc794d10
parent 953 3ed51c088582
child 957 ed5ac2e83495
equal deleted inserted replaced
955:9b1c277a1b34 956:d9b9bc794d10
     6 
     6 
     7 #include <getopt.h>
     7 #include <getopt.h>
     8 
     8 
     9 #include <iostream>
     9 #include <iostream>
    10 #include <string>
    10 #include <string>
       
    11 #include <vector>
    11 using namespace std;
    12 using namespace std;
    12 
    13 
    13 #include "Master.h"
    14 #include "Master.h"
    14 
    15 
    15 /*****************************************************************************/
    16 /*****************************************************************************/
    21 
    22 
    22 static unsigned int masterIndex = DEFAULT_MASTER;
    23 static unsigned int masterIndex = DEFAULT_MASTER;
    23 static int slavePosition = DEFAULT_SLAVEPOSITION;
    24 static int slavePosition = DEFAULT_SLAVEPOSITION;
    24 static int domainIndex = DEFAULT_DOMAININDEX;
    25 static int domainIndex = DEFAULT_DOMAININDEX;
    25 static string command = DEFAULT_COMMAND;
    26 static string command = DEFAULT_COMMAND;
       
    27 vector<string> commandArgs;
    26 
    28 
    27 /*****************************************************************************/
    29 /*****************************************************************************/
    28 
    30 
    29 void printUsage()
    31 void printUsage()
    30 {
    32 {
    31     cerr
    33     cerr
    32         << "Usage: ethercat <COMMAND> [OPTIONS]" << endl
    34         << "Usage: ethercat <COMMAND> [OPTIONS]" << endl
    33 		<< "Commands:" << endl
    35 		<< "Commands:" << endl
    34         << "  data               Output binary domain process data." << endl
    36         << "  data               Output binary domain process data." << endl
       
    37         << "  debug              Set the master debug level." << endl
    35         << "  domain             Show domain information." << endl
    38         << "  domain             Show domain information." << endl
    36         << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
    39         << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
    37         << "  pdos               List Pdo mapping of given slaves." << endl
    40         << "  pdos               List Pdo mapping of given slaves." << endl
    38         << "  xml                Generate slave information xml." << endl
    41         << "  xml                Generate slave information xml." << endl
    39 		<< "Global options:" << endl
    42 		<< "Global options:" << endl
   129 		printUsage();
   132 		printUsage();
   130         exit(1);
   133         exit(1);
   131 	}
   134 	}
   132 
   135 
   133     command = argv[optind];
   136     command = argv[optind];
       
   137     while (++optind < argc)
       
   138         commandArgs.push_back(string(argv[optind]));
   134 }
   139 }
   135 
   140 
   136 /****************************************************************************/
   141 /****************************************************************************/
   137 
   142 
   138 int main(int argc, char **argv)
   143 int main(int argc, char **argv)
   144     try {
   149     try {
   145         master.open(masterIndex);
   150         master.open(masterIndex);
   146 
   151 
   147         if (command == "data") {
   152         if (command == "data") {
   148             master.outputData(domainIndex);
   153             master.outputData(domainIndex);
       
   154         } else if (command == "debug") {
       
   155             master.setDebug(commandArgs);
   149         } else if (command == "domain") {
   156         } else if (command == "domain") {
   150             master.showDomains(domainIndex);
   157             master.showDomains(domainIndex);
   151 		} else if (command == "list" || command == "ls" || command == "slaves") {
   158 		} else if (command == "list" || command == "ls" || command == "slaves") {
   152             master.listSlaves();
   159             master.listSlaves();
   153         } else if (command == "pdos") {
   160         } else if (command == "pdos") {