From b83b588fc5359f43912a3b70db427e98364230f8 Mon Sep 17 00:00:00 2001 From: DanielePettenuzzo <daniele@px4.io> Date: Wed, 10 Oct 2018 14:04:56 +0200 Subject: [PATCH] irlock driver: fix bus selection argument (-b) --- src/drivers/irlock/irlock.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/drivers/irlock/irlock.cpp b/src/drivers/irlock/irlock.cpp index 8d4c5cfb87..f6eeb5d054 100644 --- a/src/drivers/irlock/irlock.cpp +++ b/src/drivers/irlock/irlock.cpp @@ -54,6 +54,8 @@ #include <drivers/drv_irlock.h> #include <drivers/drv_hrt.h> +#include <px4_getopt.h> + #include <nuttx/clock.h> #include <nuttx/wqueue.h> #include <systemlib/err.h> @@ -449,17 +451,28 @@ int irlock_main(int argc, char *argv[]) { int i2cdevice = IRLOCK_I2C_BUS; - /** jump over start/off/etc and look at options first **/ - if (getopt(argc, argv, "b:") != EOF) { - i2cdevice = (int)strtol(optarg, NULL, 0); + int ch; + int myoptind = 1; + const char *myoptarg = nullptr; + + while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) { + switch (ch) { + case 'b': + i2cdevice = (uint8_t)atoi(myoptarg); + break; + + default: + PX4_WARN("Unknown option!"); + return -1; + } } - if (optind >= argc) { + if (myoptind >= argc) { irlock_usage(); exit(1); } - const char *command = argv[optind]; + const char *command = argv[myoptind]; /** start driver **/ if (!strcmp(command, "start")) { -- GitLab