Skip to content
Snippets Groups Projects
Commit 38205401 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

fixed error that cut off beginning of strings, added usability methods

parent d1fac93e
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!6Espnow
......@@ -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;
}
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment