From 969e7ded9c7074d281501ea6815512fb693fe4c6 Mon Sep 17 00:00:00 2001 From: Moritz Perschke <moritz.perschke@uibk.ac.at> Date: Wed, 3 Aug 2022 14:51:35 +0200 Subject: [PATCH] added lib to cache data if not sent successfully --- client/client/lib/caching/src/ram_caching.cpp | 21 +++++++++++++++++++ client/client/lib/caching/src/ram_caching.hpp | 10 +++++++++ client/client/lib/espnow/src/espnow.hpp | 1 + 3 files changed, 32 insertions(+) create mode 100644 client/client/lib/caching/src/ram_caching.cpp create mode 100644 client/client/lib/caching/src/ram_caching.hpp diff --git a/client/client/lib/caching/src/ram_caching.cpp b/client/client/lib/caching/src/ram_caching.cpp new file mode 100644 index 0000000..f40da86 --- /dev/null +++ b/client/client/lib/caching/src/ram_caching.cpp @@ -0,0 +1,21 @@ +#include <Arduino.h> +#include "espnow.hpp" + +RTC_DATA_ATTR int cachedAmount = -1; +RTC_DATA_ATTR data_struct backup[10]; + +data_struct ram_cache_pop(){ + return backup[cachedAmount--]; +} + +bool ram_cache_push(data_struct data){ + backup[++cachedAmount] = data; +} + +bool ram_cache_is_empty(){ + return cachedAmount == -1; +} + +bool ram_cache_is_full(){ + return cachedAmount == 9; +} \ No newline at end of file diff --git a/client/client/lib/caching/src/ram_caching.hpp b/client/client/lib/caching/src/ram_caching.hpp new file mode 100644 index 0000000..888719b --- /dev/null +++ b/client/client/lib/caching/src/ram_caching.hpp @@ -0,0 +1,10 @@ +#ifndef _RAM_CACHE +#define _RAM_CACHE +#include "espnow.hpp" + +bool ram_cache_push(data_struct data); +bool ram_cache_is_empty(); +bool ram_cache_is_full(); +data_struct ram_cache_pop(); + +#endif \ No newline at end of file diff --git a/client/client/lib/espnow/src/espnow.hpp b/client/client/lib/espnow/src/espnow.hpp index 7fa8ff0..50f65ab 100644 --- a/client/client/lib/espnow/src/espnow.hpp +++ b/client/client/lib/espnow/src/espnow.hpp @@ -22,6 +22,7 @@ typedef struct config{ class Message{ public: Message(); + Message(data_struct old_data); void add_data(float value, int identifier); esp_err_t send(); -- GitLab