diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 2ba5ccfb..2a16d5a1 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -40,8 +40,36 @@ void DataStore::begin() { #include #elif defined(RP2040_PLATFORM) #include +#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + #include #endif +uint32_t DataStore::getStorageUsedKb() const { +#if defined(ESP32) + return SPIFFS.usedBytes() / 1024; +#elif defined(RP2040_PLATFORM) + FSInfo info; + info.usedBytes = 0; + _fs->info(info); + return info.usedBytes / 1024; +#else + return 0; // TODO: InternalFS. method? +#endif +} + +uint32_t DataStore::getStorageTotalKb() const { +#if defined(ESP32) + return SPIFFS.totalBytes() / 1024; +#elif defined(RP2040_PLATFORM) + FSInfo info; + info.totalBytes = 0; + _fs->info(info); + return info.totalBytes / 1024; +#else + return 0; // TODO: InternalFS. method? +#endif +} + File DataStore::openRead(const char* filename) { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) return _fs->open(filename, FILE_O_READ); diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index 32ccd196..7bd33301 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -39,4 +39,6 @@ public: bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len); File openRead(const char* filename); bool removeFile(const char* filename); + uint32_t getStorageUsedKb() const; + uint32_t getStorageTotalKb() const; }; diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 97781a08..034f0206 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -22,7 +22,7 @@ #define CMD_EXPORT_CONTACT 17 #define CMD_IMPORT_CONTACT 18 #define CMD_REBOOT 19 -#define CMD_GET_BATTERY_VOLTAGE 20 +#define CMD_GET_BATT_AND_STORAGE 20 // was CMD_GET_BATTERY_VOLTAGE #define CMD_SET_TUNING_PARAMS 21 #define CMD_DEVICE_QEURY 22 #define CMD_EXPORT_PRIVATE_KEY 23 @@ -58,7 +58,7 @@ #define RESP_CODE_CURR_TIME 9 // a reply to CMD_GET_DEVICE_TIME #define RESP_CODE_NO_MORE_MESSAGES 10 // a reply to CMD_SYNC_NEXT_MESSAGE #define RESP_CODE_EXPORT_CONTACT 11 -#define RESP_CODE_BATTERY_VOLTAGE 12 // a reply to a CMD_GET_BATTERY_VOLTAGE +#define RESP_CODE_BATT_AND_STORAGE 12 // a reply to a CMD_GET_BATT_AND_STORAGE #define RESP_CODE_DEVICE_INFO 13 // a reply to CMD_DEVICE_QEURY #define RESP_CODE_PRIVATE_KEY 14 // a reply to CMD_EXPORT_PRIVATE_KEY #define RESP_CODE_DISABLED 15 @@ -1016,12 +1016,17 @@ void MyMesh::handleCmdFrame(size_t len) { saveContacts(); } board.reboot(); - } else if (cmd_frame[0] == CMD_GET_BATTERY_VOLTAGE) { - uint8_t reply[3]; - reply[0] = RESP_CODE_BATTERY_VOLTAGE; + } else if (cmd_frame[0] == CMD_GET_BATT_AND_STORAGE) { + uint8_t reply[11]; + int i = 0; + reply[i++] = RESP_CODE_BATT_AND_STORAGE; uint16_t battery_millivolts = board.getBattMilliVolts(); - memcpy(&reply[1], &battery_millivolts, 2); - _serial->writeFrame(reply, 3); + uint32_t used = _store->getStorageUsedKb(); + uint32_t total = _store->getStorageTotalKb(); + memcpy(&reply[i], &battery_millivolts, 2); i += 2; + memcpy(&reply[i], &used, 4); i += 4; + memcpy(&reply[i], &total, 4); i += 4; + _serial->writeFrame(reply, i); } else if (cmd_frame[0] == CMD_EXPORT_PRIVATE_KEY) { #if ENABLE_PRIVATE_KEY_EXPORT uint8_t reply[65];