mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 10:26:52 +08:00
ms4525: add argc check and use px4_getopt
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
#include <px4_getopt.h>
|
||||||
|
|
||||||
#include <drivers/device/i2c.h>
|
#include <drivers/device/i2c.h>
|
||||||
|
|
||||||
@@ -493,38 +494,48 @@ ms4525_airspeed_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int i2c_bus = PX4_I2C_BUS_DEFAULT;
|
int i2c_bus = PX4_I2C_BUS_DEFAULT;
|
||||||
|
|
||||||
int i;
|
int myoptind = 1;
|
||||||
|
int ch;
|
||||||
|
const char *myoptarg = nullptr;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) {
|
||||||
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
|
switch (ch) {
|
||||||
if (argc > i + 1) {
|
case 'b':
|
||||||
i2c_bus = atoi(argv[i + 1]);
|
i2c_bus = atoi(myoptarg);
|
||||||
}
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
meas_airspeed_usage();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myoptind >= argc) {
|
||||||
|
meas_airspeed_usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "start")) {
|
if (!strcmp(argv[myoptind], "start")) {
|
||||||
return meas_airspeed::start(i2c_bus);
|
return meas_airspeed::start(i2c_bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop the driver
|
* Stop the driver
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "stop")) {
|
if (!strcmp(argv[myoptind], "stop")) {
|
||||||
return meas_airspeed::stop();
|
return meas_airspeed::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset the driver.
|
* Reset the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "reset")) {
|
if (!strcmp(argv[myoptind], "reset")) {
|
||||||
return meas_airspeed::reset();
|
return meas_airspeed::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
meas_airspeed_usage();
|
meas_airspeed_usage();
|
||||||
|
return 0;
|
||||||
return PX4_OK;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user