From 35193ef13b660289093c40f482dd7589629ef9de Mon Sep 17 00:00:00 2001 From: hhvrc Date: Tue, 28 Nov 2023 20:12:45 +0100 Subject: [PATCH] Fix build --- include/config/RFConfig.h | 1 + src/config/RFConfig.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/config/RFConfig.h b/include/config/RFConfig.h index 7b0ed13e..85083078 100644 --- a/include/config/RFConfig.h +++ b/include/config/RFConfig.h @@ -5,6 +5,7 @@ namespace OpenShock::Config { struct RFConfig : public ConfigBase { std::uint8_t txPin; + bool keepAliveEnabled; void ToDefault() override; diff --git a/src/config/RFConfig.cpp b/src/config/RFConfig.cpp index 0906daae..f6f321b6 100644 --- a/src/config/RFConfig.cpp +++ b/src/config/RFConfig.cpp @@ -7,7 +7,8 @@ const char* const TAG = "Config::RFConfig"; using namespace OpenShock::Config; void RFConfig::ToDefault() { - txPin = 0U; + txPin = 0U; + keepAliveEnabled = true; } bool RFConfig::FromFlatbuffers(const Serialization::Configuration::RFConfig* config) { @@ -16,13 +17,14 @@ bool RFConfig::FromFlatbuffers(const Serialization::Configuration::RFConfig* con return false; } - txPin = config->tx_pin(); + txPin = config->tx_pin(); + keepAliveEnabled = config->keepalive_enabled(); return true; } flatbuffers::Offset RFConfig::ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const { - return Serialization::Configuration::CreateRFConfig(builder, txPin); + return Serialization::Configuration::CreateRFConfig(builder, txPin, keepAliveEnabled); } bool RFConfig::FromJSON(const cJSON* json) { @@ -44,6 +46,14 @@ bool RFConfig::FromJSON(const cJSON* json) { txPin = txPinJson->valueint; + const cJSON* keepAliveEnabledJson = cJSON_GetObjectItemCaseSensitive(json, "keepAliveEnabled"); + if (!cJSON_IsBool(keepAliveEnabledJson)) { + ESP_LOGE(TAG, "value at 'keepAliveEnabled' is not a bool"); + return false; + } + + keepAliveEnabled = cJSON_IsTrue(keepAliveEnabledJson); + return true; } @@ -51,6 +61,7 @@ cJSON* RFConfig::ToJSON() const { cJSON* root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "txPin", txPin); + cJSON_AddBoolToObject(root, "keepAliveEnabled", keepAliveEnabled); return root; }