Updated to new esp-idf
This commit is contained in:
@ -36,7 +36,6 @@ set(dependencies
|
|||||||
espwifistack
|
espwifistack
|
||||||
date
|
date
|
||||||
espchrono
|
espchrono
|
||||||
expected
|
|
||||||
fmt
|
fmt
|
||||||
nvs_flash
|
nvs_flash
|
||||||
)
|
)
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <tl/expected.hpp>
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
@ -16,7 +16,7 @@ template<int MAX_LENGTH>
|
|||||||
ConfigConstraintReturnType StringMaxSize(const std::string &str)
|
ConfigConstraintReturnType StringMaxSize(const std::string &str)
|
||||||
{
|
{
|
||||||
if (str.size() > MAX_LENGTH)
|
if (str.size() > MAX_LENGTH)
|
||||||
return tl::make_unexpected(fmt::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH));
|
return std::unexpected(fmt::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,14 +24,14 @@ template<int MIN_LENGTH, int MAX_LENGTH>
|
|||||||
ConfigConstraintReturnType StringMinMaxSize(const std::string &str)
|
ConfigConstraintReturnType StringMinMaxSize(const std::string &str)
|
||||||
{
|
{
|
||||||
if (str.size() < MIN_LENGTH || str.size() > MAX_LENGTH)
|
if (str.size() < MIN_LENGTH || str.size() > MAX_LENGTH)
|
||||||
return tl::make_unexpected(fmt::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH));
|
return std::unexpected(fmt::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ConfigConstraintReturnType StringEmpty(const std::string &str)
|
inline ConfigConstraintReturnType StringEmpty(const std::string &str)
|
||||||
{
|
{
|
||||||
if (!str.empty())
|
if (!str.empty())
|
||||||
return tl::make_unexpected("String has to be empty");
|
return std::unexpected("String has to be empty");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ ConfigConstraintReturnType StringOr(const std::string &str)
|
|||||||
const auto result1 = callback1(str);
|
const auto result1 = callback1(str);
|
||||||
if (result1)
|
if (result1)
|
||||||
return {};
|
return {};
|
||||||
return tl::make_unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error()));
|
return std::unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<ConfigWrapper<std::string>::ConstraintCallback callback0, ConfigWrapper<std::string>::ConstraintCallback callback1, ConfigWrapper<std::string>::ConstraintCallback callback2>
|
template<ConfigWrapper<std::string>::ConstraintCallback callback0, ConfigWrapper<std::string>::ConstraintCallback callback1, ConfigWrapper<std::string>::ConstraintCallback callback2>
|
||||||
@ -64,16 +64,16 @@ ConfigConstraintReturnType StringOr(const std::string &str)
|
|||||||
const auto result2 = callback2(str);
|
const auto result2 = callback2(str);
|
||||||
if (result2)
|
if (result2)
|
||||||
return {};
|
return {};
|
||||||
return tl::make_unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error()));
|
return std::unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<ConfigWrapper<std::string>::ConstraintCallback callback0, ConfigWrapper<std::string>::ConstraintCallback callback1>
|
template<ConfigWrapper<std::string>::ConstraintCallback callback0, ConfigWrapper<std::string>::ConstraintCallback callback1>
|
||||||
ConfigConstraintReturnType StringAnd(const std::string &str)
|
ConfigConstraintReturnType StringAnd(const std::string &str)
|
||||||
{
|
{
|
||||||
if (const auto result = callback0(str); !result)
|
if (const auto result = callback0(str); !result)
|
||||||
return tl::make_unexpected(result.error());
|
return std::unexpected(result.error());
|
||||||
if (const auto result = callback1(str); !result)
|
if (const auto result = callback1(str); !result)
|
||||||
return tl::make_unexpected(result.error());
|
return std::unexpected(result.error());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +81,11 @@ template<ConfigWrapper<std::string>::ConstraintCallback callback0, ConfigWrapper
|
|||||||
ConfigConstraintReturnType StringAnd(const std::string &str)
|
ConfigConstraintReturnType StringAnd(const std::string &str)
|
||||||
{
|
{
|
||||||
if (const auto result = callback0(str); !result)
|
if (const auto result = callback0(str); !result)
|
||||||
return tl::make_unexpected(result.error());
|
return std::unexpected(result.error());
|
||||||
if (const auto result = callback1(str); !result)
|
if (const auto result = callback1(str); !result)
|
||||||
return tl::make_unexpected(result.error());
|
return std::unexpected(result.error());
|
||||||
if (const auto result = callback2(str); !result)
|
if (const auto result = callback2(str); !result)
|
||||||
return tl::make_unexpected(result.error());
|
return std::unexpected(result.error());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ template<typename T, T ... ALLOWED_VALUES>
|
|||||||
ConfigConstraintReturnType OneOf(typename ConfigWrapper<T>::value_t val)
|
ConfigConstraintReturnType OneOf(typename ConfigWrapper<T>::value_t val)
|
||||||
{
|
{
|
||||||
if (!((ALLOWED_VALUES == val) || ...))
|
if (!((ALLOWED_VALUES == val) || ...))
|
||||||
return tl::make_unexpected("Value not one of the allowed ones");
|
return std::unexpected("Value not one of the allowed ones");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ template<typename T, T MIN_VALUE>
|
|||||||
ConfigConstraintReturnType MinValue(typename ConfigWrapper<T>::value_t val)
|
ConfigConstraintReturnType MinValue(typename ConfigWrapper<T>::value_t val)
|
||||||
{
|
{
|
||||||
if (val < MIN_VALUE)
|
if (val < MIN_VALUE)
|
||||||
return tl::make_unexpected(fmt::format("Value {} exceeds minimum {}", val, MIN_VALUE));
|
return std::unexpected(fmt::format("Value {} exceeds minimum {}", val, MIN_VALUE));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ template<typename T, T MAX_VALUE>
|
|||||||
ConfigConstraintReturnType MaxValue(typename ConfigWrapper<T>::value_t val)
|
ConfigConstraintReturnType MaxValue(typename ConfigWrapper<T>::value_t val)
|
||||||
{
|
{
|
||||||
if (val > MAX_VALUE)
|
if (val > MAX_VALUE)
|
||||||
return tl::make_unexpected(fmt::format("Value {} exceeds maximum {}", val, MAX_VALUE));
|
return std::unexpected(fmt::format("Value {} exceeds maximum {}", val, MAX_VALUE));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ template<typename T, T MIN_VALUE, T MAX_VALUE>
|
|||||||
ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper<T>::value_t val)
|
ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper<T>::value_t val)
|
||||||
{
|
{
|
||||||
if (val < MIN_VALUE || val > MAX_VALUE)
|
if (val < MIN_VALUE || val > MAX_VALUE)
|
||||||
return tl::make_unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ template<typename T>
|
|||||||
ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper<T>::value_t val, T MIN_VALUE, T MAX_VALUE)
|
ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper<T>::value_t val, T MIN_VALUE, T MAX_VALUE)
|
||||||
{
|
{
|
||||||
if (val < MIN_VALUE || val > MAX_VALUE)
|
if (val < MIN_VALUE || val > MAX_VALUE)
|
||||||
return tl::make_unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ template<typename T, T MIN_VALUE, T MAX_VALUE>
|
|||||||
ConfigConstraintReturnType MinMaxOrZeroValue(typename ConfigWrapper<T>::value_t val)
|
ConfigConstraintReturnType MinMaxOrZeroValue(typename ConfigWrapper<T>::value_t val)
|
||||||
{
|
{
|
||||||
if (val != 0 && (val < MIN_VALUE || val > MAX_VALUE))
|
if (val != 0 && (val < MIN_VALUE || val > MAX_VALUE))
|
||||||
return tl::make_unexpected(fmt::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
return std::unexpected(fmt::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
} // namespace espconfig
|
} // namespace espconfig
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <tl/expected.hpp>
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
@ -16,7 +16,7 @@ inline ConfigConstraintReturnType MinTimeSyncInterval(espchrono::milliseconds32
|
|||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
if (val < 15s)
|
if (val < 15s)
|
||||||
return tl::make_unexpected("SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds");
|
return std::unexpected("SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
} // namespace espconfig
|
} // namespace espconfig
|
||||||
|
@ -166,7 +166,7 @@ ConfigStatusReturnType ConfigManager<ConfigContainer>::reset()
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!message.empty())
|
if (!message.empty())
|
||||||
return tl::make_unexpected(std::move(message));
|
return std::unexpected(std::move(message));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <expected>
|
||||||
// 3rdparty lib includes
|
|
||||||
#include <tl/expected.hpp>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "configwrapperinterface.h"
|
#include "configwrapperinterface.h"
|
||||||
|
@ -153,7 +153,7 @@ ConfigStatusReturnType ConfigWrapper<T>::forceReset(nvs_handle_t nvsHandle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result != ESP_OK)
|
if (result != ESP_OK)
|
||||||
return tl::make_unexpected(std::string{"nvs_erase_key() failed with "} + esp_err_to_name(result));
|
return std::unexpected(std::string{"nvs_erase_key() failed with "} + esp_err_to_name(result));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ ConfigStatusReturnType ConfigWrapper<T>::writeToFlash(nvs_handle_t nvsHandle, va
|
|||||||
m_touched = true;
|
m_touched = true;
|
||||||
|
|
||||||
if (result != ESP_OK)
|
if (result != ESP_OK)
|
||||||
return tl::make_unexpected(std::string{"nvs_set() failed with "} + esp_err_to_name(result));
|
return std::unexpected(std::string{"nvs_set() failed with "} + esp_err_to_name(result));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,17 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <nvs.h>
|
#include <nvs.h>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
|
||||||
#include <tl/expected.hpp>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "cppmacros.h"
|
#include "cppmacros.h"
|
||||||
|
|
||||||
namespace espconfig {
|
namespace espconfig {
|
||||||
|
|
||||||
using ConfigStatusReturnType = tl::expected<void, std::string>;
|
using ConfigStatusReturnType = std::expected<void, std::string>;
|
||||||
|
|
||||||
class ConfigWrapperInterface
|
class ConfigWrapperInterface
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user