1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
|
/*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#include "Aria.h"
#include <stdio.h>
/* Queries a subset of the ARIA classes for help text on their command line
* arguments, outputs nd creates files containing that text, plus two files that
* aggregates them all, one with some HTML formatting for use in the doxygen
* documentation, one with an explanatory header for use as a stand alone
* text file. It redirects the log help output be reopening stdout bound to
* each file and then calling the logOptions() or similar methods on objects
* of the classes with options.
*
*
* When compiling this program, you must define either FOR_ARIA or
* FOR_ARNETWORKING (or both) with -D, since this program can be used either
* for ARIA or ArNetworking.
*
* The files generated are:
* docs/options/<class name>
* docs/options/all_options.dox
* CommandLineOptions.txt.in
*
* If FOR_ARIA is defined, then the classes whose options are included are:
* ArRobotConnector
* ArLaserConnector with Sick LMS2xx
* ArLaserConnector with Sick LMS1xx
* ArLaserConnector with URG 1.0
* ArLaserConnector with URG 2.0
* ArLaserConnector with LMS5xx
* ArLaserConnector with SICK S3xxx Series
* ArLaserConnector with Keyence SZ Series
* ArLaserConnector with SICK TiM3XX
* ArPTZConnector
* ArGPSConnector
* ArCompassConnector
* ArSonarConnector
* [ArDaemonizer?]
*
* If FOR_ARNETWORKING is defined, then these classes are also included:
* ArClientSimpleConnector
* ArServerSimpleOpener
* ArClientSwitchManager
*/
/* Wrapper classes provide a standardized publically accessible logOptions()
* method for each class that have the ability to log options in some way.
* (They can all be stored as Wrapper classes below, and they expose
* logOptions() as a public method instead of private.)
*/
class Wrapper {
public:
virtual void logOptions() = 0;
};
#ifdef FOR_ARIA
#include "ArArgumentParser.h"
#include "ArRobotConnector.h"
#include "ArGPSConnector.h"
#include "ArTCM2.h"
#include "ArSonarConnector.h"
#include "ArPTZConnector.h"
class ArRobotConnectorWrapper :
public ArRobotConnector, public virtual Wrapper
{
public:
ArRobotConnectorWrapper(ArArgumentParser *argParser) :
ArRobotConnector(argParser, NULL)
{
}
virtual void logOptions()
{
ArRobotConnector::logOptions();
}
};
class ArPTZConnectorWrapper :
public ArPTZConnector, public virtual Wrapper
{
public:
ArPTZConnectorWrapper(ArArgumentParser *argParser) :
ArPTZConnector(argParser, NULL)
{
}
virtual void logOptions()
{
ArPTZConnector::logOptions();
}
};
class ArLaserConnectorWrapper :
public ArLaserConnector, public virtual Wrapper
{
ArLMS2xx lms2xxLaser;
ArUrg urgLaser;
ArUrg_2_0 urg2Laser;
ArLMS1XX lms1xxLaser;
ArLMS1XX lms5xxLaser;
ArS3Series s3xxLaser;
ArSZSeries szLaser;
ArLMS1XX tim3xxLaser;
public:
ArLaserConnectorWrapper(ArArgumentParser *argParser) :
ArLaserConnector(argParser, NULL, NULL),
lms2xxLaser(1), urgLaser(1), urg2Laser(1), lms1xxLaser(1, "lms1xx", ArLMS1XX::LMS1XX),
lms5xxLaser(1, "lms5xx", ArLMS1XX::LMS5XX), s3xxLaser(1), szLaser(1),
tim3xxLaser(1, "tim3XX", ArLMS1XX::TiM3XX)
{
}
virtual void logOptions()
{
puts(
"Laser types and options may also be set in the robot parameter file. See the\n"
"ARIA reference documentation for details.\n\n"
"If a program supports multiple lasers, then options for additional lasers\n"
"after the first are given by appending the laser number (e.g. -laserType2)\n"
"To enable use of a laser, choose its type with the -laserType<N> options\n"
"(e.g.: -laserType lms2xx -laserType2 urg2.0)\n\n"
"The default laser type for the primary laser (laser 1) is specified in the\n"
"robot type parameter file in the ARIA \"params\" directory. For many robots\n"
"it is \"lms2xx\", the SICK LMS200. For some it is \"lms1xx\", for the SICK\n"
"LMS100 or LMS111.\n\n"
"Instruct a program to connect to a laser using the -connectLaser<N> option\n"
"or by setting LaserAutoConnect to true in the robot's parameter file.\n"
"If a program requires use of a laser it usually always attempts to connect to\n"
"the primary laser, however.\n\n"
"The index number is optional in any options for the primary laser; i.e. 1 is\n"
"assumed if the index number is omitted.\n\n"
);
// TODO loop through all laser registered with Aria class and instantiate
// them that way.
// lms 200
puts("\nFor laser type \"lms2xx\" (SICK LMS-200):\n");
addPlaceholderLaser(&lms2xxLaser, 1);
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// lms 100
puts("\nFor laser type \"lms1xx\" (SICK LMS-100, LMS-111, etc.):\n");
addPlaceholderLaser(&lms1xxLaser, 1); // replace lms2xx as first laser
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// urg2.0
puts("\nFor laser type \"urg2.0\" (URG with SCIP 2.0):\n");
addPlaceholderLaser(&urg2Laser, 1); // replace lms1xx as first laser
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// urg 1.0
puts("\nFor laser type \"urg\" (URG with old SCIP 1.0):\n");
addPlaceholderLaser(&urgLaser, 1); // replace urg2.0 as first laser
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// LMS500
puts("\nFor laser type \"lms5XX\" (SICK LMS-500):\n");
addPlaceholderLaser(&lms5xxLaser, 1); // replace previous
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// SZ
puts("\nFor laser type \"sZseries\" (Keyence SZ):\n");
addPlaceholderLaser(&szLaser, 1); // replace previous
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// S3xx
puts("\nFor laser type \"s3series\" (SICK S-300, S-3000, etc.):\n");
addPlaceholderLaser(&s3xxLaser, 1); // replace previous
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
// TiM3xx
puts("\nFor laser type \"tim3XX\" (SICK TiM300):\n");
addPlaceholderLaser(&tim3xxLaser, 1); // replace previous
ArLaserConnector::logLaserOptions(myLasers[1], false, false);
}
};
class ArGPSConnectorWrapper :
public ArGPSConnector,
public virtual Wrapper
{
public:
ArGPSConnectorWrapper(ArArgumentParser *argParser) :
ArGPSConnector(argParser)
{
}
virtual void logOptions()
{
ArGPSConnector::logOptions();
}
};
class ArCompassConnectorWrapper :
public ArCompassConnector,
public virtual Wrapper
{
public:
ArCompassConnectorWrapper(ArArgumentParser *argParser) :
ArCompassConnector(argParser)
{
}
virtual void logOptions()
{
ArCompassConnector::logOptions();
}
};
class ArSonarConnectorWrapper:
public ArSonarConnector,
public virtual Wrapper
{
public:
ArSonarConnectorWrapper(ArArgumentParser *argParser) :
ArSonarConnector(argParser, NULL, NULL)
{
}
virtual void logOptions()
{
ArSonarConnector::logOptions();
}
};
#endif
#ifdef FOR_ARNETWORKING
#include "ArNetworking.h"
class ArClientSimpleConnectorWrapper : public ArClientSimpleConnector, public virtual Wrapper
{
public:
ArClientSimpleConnectorWrapper(ArArgumentParser *argParser) : ArClientSimpleConnector(argParser)
{
}
virtual void logOptions()
{
ArClientSimpleConnector::logOptions();
}
};
class ArServerSimpleOpenerWrapper : public ArServerSimpleOpener, public virtual Wrapper
{
public:
ArServerSimpleOpenerWrapper(ArArgumentParser *argParser) : ArServerSimpleOpener(argParser)
{
}
virtual void logOptions()
{
ArServerSimpleOpener::logOptions();
}
};
class ArClientSwitchManagerWrapper : public ArClientSwitchManager, public virtual Wrapper
{
public:
ArClientSwitchManagerWrapper(ArServerBase *server, ArArgumentParser *argParser) : ArClientSwitchManager(server, argParser)
{
}
virtual void logOptions()
{
ArClientSwitchManager::logOptions();
}
};
#endif
const char *EXPLANATION =
"Some classes in ARIA and ArNetworking check a program's run time options to\n"
"specify parameters and options. These options are used to configure run time\n"
"accessory device parameters (ports, speeds, etc.) used by ARIA; host names,\n"
"port numbers, etc. used by ArNetworking; and various other run time options.\n"
"Options may be given as program arguments on the command line, or globally\n"
"saved as defaults in the file /etc/Aria.args if on Linux, or in the ARIAARGS\n"
"environment variable. Arguments given on the command line may override some\n"
"internal defaults or values read from the robot parameter files.\n\n"
"Note, an option will be available only in programs that instantiate an\n"
"object of the class that uses it. Some programs may also check for\n"
"program-specific command line options.\n\n"
"Use the special \"-help\" command line option to cause a program to \n"
"print out its available options.\n\n"
"A list of options used by each class follows.\n\n";
/* Redirect stdout to a file. If reopening stdout for the new file fails, print
* a message and exit the program with error code 3.
*/
void redirectStdout(const char *filename)
{
FILE *fp = freopen(filename, "w", stdout);
if(fp == NULL)
{
fprintf(stderr, "genCommandLineOptionDocs: Error opening \"%s\"! Exiting.\n", filename);
Aria::exit(3);
}
}
typedef std::pair<std::string, Wrapper*> WrapPair;
typedef std::vector<WrapPair> WrapList;
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser argParser(&argc, argv);
WrapList wrappers;
#ifdef FOR_ARIA
wrappers.push_back(WrapPair("ArRobotConnector", new ArRobotConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArLaserConnector", new ArLaserConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArPTZConnector", new ArPTZConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArGPSConnector", new ArGPSConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArCompassConnector", new ArCompassConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArSonarConnector", new ArSonarConnectorWrapper(&argParser)));
#endif
#ifdef FOR_ARNETWORKING
ArServerBase server;
wrappers.push_back(WrapPair("ArClientSimpleConnector", new ArClientSimpleConnectorWrapper(&argParser)));
wrappers.push_back(WrapPair("ArServerSimpleOpener", new ArServerSimpleOpenerWrapper(&argParser)));
wrappers.push_back(WrapPair("ArClientSwitchManager", new ArClientSwitchManagerWrapper(&server, &argParser)));
#endif
/* Write docs/options/all_options.dox */
// TODO process text to replace HTML characters with entities or formatting
// (especially < and >)
redirectStdout("docs/options/all_options.dox");
printf("/* This file was automatically generated by utils/genCommandLineOptionDocs.cpp. Do not modify or changes will be lost.*/\n\n"\
"/** @page CommandLineOptions Command Line Option Summary\n\n%s\n\n", EXPLANATION);
// TODO process text by turning it into a <dl> or similar: start new <dt> at
// beginning of line, add </dt><dd> at first \t, then add </dt> at end.
for(WrapList::const_iterator i = wrappers.begin(); i != wrappers.end(); ++i)
{
printf("@section %s\n\n(See %s for class documentation)\n\n<pre>", (*i).first.c_str(), (*i).first.c_str());
(*i).second->logOptions();
puts("</pre>\n");
fprintf(stderr, "genCommandLineOptionDocs: Added %s to docs/options/all_options.dox\n", (*i).first.c_str());
}
puts("*/");
fputs("genCommandLineOptionDocs: Wrote docs/options/all_options.dox\n", stderr);
/* Write docs/options/<class> */
for(WrapList::const_iterator i = wrappers.begin(); i != wrappers.end(); ++i)
{
std::string filename("docs/options/");
filename += (*i).first + "_options";
redirectStdout(filename.c_str());
(*i).second->logOptions();
fprintf(stderr, "genCommandLineOptionDocs: Wrote %s\n", filename.c_str());
}
/* Write CommandLineOptions.txt.in */
redirectStdout("CommandLineOptions.txt.in");
#ifdef FOR_ARIA
puts("\nARIA @ARIA_VERSION@\n");
#elif defined(FOR_ARNETWORKING)
puts("\nArNetworking @ARIA_VERSION@\n");
#endif
printf("Summary of command line options\n\n%s", EXPLANATION);
for(WrapList::const_iterator i = wrappers.begin(); i != wrappers.end(); ++i)
{
puts("");
puts((*i).first.c_str());
for(std::string::size_type c = 0; c < (*i).first.size(); ++c)
fputc('-', stdout);
puts("");
(*i).second->logOptions();
}
puts("\n");
fputs("genCommandLineOptionDocs: Wrote CommandLineOptions.txt.in\n", stderr);
Aria::exit(0);
}
|