tools/main.cpp
changeset 968 b0e894257743
parent 966 f1a7ea8a550a
child 972 ad59641a68c8
equal deleted inserted replaced
967:93807963b906 968:b0e894257743
    14 #include "Master.h"
    14 #include "Master.h"
    15 
    15 
    16 /*****************************************************************************/
    16 /*****************************************************************************/
    17 
    17 
    18 #define DEFAULT_MASTER 0
    18 #define DEFAULT_MASTER 0
    19 #define DEFAULT_COMMAND "slaves"
       
    20 #define DEFAULT_SLAVEPOSITION -1
       
    21 #define DEFAULT_DOMAININDEX -1
       
    22 
    19 
    23 static unsigned int masterIndex = DEFAULT_MASTER;
    20 static unsigned int masterIndex = DEFAULT_MASTER;
    24 static int slavePosition = DEFAULT_SLAVEPOSITION;
    21 static int slavePosition = -1;
    25 static int domainIndex = DEFAULT_DOMAININDEX;
    22 static int domainIndex = -1;
    26 static string command = DEFAULT_COMMAND;
    23 static string command;
    27 vector<string> commandArgs;
    24 vector<string> commandArgs;
    28 static bool quiet = false;
    25 static bool quiet = false;
       
    26 string dataTypeStr;
    29 
    27 
    30 /*****************************************************************************/
    28 /*****************************************************************************/
    31 
    29 
    32 void printUsage()
    30 void printUsage()
    33 {
    31 {
    39         << "  domain             Show domain information." << endl
    37         << "  domain             Show domain information." << endl
    40         << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
    38         << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
    41         << "  master             Show master information." << endl
    39         << "  master             Show master information." << endl
    42         << "  pdos               List Pdo mapping." << endl
    40         << "  pdos               List Pdo mapping." << endl
    43         << "  sdos               List Sdo dictionaries." << endl
    41         << "  sdos               List Sdo dictionaries." << endl
       
    42         << "  sdo_upload (su)    Read Sdo entries." << endl
    44         << "  state              Request slave states." << endl
    43         << "  state              Request slave states." << endl
    45         << "  xml                Generate slave information xmls." << endl
    44         << "  xml                Generate slave information xmls." << endl
    46 		<< "Global options:" << endl
    45 		<< "Global options:" << endl
    47         << "  --master  -m <master>  Index of the master to use. Default: "
    46         << "  --master  -m <master>  Index of the master to use. Default: "
    48 		<< DEFAULT_MASTER << endl
    47 		<< DEFAULT_MASTER << endl
    52         << endl
    51         << endl
    53         << "  --domain  -d <index>   Positive numerical index,"
    52         << "  --domain  -d <index>   Positive numerical index,"
    54         << endl
    53         << endl
    55         << "                         or 'all' for all domains (default)."
    54         << "                         or 'all' for all domains (default)."
    56         << endl
    55         << endl
       
    56         << "  --type    -t <type>    Forced Sdo data type." << endl
    57         << "  --quiet   -q           Show less output." << endl
    57         << "  --quiet   -q           Show less output." << endl
    58         << "  --help    -h           Show this help." << endl;
    58         << "  --help    -h           Show this help." << endl;
    59 }
    59 }
    60 
    60 
    61 /*****************************************************************************/
    61 /*****************************************************************************/
    68     static struct option longOptions[] = {
    68     static struct option longOptions[] = {
    69         //name,    has_arg,           flag, val
    69         //name,    has_arg,           flag, val
    70         {"master", required_argument, NULL, 'm'},
    70         {"master", required_argument, NULL, 'm'},
    71         {"slave",  required_argument, NULL, 's'},
    71         {"slave",  required_argument, NULL, 's'},
    72         {"domain", required_argument, NULL, 'd'},
    72         {"domain", required_argument, NULL, 'd'},
       
    73         {"type",   required_argument, NULL, 't'},
    73         {"quiet",  no_argument,       NULL, 'q'},
    74         {"quiet",  no_argument,       NULL, 'q'},
    74         {"help",   no_argument,       NULL, 'h'},
    75         {"help",   no_argument,       NULL, 'h'},
    75         {}
    76         {}
    76     };
    77     };
    77 
    78 
    78     do {
    79     do {
    79         c = getopt_long(argc, argv, "m:s:d:qh", longOptions, &optionIndex);
    80         c = getopt_long(argc, argv, "m:s:d:t:qh", longOptions, &optionIndex);
    80 
    81 
    81         switch (c) {
    82         switch (c) {
    82             case 'm':
    83             case 'm':
    83                 number = strtoul(optarg, &remainder, 0);
    84                 number = strtoul(optarg, &remainder, 0);
    84                 if (remainder == optarg || *remainder || number < 0) {
    85                 if (remainder == optarg || *remainder || number < 0) {
   118                     }
   119                     }
   119                     domainIndex = number;
   120                     domainIndex = number;
   120                 }
   121                 }
   121                 break;
   122                 break;
   122 
   123 
       
   124             case 't':
       
   125                 dataTypeStr = optarg;
       
   126                 break;
       
   127 
   123             case 'q':
   128             case 'q':
   124                 quiet = true;
   129                 quiet = true;
   125                 break;
   130                 break;
   126 
   131 
   127             case 'h':
   132             case 'h':
   171             master.showMaster();
   176             master.showMaster();
   172         } else if (command == "pdos") {
   177         } else if (command == "pdos") {
   173             master.listPdos(slavePosition, quiet);
   178             master.listPdos(slavePosition, quiet);
   174         } else if (command == "sdos") {
   179         } else if (command == "sdos") {
   175             master.listSdos(slavePosition, quiet);
   180             master.listSdos(slavePosition, quiet);
       
   181         } else if (command == "sdo_upload" || command == "su") {
       
   182             master.sdoUpload(slavePosition, dataTypeStr, commandArgs);
   176         } else if (command == "state") {
   183         } else if (command == "state") {
   177             master.requestStates(slavePosition, commandArgs);
   184             master.requestStates(slavePosition, commandArgs);
   178         } else if (command == "xml") {
   185         } else if (command == "xml") {
   179             master.generateXml(slavePosition);
   186             master.generateXml(slavePosition);
   180         } else {
   187         } else {