diff --git a/client/client/lib/caching/src/ram_caching.cpp b/client/client/lib/caching/src/ram_caching.cpp index 3b16f6e073fcffeef10cf68a0e8dd3db981f9fc6..641f9744f12e4b7755ea78e786fcf06448f627f6 100644 --- a/client/client/lib/caching/src/ram_caching.cpp +++ b/client/client/lib/caching/src/ram_caching.cpp @@ -3,6 +3,7 @@ namespace RtcMemory{ // 2D array of 20 Strings with maxLength of 251 RTC_DATA_ATTR char storage[maxLength_][maxSize_]; + RTC_DATA_ATTR int storedElements; RTC_DATA_ATTR int headElement = 0; RTC_DATA_ATTR int tailElement = 0; @@ -19,13 +20,11 @@ namespace RtcMemory{ // apparently I am not allowed to copy to rtc mem for(int i=0; i<maxLength_; i++){ storage[i][headElement] = jsonString[i]; - Serial.print(jsonString[i]); if(jsonString[i] == '\0'){ - Serial.println("\n"); - Serial.flush(); break; } } + storedElements++; ESP_LOGE(TAG, "Moved message to storage."); } @@ -36,16 +35,22 @@ namespace RtcMemory{ for(int i = 0; i<maxLength_; i++){ current = storage[i][tailElement]; buf += current; - Serial.print(current); if(current == '\0'){ - Serial.println("\n"); - Serial.flush(); break; } } // move tail to next element - tailElement = (tailElement + 1) % maxLength_; + tailElement = (tailElement + 1) % maxSize_; + storedElements--; ESP_LOGE(TAG, "Retrieved message from storage"); return buf; } + + bool is_full(){ + return headElement == tailElement; + } + + int stored_amount(){ + return storedElements; + } } diff --git a/client/client/lib/caching/src/ram_caching.hpp b/client/client/lib/caching/src/ram_caching.hpp index b16e248a7a514a21e523f06cb66c5408ad0a65ab..c1a4ac57312afe9505b565b0ccfb1cf73f9175e9 100644 --- a/client/client/lib/caching/src/ram_caching.hpp +++ b/client/client/lib/caching/src/ram_caching.hpp @@ -3,17 +3,14 @@ #include "esp_log.h" #include <ESP32Time.h> -#define maxSize_ 2 +#define maxSize_ 20 #define maxLength_ 251 namespace RtcMemory { void store(std::string message); String get_from_storage(); + bool is_full(); + int stored_amount(); } -// bool ram_cache_is_empty(); -// bool ram_cache_is_full(); -// void ram(ClientDataPackage data); -// ClientDataPackage ram_cache_pop(); - #endif \ No newline at end of file