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 // Don't write anything to SD card if in EM
if (UNEXPECTED_SHUTDOWN()) return; if (UNEXPECTED_SHUTDOWN()) return;
static constexpr uint8_t retryLimit = 10;
static uint8_t retryRadioCount = 0;
if (storageDirtyMsk & EE_GENERAL) { if (storageDirtyMsk & EE_GENERAL) {
TRACE("eeprom write general"); if (retryRadioCount < retryLimit) {
const char * error = writeGeneralSettings(); TRACE("SD card write radio settings");
if (error) { const char * error = writeGeneralSettings();
TRACE("writeGeneralSettings error=%s", error); if (error) {
} TRACE("writeGeneralSettings error=%s", error);
else { retryRadioCount += 1;
storageDirtyMsk &= ~EE_GENERAL; } 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) #if defined(STORAGE_MODELSLIST)
static uint8_t retryLabelsCount = 0;
if (storageDirtyMsk & EE_LABELS) { if (storageDirtyMsk & EE_LABELS) {
TRACE("SD card write labels"); if (retryLabelsCount < retryLimit) {
const char * error = modelslist.save(); TRACE("SD card write labels");
if (error) { const char * error = modelslist.save();
TRACE("writeLabels error=%s", error); if (error) {
} TRACE("writeLabels error=%s", error);
else { retryLabelsCount += 1;
storageDirtyMsk &= ~EE_LABELS; } 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 #endif
static uint8_t retryModelCount = 0;
if (storageDirtyMsk & EE_MODEL) { if (storageDirtyMsk & EE_MODEL) {
TRACE("eeprom write model"); if (retryModelCount < retryLimit) {
const char * error = writeModel(); TRACE("SD card write model settings");
const char * error = writeModel();
#if defined(STORAGE_MODELSLIST) #if defined(STORAGE_MODELSLIST)
modelslist.updateCurrentModelCell(); modelslist.updateCurrentModelCell();
#endif #endif
if (error) { if (error) {
TRACE("writeModel error=%s", error); TRACE("writeModel error=%s", error);
} retryModelCount += 1;
else { } else {
storageDirtyMsk &= ~EE_MODEL; 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
} }
} }
} }