Skip to content

Commit c44ce16

Browse files
committed
re-enabled sd related commands now that sdcard support is working; add blank line output after command - cleaner
1 parent 93818fc commit c44ce16

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

sfeIoTNodeLoRaWAN/sfeNLCommands.h

+46-46
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,29 @@ class sfeNLCommands
120120
/// @param theApp Pointer to the DataLogger App
121121
/// @retval bool indicates success (true) or failure (!true)
122122
///
123-
// bool loadJSONSettings(sfeIoTNodeLoRaWAN *theApp)
124-
// {
125-
// if (!theApp)
126-
// return false;
127-
128-
// flxLog_I(F("Load JSON Settings - Not Implemented"));
123+
bool loadJSONSettings(sfeIoTNodeLoRaWAN *theApp)
124+
{
125+
if (!theApp)
126+
return false;
129127

130-
// // // Create a JSON prefs serial object and read in the settings
131-
// // flxStorageJSONPrefSerial prefsSerial(flxSettings.fallbackBuffer() > 0 ? flxSettings.fallbackBuffer() :
132-
// 2000);
128+
// Create a JSON prefs serial object and read in the settings
129+
flxStorageJSONPrefSerial prefsSerial(flxSettings.fallbackBuffer() > 0 ? flxSettings.fallbackBuffer() : 2000);
133130

134-
// // // restore the settings from serial
135-
// // bool status = flxSettings.restoreObjectFromStorage(&flux, &prefsSerial);
136-
// // if (!status)
137-
// // return false;
131+
// restore the settings from serial
132+
bool status = flxSettings.restoreObjectFromStorage(&flux, &prefsSerial);
133+
if (!status)
134+
return false;
138135

139-
// // flxLog_I_(F("Settings restored from serial..."));
136+
flxLog_I_(F("Settings restored from serial..."));
140137

141-
// // // now save the new settings in primary storage
142-
// // status = flxSettings.save(&flux, true);
143-
// // if (status)
144-
// // flxLog_N(F("saved locally"));
138+
// now save the new settings in primary storage
139+
status = flxSettings.save(&flux, true);
140+
if (status)
141+
flxLog_N(F("saved locally"));
145142

146-
// // return status;
147-
// return true;
148-
// }
143+
// return status;
144+
return true;
145+
}
149146
//---------------------------------------------------------------------
150147
///
151148
/// @brief Saves the current system to preferences/Settings
@@ -232,35 +229,37 @@ class sfeNLCommands
232229
/// @param theApp Pointer to the DataLogger App
233230
/// @retval bool indicates success (true) or failure (!true)
234231
///
235-
// bool sdCardStats(sfeIoTNodeLoRaWAN *theApp)
236-
// {
237-
// if (!theApp)
238-
// return false;
232+
bool sdCardStats(sfeIoTNodeLoRaWAN *theApp)
233+
{
234+
if (!theApp)
235+
return false;
239236

240-
// flxLog_I(F("SD Stats - Not Implemented"));
237+
if (theApp->_theSDCard.enabled())
238+
{
239+
char szSize[32];
240+
char szCap[32];
241+
char szAvail[32];
241242

242-
// // if (theApp->_theSDCard.enabled())
243-
// // {
243+
uint64_t sd_size = theApp->_theSDCard.size();
244+
uint64_t sd_total = theApp->_theSDCard.total();
244245

245-
// // char szSize[32];
246-
// // char szCap[32];
247-
// // char szAvail[32];
246+
flx_utils::formatByteString(sd_size, 2, szSize, sizeof(szSize));
247+
flx_utils::formatByteString(sd_total, 2, szCap, sizeof(szCap));
248248

249-
// // flx_utils::formatByteString(theApp->_theSDCard.size(), 2, szSize, sizeof(szSize));
250-
// // flx_utils::formatByteString(theApp->_theSDCard.total(), 2, szCap, sizeof(szCap));
251-
// // flx_utils::formatByteString(theApp->_theSDCard.total() - theApp->_theSDCard.used(), 2, szAvail,
252-
// // sizeof(szAvail));
249+
flxLog_I_("SD Card - Type: %s Size: %s Capacity: %s ", theApp->_theSDCard.type(), szSize, szCap);
253250

254-
// // flxLog_I(F("SD Card - Type: %s Size: %s Capacity: %s Free: %s (%.1f%%)"), theApp->_theSDCard.type(),
255-
// // szSize,
256-
// // szCap, szAvail, 100. - (theApp->_theSDCard.used() / (float)theApp->_theSDCard.total() *
257-
// 100.));
258-
// // }
259-
// // else
260-
// // flxLog_I(F("SD card not available"));
251+
flxLog_N_("...");
252+
flxSerial.flush();
253+
// This call can take some time .. .so
254+
uint64_t sd_used = theApp->_theSDCard.used();
255+
flx_utils::formatByteString(sd_total - sd_used, 2, szAvail, sizeof(szAvail));
256+
flxLog_N("Free: %s (%.1f%%)", szAvail, 100. - (sd_used / (float)sd_total * 100.));
257+
}
258+
else
259+
flxLog_I(F("SD card not available"));
261260

262-
// return true;
263-
// }
261+
return true;
262+
}
264263

265264
//---------------------------------------------------------------------
266265
///
@@ -429,11 +428,11 @@ class sfeNLCommands
429428
{"clear-settings-forced", &sfeNLCommands::clearDeviceSettingsForced},
430429
{"restart", &sfeNLCommands::restartDevice},
431430
{"restart-forced", &sfeNLCommands::restartDeviceForced},
432-
// {"json-settings", &sfeNLCommands::loadJSONSettings},
431+
{"json-settings", &sfeNLCommands::loadJSONSettings},
433432
{"log-rate", &sfeNLCommands::logRateStats},
434433
{"log-rate-toggle", &sfeNLCommands::logRateToggle},
435434
{"log-now", &sfeNLCommands::logObservationNow},
436-
// {"sdcard", &sfeNLCommands::sdCardStats},
435+
{"sdcard", &sfeNLCommands::sdCardStats},
437436
{"devices", &sfeNLCommands::listLoadedDevices},
438437
{"save-settings", &sfeNLCommands::saveSettings},
439438
{"heap", &sfeNLCommands::heapStatus},
@@ -472,6 +471,7 @@ class sfeNLCommands
472471
flxLog_N(F("Unknown Command: `%s`"), sBuffer.c_str());
473472
status = false;
474473
}
474+
flxLog_N("");
475475
return status;
476476
}
477477
};

0 commit comments

Comments
 (0)