CF/BF - Ensure that ESC voltage/current meters do not read random memory

when reading data from unconfigured motors.
This commit is contained in:
Hydra 2017-04-02 17:46:11 +01:00 committed by Dominic Clifton
parent 526c15521d
commit 1f4644557d
2 changed files with 9 additions and 4 deletions

View File

@ -220,11 +220,12 @@ void currentMeterESCReadMotor(uint8_t motorNumber, currentMeter_t *meter)
currentMeterReset(meter);
#else
escSensorData_t *escData = getEscSensorData(motorNumber);
if (escData->dataAge <= ESC_BATTERY_AGE_MAX) {
if (escData && escData->dataAge <= ESC_BATTERY_AGE_MAX) {
meter->amperage = escData->current;
meter->amperageLatest = escData->current;
meter->mAhDrawn = escData->consumption;
return;
} else {
currentMeterReset(meter);
}
#endif
}

View File

@ -221,9 +221,13 @@ void voltageMeterESCReadMotor(uint8_t motorNumber, voltageMeter_t *voltageMeter)
voltageMeterReset(voltageMeter);
#else
escSensorData_t *escData = getEscSensorData(motorNumber);
if (escData) {
voltageMeter->unfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0;
voltageMeter->filtered = voltageMeter->unfiltered; // no filtering for ESC motors currently.
} else {
voltageMeterReset(voltageMeter);
}
voltageMeter->unfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0;
voltageMeter->filtered = voltageMeter->unfiltered; // no filtering for ESC motors currently.
#endif
}