mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 06:23:34 +08:00
sdp3x: add argc check and use px4_getopt
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "SDP3X.hpp"
|
#include "SDP3X.hpp"
|
||||||
|
#include <px4_getopt.h>
|
||||||
|
|
||||||
// Driver 'main' command.
|
// Driver 'main' command.
|
||||||
extern "C" __EXPORT int sdp3x_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int sdp3x_airspeed_main(int argc, char *argv[]);
|
||||||
@@ -164,36 +165,49 @@ sdp3x_airspeed_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
uint8_t i2c_bus = PX4_I2C_BUS_DEFAULT;
|
uint8_t i2c_bus = PX4_I2C_BUS_DEFAULT;
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
int myoptind = 1;
|
||||||
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
|
int ch;
|
||||||
if (argc > i + 1) {
|
const char *myoptarg = nullptr;
|
||||||
i2c_bus = atoi(argv[i + 1]);
|
|
||||||
}
|
while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'b':
|
||||||
|
i2c_bus = atoi(myoptarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sdp3x_airspeed_usage();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myoptind >= argc) {
|
||||||
|
sdp3x_airspeed_usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "start")) {
|
if (!strcmp(argv[myoptind], "start")) {
|
||||||
return sdp3x_airspeed::start(i2c_bus);
|
return sdp3x_airspeed::start(i2c_bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop the driver
|
* Stop the driver
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "stop")) {
|
if (!strcmp(argv[myoptind], "stop")) {
|
||||||
return sdp3x_airspeed::stop();
|
return sdp3x_airspeed::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset the driver.
|
* Reset the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "reset")) {
|
if (!strcmp(argv[myoptind], "reset")) {
|
||||||
return sdp3x_airspeed::reset();
|
return sdp3x_airspeed::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
sdp3x_airspeed_usage();
|
sdp3x_airspeed_usage();
|
||||||
|
return 0;
|
||||||
return PX4_OK;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user