SITL: add sanity check for duplicate bus/addr I2C devices

This commit is contained in:
Peter Barker 2021-01-03 13:34:53 +11:00 committed by Peter Barker
parent ac69cfe2b3
commit 21ffa4d259

View File

@ -70,6 +70,19 @@ void I2C::init()
for (auto &i : i2c_devices) {
i.device.init();
}
// sanity check the i2c_devices structure to ensure we don't have
// two devices at the same address on the same bus:
for (uint8_t i=0; i<ARRAY_SIZE(i2c_devices)-1; i++) {
const auto &dev_i = i2c_devices[i];
for (uint8_t j=i+1; j<ARRAY_SIZE(i2c_devices); j++) {
const auto &dev_j = i2c_devices[j];
if (dev_i.bus == dev_j.bus &&
dev_i.addr == dev_j.addr) {
AP_HAL::panic("Two devices at the same address on the same bus");
}
}
}
}
void I2C::update(const class Aircraft &aircraft)