bmm150: add argc check and use px4_getopt

This commit is contained in:
Beat Küng
2018-06-04 14:31:02 +02:00
committed by Lorenz Meier
parent 009b2d4d6b
commit ffccba12e2
2 changed files with 14 additions and 8 deletions
+14 -7
View File
@@ -37,6 +37,7 @@
*/ */
#include "bmm150.hpp" #include "bmm150.hpp"
#include <px4_getopt.h>
/** driver 'main' command */ /** driver 'main' command */
extern "C" { __EXPORT int bmm150_main(int argc, char *argv[]); } extern "C" { __EXPORT int bmm150_main(int argc, char *argv[]); }
@@ -1128,28 +1129,34 @@ BMM150::print_registers()
int int
bmm150_main(int argc, char *argv[]) bmm150_main(int argc, char *argv[])
{ {
bool external_bus = false; int myoptind = 1;
int ch; int ch;
const char *myoptarg = nullptr;
bool external_bus = false;
enum Rotation rotation = ROTATION_NONE; enum Rotation rotation = ROTATION_NONE;
/* jump over start/off/etc and look at options first */ while ((ch = px4_getopt(argc, argv, "XR:", &myoptind, &myoptarg)) != EOF) {
while ((ch = getopt(argc, argv, "XR:")) != EOF) {
switch (ch) { switch (ch) {
case 'X': case 'X':
external_bus = true; external_bus = true;
break; break;
case 'R': case 'R':
rotation = (enum Rotation)atoi(optarg); rotation = (enum Rotation)atoi(myoptarg);
break; break;
default: default:
bmm150::usage(); bmm150::usage();
exit(0); return 0;
} }
} }
const char *verb = argv[optind]; if (myoptind >= argc) {
bmm150::usage();
return -1;
}
const char *verb = argv[myoptind];
/* /*
* Start/load the driver. * Start/load the driver.
@@ -1189,5 +1196,5 @@ bmm150_main(int argc, char *argv[])
bmm150::usage(); bmm150::usage();
exit(1); return -1;
} }
@@ -16,7 +16,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <px4_log.h> #include <px4_log.h>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>