mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:47:21 +08:00
tfmini: add argc check and fix argv index
This commit is contained in:
@@ -922,31 +922,32 @@ usage()
|
|||||||
int
|
int
|
||||||
tfmini_main(int argc, char *argv[])
|
tfmini_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// check for optional arguments
|
|
||||||
int ch;
|
int ch;
|
||||||
uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||||
const char *device_path = "";
|
const char *device_path = "";
|
||||||
int myoptind = 1;
|
int myoptind = 1;
|
||||||
const char *myoptarg = nullptr;
|
const char *myoptarg = nullptr;
|
||||||
|
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "R:d:", &myoptind, &myoptarg)) != EOF) {
|
while ((ch = px4_getopt(argc, argv, "R:d:", &myoptind, &myoptarg)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'R':
|
case 'R':
|
||||||
rotation = (uint8_t)atoi(myoptarg);
|
rotation = (uint8_t)atoi(myoptarg);
|
||||||
PX4_INFO("Setting distance sensor orientation to %d", (int)rotation);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
device_path = myoptarg;
|
device_path = myoptarg;
|
||||||
PX4_INFO("Using device path '%s'", device_path);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
PX4_WARN("Unknown option!");
|
PX4_WARN("Unknown option!");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myoptind >= argc) {
|
||||||
|
goto out_error;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
@@ -957,7 +958,7 @@ tfmini_main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
PX4_WARN("Please specify device path!");
|
PX4_WARN("Please specify device path!");
|
||||||
tfmini::usage();
|
tfmini::usage();
|
||||||
return PX4_ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -985,10 +986,11 @@ tfmini_main(int argc, char *argv[])
|
|||||||
/*
|
/*
|
||||||
* Print driver information.
|
* Print driver information.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[myoptind], "info") || !strcmp(argv[1], "status")) {
|
if (!strcmp(argv[myoptind], "info") || !strcmp(argv[myoptind], "status")) {
|
||||||
tfmini::info();
|
tfmini::info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_error:
|
||||||
PX4_ERR("unrecognized command, try 'start', 'test', 'reset' or 'info'");
|
PX4_ERR("unrecognized command, try 'start', 'test', 'reset' or 'info'");
|
||||||
return PX4_ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user