Skip to content

Commit

Permalink
Sensors: Clean up boot output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LorenzMeier committed Sep 24, 2017
1 parent 13e64d0 commit 92618c0
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 95 deletions.
1 change: 0 additions & 1 deletion src/drivers/bmi055/bmi055_accel.cpp
Expand Up @@ -79,7 +79,6 @@ BMI055_accel::init()

/* if probe/setup failed, bail now */
if (ret != OK) {
warnx("SPI error");
DEVICE_DEBUG("SPI setup failed");
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/bmi055/bmi055_gyro.cpp
Expand Up @@ -184,7 +184,7 @@ BMI055_gyro::probe()
return OK;
}

PX4_ERR("unexpected whoami 0x%02x", _whoami);
DEVICE_DEBUG("unexpected whoami 0x%02x", _whoami);
return -EIO;
}

Expand Down
8 changes: 5 additions & 3 deletions src/drivers/bmi055/bmi055_main.cpp
Expand Up @@ -133,7 +133,7 @@ start(bool external_bus, enum Rotation rotation, enum sensor_type sensor)
close(fd_gyr);
}

exit(0);
exit(PX4_OK);

fail_accel:

Expand All @@ -142,7 +142,8 @@ start(bool external_bus, enum Rotation rotation, enum sensor_type sensor)
*g_dev_acc_ptr = nullptr;
}

errx(1, "bmi055 accel driver start failed");
PX4_WARN("No BMI055 accel found");
exit(PX4_ERROR);

fail_gyro:

Expand All @@ -151,7 +152,8 @@ start(bool external_bus, enum Rotation rotation, enum sensor_type sensor)
*g_dev_gyr_ptr = nullptr;
}

errx(1, "bmi055 gyro driver start failed");
PX4_WARN("No BMI055 gyro found");
exit(PX4_ERROR);

}

Expand Down
52 changes: 34 additions & 18 deletions src/drivers/ets_airspeed/ets_airspeed.cpp
Expand Up @@ -243,25 +243,26 @@ 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.
*
* 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 */
Expand All @@ -286,7 +287,7 @@ start(int i2c_bus)
goto fail;
}

return;
return PX4_OK;

fail:

Expand All @@ -295,13 +296,14 @@ start(int i2c_bus)
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) {
Expand All @@ -310,15 +312,18 @@ stop()

} else {
PX4_ERR("driver not running");
return PX4_ERROR;
}

return PX4_OK;
}

/**
* Perform some basic functional tests on the driver;
* make sure we can collect data from the sensor in polled
* and automatic modes.
*/
void
int
test()
{
struct differential_pressure_s report;
Expand All @@ -329,13 +334,15 @@ 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 */
sz = px4_read(fd, &report, sizeof(report));

if (sz != sizeof(report)) {
PX4_ERR("immediate read failed");
return PX4_ERROR;
}

PX4_INFO("single read");
Expand All @@ -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 */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 92618c0

Please sign in to comment.