mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
fix(drivers/differential_pressure/auav): validate full status byte
Compare the complete status byte against the value the datasheet specifies for a completed reading without error (0x40 absolute, 0x50 differential). Signed-off-by: Marin Doetterer <marin@auterion.com>
This commit is contained in:
1 parent
2a0c1142a0
commit
1ad1d0cef7
6 files changed
+27
-9
No files matched your search
@@ -59,11 +59,12 @@ I2CSPIDriverBase *AUAV::instantiate(const I2CSPIDriverConfig &config, const int
|
||||
return instance;
|
||||
}
|
||||
|
||||
AUAV::AUAV(const I2CSPIDriverConfig &config) :
|
||||
AUAV::AUAV(const I2CSPIDriverConfig &config, const uint8_t status_byte_expected) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors")),
|
||||
_status_byte(status_byte_expected)
|
||||
{
|
||||
I2C::_retries = 5;
|
||||
}
|
||||
@@ -124,8 +125,8 @@ int AUAV::probe()
|
||||
res_data = 0;
|
||||
int status = transfer(nullptr, 0, &res_data, 1);
|
||||
|
||||
/* Check that the sensor is active. Reported in bit 6 of the status byte */
|
||||
if (status == PX4_OK && (res_data & 0x40)) {
|
||||
/* Check that the sensor is powered on, error free and of the expected type (mode bits) */
|
||||
if (status == PX4_OK && res_data == _status_byte) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
@@ -201,8 +202,8 @@ void AUAV::handle_state_gather_measurement()
|
||||
uint8_t res_data[7];
|
||||
int status = transfer(nullptr, 0, res_data, sizeof(res_data));
|
||||
|
||||
/* Continue processing if the transfer was a success and bit 5 of the status is set to 0 (indicating the sensor is finished) */
|
||||
if (status == PX4_OK && (res_data[0] & 0x20) == 0) {
|
||||
/* Continue processing if the transfer was a success and the status is as expected (powered on, not busy, no errors) */
|
||||
if (status == PX4_OK && res_data[0] == _status_byte) {
|
||||
const hrt_abstime timestamp_sample = hrt_absolute_time();
|
||||
|
||||
const uint32_t pressure_raw = (res_data[1] << 16) | (res_data[2] << 8) | (res_data[3]);
|
||||
|
||||
@@ -49,7 +49,7 @@ static constexpr uint32_t I2C_SPEED = 100 * 1000; // 100 kHz I2C serial interfac
|
||||
class AUAV : public device::I2C, public I2CSPIDriver<AUAV>
|
||||
{
|
||||
public:
|
||||
explicit AUAV(const I2CSPIDriverConfig &config);
|
||||
explicit AUAV(const I2CSPIDriverConfig &config, const uint8_t status_byte_expected);
|
||||
virtual ~AUAV();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, const int runtime_instance);
|
||||
@@ -126,6 +126,18 @@ protected:
|
||||
perf_counter_t _sample_perf;
|
||||
perf_counter_t _comms_errors;
|
||||
|
||||
/*
|
||||
* Expected status byte of a healthy, idle sensor. Must match exactly.
|
||||
* bit 0: ALU error (0 = ok)
|
||||
* bit 1: reserved (0)
|
||||
* bit 2: memory error (0 = ok)
|
||||
* bit 3-4: mode (differential: 0x10, absolute: 0x00)
|
||||
* bit 5: busy (0 = measurement ready)
|
||||
* bit 6: power on (1)
|
||||
* bit 7: reserved (0)
|
||||
*/
|
||||
const uint8_t _status_byte;
|
||||
|
||||
private:
|
||||
int probe() override;
|
||||
};
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "AUAV_Absolute.hpp"
|
||||
|
||||
AUAV_Absolute::AUAV_Absolute(const I2CSPIDriverConfig &config) :
|
||||
AUAV(config),
|
||||
AUAV(config, STATUS_BYTE_ABS),
|
||||
_baro_external(config.external)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ static_assert(ABS_CONVERSION_INTERVAL >= 7000, "Conversion interval is too fast"
|
||||
/* Conversions */
|
||||
static constexpr float MBAR_TO_PA = 100.0f;
|
||||
|
||||
/* Status byte of a completed reading without error */
|
||||
static constexpr uint8_t STATUS_BYTE_ABS = 0x40;
|
||||
|
||||
class AUAV_Absolute : public AUAV
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <cctype>
|
||||
|
||||
AUAV_Differential::AUAV_Differential(const I2CSPIDriverConfig &config) :
|
||||
AUAV(config)
|
||||
AUAV(config, STATUS_BYTE_DIFF)
|
||||
{
|
||||
/* Initialize cal_range from parameter as fallback value */
|
||||
int32_t hw_model = 0;
|
||||
|
||||
@@ -55,6 +55,8 @@ static constexpr int64_t DIFF_CONVERSION_INTERVAL = (1000000 / DIFF_MEAS_RATE);
|
||||
/* reading too fast can yield all zero data -> incorrect sensor reading */
|
||||
static_assert(DIFF_CONVERSION_INTERVAL >= 7000, "Conversion interval is too fast");
|
||||
|
||||
static constexpr uint8_t STATUS_BYTE_DIFF = 0x50;
|
||||
|
||||
/* Valid AUAV types */
|
||||
static constexpr int32_t AUAV_LD_05 = 5;
|
||||
static constexpr int32_t AUAV_LD_10 = 10;
|
||||
|
||||
Reference in new issue
Block a user