tools/main.cpp
changeset 966 f1a7ea8a550a
parent 965 1aee4aa1def3
child 968 b0e894257743
equal deleted inserted replaced
965:1aee4aa1def3 966:f1a7ea8a550a
    23 static unsigned int masterIndex = DEFAULT_MASTER;
    23 static unsigned int masterIndex = DEFAULT_MASTER;
    24 static int slavePosition = DEFAULT_SLAVEPOSITION;
    24 static int slavePosition = DEFAULT_SLAVEPOSITION;
    25 static int domainIndex = DEFAULT_DOMAININDEX;
    25 static int domainIndex = DEFAULT_DOMAININDEX;
    26 static string command = DEFAULT_COMMAND;
    26 static string command = DEFAULT_COMMAND;
    27 vector<string> commandArgs;
    27 vector<string> commandArgs;
       
    28 static bool quiet = false;
    28 
    29 
    29 /*****************************************************************************/
    30 /*****************************************************************************/
    30 
    31 
    31 void printUsage()
    32 void printUsage()
    32 {
    33 {
    51         << endl
    52         << endl
    52         << "  --domain  -d <index>   Positive numerical index,"
    53         << "  --domain  -d <index>   Positive numerical index,"
    53         << endl
    54         << endl
    54         << "                         or 'all' for all domains (default)."
    55         << "                         or 'all' for all domains (default)."
    55         << endl
    56         << endl
       
    57         << "  --quiet   -q           Show less output." << endl
    56         << "  --help    -h           Show this help." << endl;
    58         << "  --help    -h           Show this help." << endl;
    57 }
    59 }
    58 
    60 
    59 /*****************************************************************************/
    61 /*****************************************************************************/
    60 
    62 
    66     static struct option longOptions[] = {
    68     static struct option longOptions[] = {
    67         //name,    has_arg,           flag, val
    69         //name,    has_arg,           flag, val
    68         {"master", required_argument, NULL, 'm'},
    70         {"master", required_argument, NULL, 'm'},
    69         {"slave",  required_argument, NULL, 's'},
    71         {"slave",  required_argument, NULL, 's'},
    70         {"domain", required_argument, NULL, 'd'},
    72         {"domain", required_argument, NULL, 'd'},
       
    73         {"quiet",  no_argument,       NULL, 'q'},
    71         {"help",   no_argument,       NULL, 'h'},
    74         {"help",   no_argument,       NULL, 'h'},
    72         {}
    75         {}
    73     };
    76     };
    74 
    77 
    75     do {
    78     do {
    76         c = getopt_long(argc, argv, "m:s:d:h", longOptions, &optionIndex);
    79         c = getopt_long(argc, argv, "m:s:d:qh", longOptions, &optionIndex);
    77 
    80 
    78         switch (c) {
    81         switch (c) {
    79             case 'm':
    82             case 'm':
    80                 number = strtoul(optarg, &remainder, 0);
    83                 number = strtoul(optarg, &remainder, 0);
    81                 if (remainder == optarg || *remainder || number < 0) {
    84                 if (remainder == optarg || *remainder || number < 0) {
   113                         printUsage();
   116                         printUsage();
   114                         exit(1);
   117                         exit(1);
   115                     }
   118                     }
   116                     domainIndex = number;
   119                     domainIndex = number;
   117                 }
   120                 }
       
   121                 break;
       
   122 
       
   123             case 'q':
       
   124                 quiet = true;
   118                 break;
   125                 break;
   119 
   126 
   120             case 'h':
   127             case 'h':
   121             case '?':
   128             case '?':
   122                 printUsage();
   129                 printUsage();
   161 		} else if (command == "list" || command == "ls" || command == "slaves") {
   168 		} else if (command == "list" || command == "ls" || command == "slaves") {
   162             master.listSlaves();
   169             master.listSlaves();
   163 		} else if (command == "master") {
   170 		} else if (command == "master") {
   164             master.showMaster();
   171             master.showMaster();
   165         } else if (command == "pdos") {
   172         } else if (command == "pdos") {
   166             master.listPdos(slavePosition);
   173             master.listPdos(slavePosition, quiet);
   167         } else if (command == "sdos") {
   174         } else if (command == "sdos") {
   168             master.listSdos(slavePosition);
   175             master.listSdos(slavePosition, quiet);
   169         } else if (command == "state") {
   176         } else if (command == "state") {
   170             master.requestStates(slavePosition, commandArgs);
   177             master.requestStates(slavePosition, commandArgs);
   171         } else if (command == "xml") {
   178         } else if (command == "xml") {
   172             master.generateXml(slavePosition);
   179             master.generateXml(slavePosition);
   173         } else {
   180         } else {