-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,016 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "config/ConfigBase.h" | ||
|
||
#include <string> | ||
|
||
namespace OpenShock::Config { | ||
struct BackendConfig : public ConfigBase<Serialization::Configuration::BackendConfig> { | ||
std::string authToken; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::BackendConfig* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::BackendConfig> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "config/ConfigBase.h" | ||
|
||
namespace OpenShock::Config { | ||
struct CaptivePortalConfig : public ConfigBase<Serialization::Configuration::CaptivePortalConfig> { | ||
CaptivePortalConfig(); | ||
CaptivePortalConfig(bool alwaysEnabled); | ||
|
||
bool alwaysEnabled; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::CaptivePortalConfig* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::CaptivePortalConfig> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "serialization/_fbs/ConfigFile_generated.h" | ||
|
||
#include <cJSON.h> | ||
|
||
namespace OpenShock::Config { | ||
template <typename T> | ||
struct ConfigBase { | ||
virtual void ToDefault() = 0; | ||
|
||
virtual bool FromFlatbuffers(const T* config) = 0; | ||
virtual flatbuffers::Offset<T> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const = 0; | ||
|
||
virtual bool FromJSON(const cJSON* json) = 0; | ||
virtual cJSON* ToJSON() const = 0; | ||
}; | ||
|
||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "config/ConfigBase.h" | ||
|
||
namespace OpenShock::Config { | ||
struct RFConfig : public ConfigBase<Serialization::Configuration::RFConfig> { | ||
std::uint8_t txPin; | ||
bool keepAliveEnabled; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::RFConfig* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::RFConfig> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "config/RFConfig.h" | ||
#include "config/WiFiConfig.h" | ||
#include "config/CaptivePortalConfig.h" | ||
#include "config/BackendConfig.h" | ||
#include "config/ConfigBase.h" | ||
|
||
namespace OpenShock::Config { | ||
struct RootConfig : public ConfigBase<Serialization::Configuration::Config> { | ||
OpenShock::Config::RFConfig rf; | ||
OpenShock::Config::WiFiConfig wifi; | ||
OpenShock::Config::CaptivePortalConfig captivePortal; | ||
OpenShock::Config::BackendConfig backend; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::Config* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::Config> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "config/WiFiCredentials.h" | ||
#include "config/ConfigBase.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace OpenShock::Config { | ||
struct WiFiConfig : public ConfigBase<Serialization::Configuration::WiFiConfig> { | ||
std::string accessPointSSID; | ||
std::string hostname; | ||
std::vector<OpenShock::Config::WiFiCredentials> credentialsList; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::WiFiConfig* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::WiFiConfig> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "config/ConfigBase.h" | ||
|
||
#include <string> | ||
|
||
namespace OpenShock::Config { | ||
struct WiFiCredentials : public ConfigBase<Serialization::Configuration::WiFiCredentials> { | ||
WiFiCredentials(); | ||
WiFiCredentials(std::uint8_t id, const std::string& ssid, const std::uint8_t (&bssid)[6], const std::string& password); | ||
|
||
std::uint8_t id; | ||
std::string ssid; | ||
std::uint8_t bssid[6]; | ||
std::string password; | ||
|
||
void ToDefault() override; | ||
|
||
bool FromFlatbuffers(const Serialization::Configuration::WiFiCredentials* config) override; | ||
flatbuffers::Offset<Serialization::Configuration::WiFiCredentials> ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const override; | ||
|
||
bool FromJSON(const cJSON* json) override; | ||
cJSON* ToJSON() const override; | ||
}; | ||
} // namespace OpenShock::Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "config/ConfigBase.h" | ||
|
||
#include <cJSON.h> | ||
|
||
namespace OpenShock::Config::Internal::Utils { | ||
inline void FromFbsStr(std::string& str, const flatbuffers::String* fbsStr, const char* defaultStr) { | ||
if (fbsStr != nullptr) { | ||
str = fbsStr->c_str(); | ||
} else { | ||
str = defaultStr; | ||
} | ||
} | ||
template<typename T, typename U> // T inherits from ConfigBase<U> | ||
void FromFbsVec(std::vector<T>& vec, const flatbuffers::Vector<flatbuffers::Offset<U>>* fbsVec) { | ||
vec.clear(); | ||
if (fbsVec != nullptr) { | ||
for (auto fbsItem : *fbsVec) { | ||
T item; | ||
if (item.FromFlatbuffers(fbsItem)) { | ||
vec.push_back(std::move(item)); | ||
} | ||
} | ||
} | ||
} | ||
} // namespace OpenShock::Config::Internal::Utils |
Oops, something went wrong.