mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 04:33:34 +08:00
bmi160: add argc check and use px4_getopt
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "bmi160.hpp"
|
#include "bmi160.hpp"
|
||||||
|
|
||||||
#include <board_config.h>
|
#include <board_config.h>
|
||||||
|
#include <px4_getopt.h>
|
||||||
|
|
||||||
/** driver 'main' command */
|
/** driver 'main' command */
|
||||||
extern "C" { __EXPORT int bmi160_main(int argc, char *argv[]); }
|
extern "C" { __EXPORT int bmi160_main(int argc, char *argv[]); }
|
||||||
@@ -271,32 +272,37 @@ usage()
|
|||||||
int
|
int
|
||||||
bmi160_main(int argc, char *argv[])
|
bmi160_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:
|
||||||
bmi160::usage();
|
bmi160::usage();
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *verb = argv[optind];
|
if (myoptind >= argc) {
|
||||||
|
bmi160::usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *verb = argv[myoptind];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if (!strcmp(verb, "start")) {
|
if (!strcmp(verb, "start")) {
|
||||||
bmi160::start(external_bus, rotation);
|
bmi160::start(external_bus, rotation);
|
||||||
@@ -339,5 +345,5 @@ bmi160_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
bmi160::usage();
|
bmi160::usage();
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user