本文整理汇总了C++中OptionParser::executable方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionParser::executable方法的具体用法?C++ OptionParser::executable怎么用?C++ OptionParser::executable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionParser
的用法示例。
在下文中一共展示了OptionParser::executable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: boot
int
main(int argc, char** argv)
{
OptionParser options;
options.executable("lucb")
.program(DUNE_SHORT_NAME)
.copyright(DUNE_COPYRIGHT)
.email(DUNE_CONTACT)
.version(getFullVersion())
.date(getCompileDate())
.arch(DUNE_SYSTEM_NAME)
.description("Utility to update firmware of LUCL based devices.")
.add("-d", "--sys-device",
"System device", "DEVICE")
.add("-b", "--baud-rate",
"Baud rate", "BAUD")
.add("-i", "--i2c-address",
"I2C slave address", "I2C_ADDR")
.add("-f", "--file",
"iHEX file", "IHEX_FILE");
// Parse command line arguments.
if (!options.parse(argc, argv))
{
if (options.bad())
std::cerr << "ERROR: " << options.error() << std::endl;
options.usage();
return 1;
}
// Get iHEX file.
std::string ihex = options.value("--file");
if (ihex.empty())
{
std::cerr << "ERROR: you must specify one iHEX file." << std::endl;
return 1;
}
// Get system device.
std::string sys_dev = options.value("--sys-device");
if (sys_dev.empty())
{
std::cerr << "ERROR: you must specify one system device." << std::endl;
return 1;
}
// Get specified baud rate.
int baud = 0;
castLexical(options.value("--baud-rate"), baud);
// Get I2C address (if any).
bool is_i2c = false;
uint8_t i2c_addr = 0;
if (castLexical(options.value("--i2c-address"), i2c_addr))
{
if ((i2c_addr < 0x03) || (i2c_addr > 0x77))
{
std::cerr << "ERROR: I2C device address is out of range (0x03 - 0x77)" << std::endl;
return 1;
}
is_i2c = true;
}
LUCL::Protocol proto;
if (is_i2c)
proto.setI2C(sys_dev, i2c_addr);
else
proto.setUART(sys_dev);
try
{
LUCL::BootLoader boot(proto, true, baud);
boot.flash(ihex);
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
}
return 0;
}
示例2: if
int
main(int argc, char** argv)
{
OptionParser options;
options.executable(argv[0])
.program(DUNE_SHORT_NAME)
.copyright(DUNE_COPYRIGHT)
.email("Renato Caldas <[email protected]>")
.version(getFullVersion())
.date(getCompileDate())
.arch(DUNE_SYSTEM_NAME)
.description("Utility to update firmware of LUCL based devices.")
.add("-d", "--sys-device",
"System device", "DEVICE")
.add("-i", "--i2c-address",
"I2C slave address", "I2C_ADDR")
.add("-c", "--command",
"LUCL command", "CMD")
.add("-p", "--data-payload",
"LUCL data", "DATA0[,DATA1 ...]");
// Parse command line arguments.
if (!options.parse(argc, argv))
{
if (options.bad())
std::cerr << "ERROR: " << options.error() << std::endl;
options.usage();
return 1;
}
// Get system device.
std::string sys_dev = options.value("--sys-device");
if (sys_dev.empty())
{
std::cerr << "ERROR: you must specify one system device." << std::endl;
return 1;
}
// Get I2C address (if any).
bool is_i2c = false;
uint8_t i2c_addr = 0;
if (castLexical(options.value("--i2c-address"), i2c_addr))
{
if ((i2c_addr < 0x03) || (i2c_addr > 0x77))
{
std::cerr << "ERROR: I2C device address is out of range (0x03 - 0x77)" << std::endl;
return 1;
}
is_i2c = true;
}
// Open the device
LUCL::Protocol proto;
if (is_i2c)
proto.setI2C(sys_dev, i2c_addr);
else
proto.setUART(sys_dev);
try
{
proto.open();
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
// Check for the command token
std::string command = options.value("--command");
if (command.empty())
{
std::cerr << "ERROR: reading from stdio not supported yet." << std::endl;
return 1;
}
// Get the data payload
std::string data_str = options.value("--data-payload");
std::vector<uint8_t> data_lst;
if (!castLexical(data_str, data_lst))
{
std::cerr << "ERROR: failed to parse the data payload argument." << std::endl;
return 1;
}
// Build and send the packet
if (command.compare("Info") == 0)
{
std::cerr << "Requesting device information" << std::endl;
try
{
proto.requestVersion();
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
//.........这里部分代码省略.........
示例3: daemon
int
main(int argc, char** argv)
{
Tasks::Context context;
I18N::setLanguage(context.dir_i18n);
Scheduler::set(Scheduler::POLICY_RR);
OptionParser options;
options.executable("dune")
.program(DUNE_SHORT_NAME)
.copyright(DUNE_COPYRIGHT)
.email(DUNE_CONTACT)
.version(getFullVersion())
.date(getCompileDate())
.arch(DUNE_SYSTEM_NAME)
.add("-d", "--config-dir",
"Configuration directory", "DIR")
.add("-w", "--www-dir",
"HTTP server base directory", "DIR")
.add("-c", "--config-file",
"Load configuration file CONFIG", "CONFIG")
.add("-m", "--lock-memory",
"Lock memory")
.add("-p", "--profiles",
"Execution Profiles", "PROFILES")
.add("-V", "--vehicle",
"Vehicle name override", "VEHICLE")
.add("-X", "--dump-params-xml",
"Dump parameters XML to folder DIR", "DIR");
// Parse command line arguments.
if (!options.parse(argc, argv))
{
if (options.bad())
std::cerr << "ERROR: " << options.error() << std::endl;
options.usage();
return 1;
}
// If requested, lock memory.
if (!options.value("--lock-memory").empty())
{
#if defined(DUNE_USING_TLSF) && defined(DUNE_CLIB_GNU)
Resources::lockMemory(c_memory, c_memory_size);
#else
Resources::lockMemory();
#endif
}
// If requested, set alternate configuration directory.
if (options.value("--config-dir") != "")
{
context.dir_cfg = options.value("--config-dir");
}
// If requested, set alternate HTTP server directory.
if (options.value("--www-dir") != "")
{
context.dir_www = options.value("--www-dir");
}
DUNE::Tasks::Factory::registerDynamicTasks(context.dir_lib.c_str());
registerStaticTasks();
// Retrieve configuration file and try parsing it.
if (options.value("--config-file") == "")
{
std::cerr << String::str(DTR("ERROR: no configuration file was given, "
"see options --config-list and --config-file\n"))
<< std::endl;
return 1;
}
Path cfg_file = context.dir_cfg / options.value("--config-file") + ".ini";
try
{
context.config.parseFile(cfg_file.c_str());
}
catch (std::runtime_error& e)
{
try
{
cfg_file = context.dir_usr_cfg / options.value("--config-file") + ".ini";
context.config.parseFile(cfg_file.c_str());
context.dir_cfg = context.dir_usr_cfg;
}
catch (std::runtime_error& e2)
{
std::cerr << String::str("ERROR: %s\n", e.what()) << std::endl;
std::cerr << String::str("ERROR: %s\n", e2.what()) << std::endl;
return 1;
}
}
if (!options.value("--vehicle").empty())
context.config.set("General", "Vehicle", options.value("--vehicle"));
try
{
DUNE::Daemon daemon(context, options.value("--profiles"));
//.........这里部分代码省略.........
示例4: defined
int
main(int argc, char** argv)
{
OptionParser options;
options.executable("dune-test-tail")
.program(DUNE_SHORT_NAME)
.copyright(DUNE_COPYRIGHT)
.email(DUNE_CONTACT)
.version(getFullVersion())
.date(getCompileDate())
.arch(DUNE_SYSTEM_NAME)
.add("-i", "--address",
"Vehicle's IP address", "ADDRESS")
.add("-w", "--wait",
"Wait DELAY seconds before starting test", "DELAY")
.add("-d", "--duration",
"Test duration in seconds", "DURATION")
.add("-s", "--speed",
"Speed in percentage", "SPEED")
.add("-t", "--angle",
"Angle in degrees", "ANGLE");
// Parse command line arguments.
if (!options.parse(argc, argv))
{
if (options.bad())
std::cerr << "ERROR: " << options.error() << std::endl;
options.usage();
return 1;
}
// Set destination address.
if (options.value("--address") == "")
g_addr = "127.0.0.1";
else
g_addr = options.value("--address").c_str();
// Set start delay.
double sdelay = 0;
if (options.value("--wait") == "")
sdelay = 0;
else
sdelay = castLexical<double>(options.value("--wait"));
// Set duration.
double duration = 0;
if (options.value("--duration") == "")
duration = 0;
else
duration = castLexical<double>(options.value("--duration"));
// Set speed.
double speed = 0;
if (options.value("--speed") == "")
speed = 0;
else
{
speed = castLexical<double>(options.value("--speed"));
speed /= 100.0;
}
// Set Angle
double angle = 0;
if (options.value("--angle") == "")
angle = 0;
else
angle = castLexical<double>(options.value("--angle"));
// POSIX implementation.
#if defined(DUNE_SYS_HAS_SIGACTION)
struct sigaction actions;
std::memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_handler = handleTerminate;
sigaction(SIGALRM, &actions, 0);
sigaction(SIGHUP, &actions, 0);
sigaction(SIGINT, &actions, 0);
sigaction(SIGQUIT, &actions, 0);
sigaction(SIGTERM, &actions, 0);
sigaction(SIGCHLD, &actions, 0);
sigaction(SIGCONT, &actions, 0);
#endif
setThrust(0);
Delay::wait(sdelay);
setLog("mcrt_endurance");
Delay::wait(2.0);
double deadline = Clock::get() + duration;
setThrust(speed);
while ((Clock::get() < deadline) && !g_stop)
{
setFin(0, -angle);
setFin(1, -angle);
setFin(2, -angle);
setFin(3, -angle);
//.........这里部分代码省略.........
示例5: itf
int
main(int argc, char** argv)
{
OptionParser options;
options.executable(argv[0])
.program("DUNE UCTK Flash Programmer")
.copyright(DUNE_COPYRIGHT)
.email("Ricardo Martins <[email protected]>")
.version(getFullVersion())
.date(getCompileDate())
.arch(DUNE_SYSTEM_NAME)
.description("Utility to update the firmware of UCTK based devices.")
.add("-d", "--dev",
"System device", "DEVICE")
.add("-t", "--dev-type",
"System device type", "TYPE")
.add("-f", "--file",
"iHEX file", "IHEX_FILE");
// Parse command line arguments.
if (!options.parse(argc, argv))
{
if (options.bad())
std::cerr << "ERROR: " << options.error() << std::endl;
options.usage();
return 1;
}
// Get iHEX file.
std::string ihex = options.value("--file");
if (ihex.empty())
{
std::cerr << "ERROR: you must specify one iHEX file." << std::endl;
return 1;
}
if (Path(ihex).type() != Path::PT_FILE)
{
std::cerr << "ERROR: no such file: '" << ihex << "'" << std::endl;
return 1;
}
// Get system device.
std::string sys_dev = options.value("--dev");
if (sys_dev.empty())
{
std::cerr << "ERROR: you must specify one system device." << std::endl;
return 1;
}
// Get device type.
IO::Handle* handle = NULL;
std::string dev_type = options.value("--dev-type");
if (dev_type == "escc")
handle = new ESCC(sys_dev);
else
handle = new SerialPort(sys_dev, c_baud_rate);
UCTK::Interface itf(handle);
UCTK::Bootloader* boot = new UCTK::Bootloader(&itf, true);
boot->program(ihex);
delete boot;
delete handle;
return 0;
}