Browse Source

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

c415-sdk
Peter Barker 4 years ago committed by Peter Barker
parent
commit
21ffa4d259
  1. 13
      libraries/SITL/SIM_I2C.cpp

13
libraries/SITL/SIM_I2C.cpp

@ -70,6 +70,19 @@ void I2C::init()
for (auto &i : i2c_devices) { for (auto &i : i2c_devices) {
i.device.init(); 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) void I2C::update(const class Aircraft &aircraft)

Loading…
Cancel
Save