Skip to content

Commit 5436ac5

Browse files
committed
AP_Baro: read data from BMP581 twice, reject if not identical
reports of corruption on this device
1 parent d6f64da commit 5436ac5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

libraries/AP_Baro/AP_Baro_BMP581.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,20 @@ bool AP_Baro_BMP581::init()
146146
void AP_Baro_BMP581::timer(void)
147147
{
148148
uint8_t buf[6];
149+
uint8_t buf2[6];
149150

151+
// read twice, make sure results are consistent; corruption has
152+
// been seen from data on this sensor
150153
if (!_dev->read_registers(BMP581_REG_TEMP_DATA_XLSB, buf, sizeof(buf))) {
151154
return;
152155
}
156+
if (!_dev->read_registers(BMP581_REG_TEMP_DATA_XLSB, buf2, sizeof(buf2))) {
157+
return;
158+
}
159+
if (memcmp(buf, buf2, ARRAY_SIZE(buf)) != 0) {
160+
// we didn't get the same data twice. Reject.
161+
return;
162+
}
153163

154164
WITH_SEMAPHORE(_sem);
155165

0 commit comments

Comments
 (0)