mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 16:53:33 +08:00
Sensors: Clean up boot output (#8005)
Various sensors had too verbose or confusing boot output that would make the boot log hard to read. This patch ensures all output is consistently indicating if there is a real error or an optional sensor just not present. It also removed redundant error messages and adds an indication on which bus the sensor was probed.
This commit is contained in:
committed by
Daniel Agar
parent
d04d62c37e
commit
a945cd9fc2
@@ -243,11 +243,11 @@ namespace ets_airspeed
|
||||
|
||||
ETSAirspeed *g_dev;
|
||||
|
||||
void start(int i2c_bus);
|
||||
void stop();
|
||||
void test();
|
||||
void reset();
|
||||
void info();
|
||||
int start(int i2c_bus);
|
||||
int stop();
|
||||
int test();
|
||||
int reset();
|
||||
int info();
|
||||
|
||||
/**
|
||||
* Start the driver.
|
||||
@@ -255,13 +255,14 @@ void info();
|
||||
* This function only returns if the sensor is up and running
|
||||
* or could not be detected successfully.
|
||||
*/
|
||||
void
|
||||
int
|
||||
start(int i2c_bus)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (g_dev != nullptr) {
|
||||
PX4_ERR("already started");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
/* create the driver */
|
||||
@@ -286,7 +287,7 @@ start(int i2c_bus)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return;
|
||||
return PX4_OK;
|
||||
|
||||
fail:
|
||||
|
||||
@@ -295,13 +296,14 @@ fail:
|
||||
g_dev = nullptr;
|
||||
}
|
||||
|
||||
PX4_WARN("no ETS airspeed sensor connected");
|
||||
PX4_WARN("no ETS airspeed sensor connected on bus %d", i2c_bus);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the driver
|
||||
*/
|
||||
void
|
||||
int
|
||||
stop()
|
||||
{
|
||||
if (g_dev != nullptr) {
|
||||
@@ -310,7 +312,10 @@ stop()
|
||||
|
||||
} else {
|
||||
PX4_ERR("driver not running");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,7 +323,7 @@ stop()
|
||||
* make sure we can collect data from the sensor in polled
|
||||
* and automatic modes.
|
||||
*/
|
||||
void
|
||||
int
|
||||
test()
|
||||
{
|
||||
struct differential_pressure_s report;
|
||||
@@ -329,6 +334,7 @@ test()
|
||||
|
||||
if (fd < 0) {
|
||||
PX4_ERR("%s open failed (try 'ets_airspeed start' if the driver is not running", ETS_PATH);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
/* do a simple demand read */
|
||||
@@ -336,6 +342,7 @@ test()
|
||||
|
||||
if (sz != sizeof(report)) {
|
||||
PX4_ERR("immediate read failed");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
PX4_INFO("single read");
|
||||
@@ -344,6 +351,7 @@ test()
|
||||
/* start the sensor polling at 2Hz */
|
||||
if (OK != px4_ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
|
||||
PX4_ERR("failed to set 2Hz poll rate");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
/* read the sensor 5x and report each value */
|
||||
@@ -373,44 +381,52 @@ test()
|
||||
/* reset the sensor polling to its default rate */
|
||||
if (OK != px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
|
||||
PX4_ERR("failed to set default rate");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
errx(0, "PASS");
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the driver.
|
||||
*/
|
||||
void
|
||||
int
|
||||
reset()
|
||||
{
|
||||
int fd = px4_open(ETS_PATH, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
PX4_ERR("failed ");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
||||
PX4_ERR("driver reset failed");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
||||
PX4_ERR("driver poll restart failed");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a little info about the driver.
|
||||
*/
|
||||
void
|
||||
int
|
||||
info()
|
||||
{
|
||||
if (g_dev == nullptr) {
|
||||
PX4_ERR("driver not running");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
PX4_INFO("state @ %p", g_dev);
|
||||
g_dev->print_info();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -445,35 +461,35 @@ ets_airspeed_main(int argc, char *argv[])
|
||||
* Start/load the driver.
|
||||
*/
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
ets_airspeed::start(i2c_bus);
|
||||
return ets_airspeed::start(i2c_bus);
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop the driver
|
||||
*/
|
||||
if (!strcmp(argv[1], "stop")) {
|
||||
ets_airspeed::stop();
|
||||
return ets_airspeed::stop();
|
||||
}
|
||||
|
||||
/*
|
||||
* Test the driver/device.
|
||||
*/
|
||||
if (!strcmp(argv[1], "test")) {
|
||||
ets_airspeed::test();
|
||||
return ets_airspeed::test();
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset the driver.
|
||||
*/
|
||||
if (!strcmp(argv[1], "reset")) {
|
||||
ets_airspeed::reset();
|
||||
return ets_airspeed::reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* Print driver information.
|
||||
*/
|
||||
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status")) {
|
||||
ets_airspeed::info();
|
||||
return ets_airspeed::info();
|
||||
}
|
||||
|
||||
ets_airspeed_usage();
|
||||
|
||||
Reference in New Issue
Block a user