mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 15:28:53 +08:00
mpu6000: add argc check and use px4_getopt
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
@@ -2590,14 +2590,16 @@ usage()
|
||||
int
|
||||
mpu6000_main(int argc, char *argv[])
|
||||
{
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
enum MPU6000_BUS busid = MPU6000_BUS_ALL;
|
||||
int device_type = MPU_DEVICE_TYPE_MPU6000;
|
||||
int ch;
|
||||
enum Rotation rotation = ROTATION_NONE;
|
||||
int accel_range = MPU6000_ACCEL_DEFAULT_RANGE_G;
|
||||
|
||||
/* jump over start/off/etc and look at options first */
|
||||
while ((ch = getopt(argc, argv, "T:XISsZzR:a:")) != EOF) {
|
||||
while ((ch = px4_getopt(argc, argv, "T:XISsZzR:a:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'X':
|
||||
busid = MPU6000_BUS_I2C_EXTERNAL;
|
||||
@@ -2624,28 +2626,32 @@ mpu6000_main(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
device_type = atoi(optarg);
|
||||
device_type = atoi(myoptarg);
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
rotation = (enum Rotation)atoi(optarg);
|
||||
rotation = (enum Rotation)atoi(myoptarg);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
accel_range = atoi(optarg);
|
||||
accel_range = atoi(myoptarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
mpu6000::usage();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = argv[optind];
|
||||
if (myoptind >= argc) {
|
||||
mpu6000::usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
/*
|
||||
* Start/load the driver.
|
||||
|
||||
*/
|
||||
if (!strcmp(verb, "start")) {
|
||||
mpu6000::start(busid, rotation, accel_range, device_type);
|
||||
@@ -2692,5 +2698,5 @@ mpu6000_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
mpu6000::usage();
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user