From 0aeede806c1c5c6814c092c47a95ee4af569f389 Mon Sep 17 00:00:00 2001 From: Moritz Perschke <moritz.perschke@uibk.ac.at> Date: Wed, 3 Aug 2022 14:55:57 +0200 Subject: [PATCH] Message::send() now caches data --- client/client/lib/caching/src/ram_caching.cpp | 2 +- client/client/lib/caching/src/ram_caching.hpp | 2 +- client/client/lib/espnow/src/espnow.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/client/lib/caching/src/ram_caching.cpp b/client/client/lib/caching/src/ram_caching.cpp index f40da86..7b3e437 100644 --- a/client/client/lib/caching/src/ram_caching.cpp +++ b/client/client/lib/caching/src/ram_caching.cpp @@ -8,7 +8,7 @@ data_struct ram_cache_pop(){ return backup[cachedAmount--]; } -bool ram_cache_push(data_struct data){ +void ram_cache_push(data_struct data){ backup[++cachedAmount] = data; } diff --git a/client/client/lib/caching/src/ram_caching.hpp b/client/client/lib/caching/src/ram_caching.hpp index 888719b..979e849 100644 --- a/client/client/lib/caching/src/ram_caching.hpp +++ b/client/client/lib/caching/src/ram_caching.hpp @@ -2,9 +2,9 @@ #define _RAM_CACHE #include "espnow.hpp" -bool ram_cache_push(data_struct data); bool ram_cache_is_empty(); bool ram_cache_is_full(); +void ram_cache_push(data_struct data); data_struct ram_cache_pop(); #endif \ No newline at end of file diff --git a/client/client/lib/espnow/src/espnow.cpp b/client/client/lib/espnow/src/espnow.cpp index 7ebf2b6..01673d7 100644 --- a/client/client/lib/espnow/src/espnow.cpp +++ b/client/client/lib/espnow/src/espnow.cpp @@ -3,6 +3,7 @@ #include <ESP32Time.h> #include "WiFi.h" #include "espnow.hpp" +#include "ram_caching.hpp" uint8_t BROADCAST_MAC[] = {0x58, 0xCF, 0x79, 0x04, 0x37, 0x38}; esp_now_peer_info_t hostInfo; @@ -72,7 +73,11 @@ esp_err_t Message::send(){ Serial.println("sending Message"); esp_err_t success; success = esp_now_send(recipient, (uint8_t *) &data, sizeof(data)); - + if(success != ESP_OK){ + if(!ram_cache_is_full()){ + ram_cache_push(*data); + } + } for(int i=0; i<data->amountData; i++){ Serial.println(data->values[i]); } -- GitLab