fix(radio): limit number of consecutive retries when writing SD card data (#5929)

This commit is contained in:
philmoz
2025-02-20 21:33:10 +10:00
committed by GitHub
parent eea03e52af
commit e22088f099
+51 -22
View File
@@ -80,41 +80,70 @@ void storageCheck(bool immediately)
// Don't write anything to SD card if in EM
if (UNEXPECTED_SHUTDOWN()) return;
static constexpr uint8_t retryLimit = 10;
static uint8_t retryRadioCount = 0;
if (storageDirtyMsk & EE_GENERAL) {
TRACE("eeprom write general");
const char * error = writeGeneralSettings();
if (error) {
TRACE("writeGeneralSettings error=%s", error);
}
else {
storageDirtyMsk &= ~EE_GENERAL;
if (retryRadioCount < retryLimit) {
TRACE("SD card write radio settings");
const char * error = writeGeneralSettings();
if (error) {
TRACE("writeGeneralSettings error=%s", error);
retryRadioCount += 1;
} else {
storageDirtyMsk &= ~EE_GENERAL;
retryRadioCount = 0;
}
} else {
// Reset timeout to next check
storageDirtyTime10ms = get_tmr10ms();
retryRadioCount = retryLimit / 2; // Retry again after timeout; but fewer times
// TODO: provide some mechanism to alert user that SD card has serious error
}
}
#if defined(STORAGE_MODELSLIST)
static uint8_t retryLabelsCount = 0;
if (storageDirtyMsk & EE_LABELS) {
TRACE("SD card write labels");
const char * error = modelslist.save();
if (error) {
TRACE("writeLabels error=%s", error);
}
else {
storageDirtyMsk &= ~EE_LABELS;
if (retryLabelsCount < retryLimit) {
TRACE("SD card write labels");
const char * error = modelslist.save();
if (error) {
TRACE("writeLabels error=%s", error);
retryLabelsCount += 1;
} else {
storageDirtyMsk &= ~EE_LABELS;
retryLabelsCount = 0;
}
} else {
// Reset timeout to next check
storageDirtyTime10ms = get_tmr10ms();
retryLabelsCount = retryLimit / 2; // Retry again after timeout; but fewer times
// TODO: provide some mechanism to alert user that SD card has serious error
}
}
#endif
static uint8_t retryModelCount = 0;
if (storageDirtyMsk & EE_MODEL) {
TRACE("eeprom write model");
const char * error = writeModel();
if (retryModelCount < retryLimit) {
TRACE("SD card write model settings");
const char * error = writeModel();
#if defined(STORAGE_MODELSLIST)
modelslist.updateCurrentModelCell();
modelslist.updateCurrentModelCell();
#endif
if (error) {
TRACE("writeModel error=%s", error);
}
else {
storageDirtyMsk &= ~EE_MODEL;
if (error) {
TRACE("writeModel error=%s", error);
retryModelCount += 1;
} else {
storageDirtyMsk &= ~EE_MODEL;
retryModelCount = 0;
}
} else {
// Reset timeout to next check
storageDirtyTime10ms = get_tmr10ms();
retryModelCount = retryLimit / 2; // Retry again after timeout; but fewer times
// TODO: provide some mechanism to alert user that SD card has serious error
}
}
}