Skip to content

Commit

Permalink
Limit the number of consecutive retries when writing SD card data.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Feb 20, 2025
1 parent b4bf1eb commit 6591032
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions radio/src/storage/sdcard_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,61 @@ void storageCheck(bool immediately)
// Don't write anything to SD card if in EM
if (UNEXPECTED_SHUTDOWN()) return;

if (storageDirtyMsk & EE_GENERAL) {
TRACE("eeprom write general");
const char * error = writeGeneralSettings();
if (error) {
TRACE("writeGeneralSettings error=%s", error);
}
else {
storageDirtyMsk &= ~EE_GENERAL;
static constexpr uint8_t retryLimit = 10;

static uint8_t retryRadioCount = 0;
// TODO: provide some mechanism to alert user that SD card has serious error
if (retryRadioCount < retryLimit) {
if (storageDirtyMsk & EE_GENERAL) {
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;
}
}
}

#if defined(STORAGE_MODELSLIST)
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;
static uint8_t retryLabelsCount = 0;
// TODO: provide some mechanism to alert user that SD card has serious error
if (retryLabelsCount < retryLimit) {
if (storageDirtyMsk & EE_LABELS) {
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;
}
}
}
#endif

if (storageDirtyMsk & EE_MODEL) {
TRACE("eeprom write model");
const char * error = writeModel();
static uint8_t retryModelCount = 0;
// TODO: provide some mechanism to alert user that SD card has serious error
if (retryModelCount < retryLimit) {
if (storageDirtyMsk & EE_MODEL) {
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;
}
}
}
}
Expand Down

0 comments on commit 6591032

Please sign in to comment.