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

moved from memcpy to a for loop, memcpy caused core panic(Store access fault)

parent 0c5781b7
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!6Espnow
......@@ -2,7 +2,7 @@
namespace RtcMemory{
// 2D array of 20 Strings with maxLength of 251
RTC_DATA_ATTR char storage[maxSize_][maxLength_];
RTC_DATA_ATTR char storage[maxLength_][maxSize_];
RTC_DATA_ATTR int headElement = 0;
RTC_DATA_ATTR int tailElement = 0;
......@@ -14,57 +14,38 @@ namespace RtcMemory{
// turn data into char array
const char* jsonString = message.c_str();
// move head to beginning of new element
// head = (head + (sizeof(char) * 251)) % sizeof(storage);
// move head to new element
headElement = (headElement + 1) % maxSize_;
// copy data to earliest free block
memcpy( &storage + headElement*maxSize_,
jsonString,
sizeof(jsonString)
);
ESP_LOGI(TAG, "Moved message to storage.");
// 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;
}
}
ESP_LOGE(TAG, "Moved message to storage.");
}
String get_from_storage(){
// remove element pointed at by tail
String buf = "";
char current;
for(int i = 0; i<251; i++){
// i dont like this
memcpy(&current, &storage + (tailElement*maxSize_) + i, sizeof(char));
char current = '\0';
for(int i = 0; i<maxLength_; i++){
current = storage[i][tailElement];
buf += current;
if(current = '\0'){
Serial.print(current);
if(current == '\0'){
Serial.println("\n");
Serial.flush();
break;
}
}
// move tail to next element
tailElement = (tailElement + 1) % maxLength_;
Serial.println(buf);
ESP_LOGI(TAG, "Retrieved message from storage");
ESP_LOGE(TAG, "Retrieved message from storage");
return buf;
}
}
//RTC_DATA_ATTR int cachedAmount = -1;
//RTC_DATA_ATTR ClientDataPackage backup[NUM_SENSORS];
//
//ClientDataPackage ram_cache_pop()
//{
// return backup[cachedAmount--];
//}
//
//void ram_cache_push(ClientDataPackage data)
//{
// backup[++cachedAmount] = data;
// ESP_LOGI(TAG, "ClientDataPackage saved");
//}
//
//bool ram_cache_is_empty()
//{
// return cachedAmount == -1;
//}
//
//bool ram_cache_is_full()
//{
// return cachedAmount == 9;
//}
\ No newline at end of file
......@@ -3,7 +3,7 @@
#include "esp_log.h"
#include <ESP32Time.h>
#define maxSize_ 20
#define maxSize_ 2
#define maxLength_ 251
namespace RtcMemory {
......
......@@ -15,12 +15,9 @@ esp_err_t Message::send() const
if (success != ESP_OK) {
ESP_LOGE(TAG, "Error sending the data");
Serial.println(success, HEX);
// TODO REWRITE FOR JSON
// if (!ram_cache_is_full()) {
// // ram_cache_push(messageData);
// }
// Removed caching from here, better do this in main
}
ESP_LOGD(TAG, "Sent data: %s", messageData.c_str());
ESP_LOGE(TAG, "Sent data: %s", messageData.c_str());
ESP_LOGD(TAG, "time sent: %l", clientDataPackage.getTimestamp());
ESP_LOGD(TAG, "send status: %d", success);
......
......@@ -32,10 +32,21 @@ void loop()
auto messages = drs26.buildMessages();
for (const Message &message : messages) {
if(message.send() != ESP_OK){
RtcMemory::store(message.getMessageAsMinifiedJsonString());
}
// if(message.send() != ESP_OK){
// RtcMemory::store(message.getMessageAsMinifiedJsonString());
// }
// some sort of if(message received) is needed as well
RtcMemory::store(message.getMessageAsMinifiedJsonString());
// Serial.println("original string:");
// Serial.println(message.getMessageAsMinifiedJsonString().c_str());
// Serial.println("length: " + (String) sizeof(message.getMessageAsMinifiedJsonString().c_str()));
// Serial.println("\n after retrieval:");
String test = RtcMemory::get_from_storage();
// Serial.println(test);
// Serial.println("length: " + (String) sizeof(test));
Serial.println("------------------------");
}
Serial.println("================================");
} catch (const NoDataAvailableException &e) {
std::cerr << e.what() << '\n';
......@@ -48,6 +59,6 @@ void loop()
Serial.print("This device: ");
Serial.println(WiFi.macAddress());
Serial.println("\n");
delay(5000);
DeepSleep::deep_sleep(5);
delay(10000);
// DeepSleep::deep_sleep(5);
}
......@@ -13,8 +13,8 @@ platform = espressif32
board = esp32-c3-devkitm-1
monitor_speed = 115200
framework = arduino
monitor_port = /dev/ttyUSB1
upload_port = /dev/ttyUSB1
; monitor_port = /dev/ttyUSB1
; upload_port = /dev/ttyUSB1
build_flags =
-I include
-DCORE_DEBUG_LEVEL=5
......
  • Developer

    For some reason, every other store/load cycle, one more char gets cut off from the beginning of the string.

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