mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 01:13:35 +08:00
Airspeed ETS: fix code style
This commit is contained in:
@@ -94,7 +94,7 @@
|
|||||||
class ETSAirspeed : public Airspeed
|
class ETSAirspeed : public Airspeed
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ETSAirspeed(int bus, int address = I2C_ADDRESS, const char* path = ETS_PATH);
|
ETSAirspeed(int bus, int address = I2C_ADDRESS, const char *path = ETS_PATH);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -113,8 +113,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
extern "C" __EXPORT int ets_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int ets_airspeed_main(int argc, char *argv[]);
|
||||||
|
|
||||||
ETSAirspeed::ETSAirspeed(int bus, int address, const char* path) : Airspeed(bus, address,
|
ETSAirspeed::ETSAirspeed(int bus, int address, const char *path) : Airspeed(bus, address,
|
||||||
CONVERSION_INTERVAL, path)
|
CONVERSION_INTERVAL, path)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,8 @@ ETSAirspeed::collect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t diff_pres_pa_raw = val[1] << 8 | val[0];
|
uint16_t diff_pres_pa_raw = val[1] << 8 | val[0];
|
||||||
if (diff_pres_pa_raw == 0) {
|
|
||||||
|
if (diff_pres_pa_raw == 0) {
|
||||||
// a zero value means the pressure sensor cannot give us a
|
// a zero value means the pressure sensor cannot give us a
|
||||||
// value. We need to return, and not report a value or the
|
// value. We need to return, and not report a value or the
|
||||||
// caller could end up using this value as part of an
|
// caller could end up using this value as part of an
|
||||||
@@ -163,7 +164,7 @@ ETSAirspeed::collect()
|
|||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
log("zero value from sensor");
|
log("zero value from sensor");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The raw value still should be compensated for the known offset
|
// The raw value still should be compensated for the known offset
|
||||||
diff_pres_pa_raw -= _diff_pres_offset;
|
diff_pres_pa_raw -= _diff_pres_offset;
|
||||||
@@ -175,7 +176,7 @@ ETSAirspeed::collect()
|
|||||||
|
|
||||||
differential_pressure_s report;
|
differential_pressure_s report;
|
||||||
report.timestamp = hrt_absolute_time();
|
report.timestamp = hrt_absolute_time();
|
||||||
report.error_count = perf_event_count(_comms_errors);
|
report.error_count = perf_event_count(_comms_errors);
|
||||||
|
|
||||||
// XXX we may want to smooth out the readings to remove noise.
|
// XXX we may want to smooth out the readings to remove noise.
|
||||||
report.differential_pressure_filtered_pa = diff_pres_pa_raw;
|
report.differential_pressure_filtered_pa = diff_pres_pa_raw;
|
||||||
@@ -210,6 +211,7 @@ ETSAirspeed::cycle()
|
|||||||
|
|
||||||
/* perform collection */
|
/* perform collection */
|
||||||
ret = collect();
|
ret = collect();
|
||||||
|
|
||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
/* restart the measurement state machine */
|
/* restart the measurement state machine */
|
||||||
@@ -239,6 +241,7 @@ ETSAirspeed::cycle()
|
|||||||
|
|
||||||
/* measurement phase */
|
/* measurement phase */
|
||||||
ret = measure();
|
ret = measure();
|
||||||
|
|
||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
debug("measure error");
|
debug("measure error");
|
||||||
}
|
}
|
||||||
@@ -287,26 +290,31 @@ start(int i2c_bus)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (g_dev != nullptr)
|
if (g_dev != nullptr) {
|
||||||
errx(1, "already started");
|
errx(1, "already started");
|
||||||
|
}
|
||||||
|
|
||||||
/* create the driver */
|
/* create the driver */
|
||||||
g_dev = new ETSAirspeed(i2c_bus);
|
g_dev = new ETSAirspeed(i2c_bus);
|
||||||
|
|
||||||
if (g_dev == nullptr)
|
if (g_dev == nullptr) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (OK != g_dev->Airspeed::init())
|
if (OK != g_dev->Airspeed::init()) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
/* set the poll rate to default, starts automatic data collection */
|
||||||
fd = open(AIRSPEED0_DEVICE_PATH, O_RDONLY);
|
fd = open(AIRSPEED0_DEVICE_PATH, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
|
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
@@ -351,21 +359,24 @@ test()
|
|||||||
|
|
||||||
int fd = open(ETS_PATH, O_RDONLY);
|
int fd = open(ETS_PATH, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
err(1, "%s open failed (try 'ets_airspeed start' if the driver is not running", ETS_PATH);
|
err(1, "%s open failed (try 'ets_airspeed start' if the driver is not running", ETS_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
/* do a simple demand read */
|
/* do a simple demand read */
|
||||||
sz = read(fd, &report, sizeof(report));
|
sz = read(fd, &report, sizeof(report));
|
||||||
|
|
||||||
if (sz != sizeof(report))
|
if (sz != sizeof(report)) {
|
||||||
err(1, "immediate read failed");
|
err(1, "immediate read failed");
|
||||||
|
}
|
||||||
|
|
||||||
warnx("single read");
|
warnx("single read");
|
||||||
warnx("diff pressure: %f pa", (double)report.differential_pressure_filtered_pa);
|
warnx("diff pressure: %f pa", (double)report.differential_pressure_filtered_pa);
|
||||||
|
|
||||||
/* start the sensor polling at 2Hz */
|
/* start the sensor polling at 2Hz */
|
||||||
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2))
|
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
|
||||||
errx(1, "failed to set 2Hz poll rate");
|
errx(1, "failed to set 2Hz poll rate");
|
||||||
|
}
|
||||||
|
|
||||||
/* read the sensor 5x and report each value */
|
/* read the sensor 5x and report each value */
|
||||||
for (unsigned i = 0; i < 5; i++) {
|
for (unsigned i = 0; i < 5; i++) {
|
||||||
@@ -376,22 +387,25 @@ test()
|
|||||||
fds.events = POLLIN;
|
fds.events = POLLIN;
|
||||||
ret = poll(&fds, 1, 2000);
|
ret = poll(&fds, 1, 2000);
|
||||||
|
|
||||||
if (ret != 1)
|
if (ret != 1) {
|
||||||
errx(1, "timed out waiting for sensor data");
|
errx(1, "timed out waiting for sensor data");
|
||||||
|
}
|
||||||
|
|
||||||
/* now go get it */
|
/* now go get it */
|
||||||
sz = read(fd, &report, sizeof(report));
|
sz = read(fd, &report, sizeof(report));
|
||||||
|
|
||||||
if (sz != sizeof(report))
|
if (sz != sizeof(report)) {
|
||||||
err(1, "periodic read failed");
|
err(1, "periodic read failed");
|
||||||
|
}
|
||||||
|
|
||||||
warnx("periodic read %u", i);
|
warnx("periodic read %u", i);
|
||||||
warnx("diff pressure: %f pa", (double)report.differential_pressure_filtered_pa);
|
warnx("diff pressure: %f pa", (double)report.differential_pressure_filtered_pa);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset the sensor polling to its default rate */
|
/* reset the sensor polling to its default rate */
|
||||||
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT))
|
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
|
||||||
errx(1, "failed to set default rate");
|
errx(1, "failed to set default rate");
|
||||||
|
}
|
||||||
|
|
||||||
errx(0, "PASS");
|
errx(0, "PASS");
|
||||||
}
|
}
|
||||||
@@ -404,14 +418,17 @@ reset()
|
|||||||
{
|
{
|
||||||
int fd = open(ETS_PATH, O_RDONLY);
|
int fd = open(ETS_PATH, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
err(1, "failed ");
|
err(1, "failed ");
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SENSORIOCRESET, 0) < 0)
|
if (ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
||||||
err(1, "driver reset failed");
|
err(1, "driver reset failed");
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
|
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
||||||
err(1, "driver poll restart failed");
|
err(1, "driver poll restart failed");
|
||||||
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@@ -422,8 +439,9 @@ reset()
|
|||||||
void
|
void
|
||||||
info()
|
info()
|
||||||
{
|
{
|
||||||
if (g_dev == nullptr)
|
if (g_dev == nullptr) {
|
||||||
errx(1, "driver not running");
|
errx(1, "driver not running");
|
||||||
|
}
|
||||||
|
|
||||||
printf("state @ %p\n", g_dev);
|
printf("state @ %p\n", g_dev);
|
||||||
g_dev->print_info();
|
g_dev->print_info();
|
||||||
@@ -462,32 +480,37 @@ ets_airspeed_main(int argc, char *argv[])
|
|||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "start"))
|
if (!strcmp(argv[1], "start")) {
|
||||||
ets_airspeed::start(i2c_bus);
|
ets_airspeed::start(i2c_bus);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop the driver
|
* Stop the driver
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "stop"))
|
if (!strcmp(argv[1], "stop")) {
|
||||||
ets_airspeed::stop();
|
ets_airspeed::stop();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test the driver/device.
|
* Test the driver/device.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "test"))
|
if (!strcmp(argv[1], "test")) {
|
||||||
ets_airspeed::test();
|
ets_airspeed::test();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset the driver.
|
* Reset the driver.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "reset"))
|
if (!strcmp(argv[1], "reset")) {
|
||||||
ets_airspeed::reset();
|
ets_airspeed::reset();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print driver information.
|
* Print driver information.
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status"))
|
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status")) {
|
||||||
ets_airspeed::info();
|
ets_airspeed::info();
|
||||||
|
}
|
||||||
|
|
||||||
ets_airspeed_usage();
|
ets_airspeed_usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user