HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
EspNvs.h
Go to the documentation of this file.
1
44#pragma once
45
46#include "BaseNvs.h"
47#include "PlatformMutex.h" // Thread-safe mutex support if enabled
48#include "utils/EspTypes_NVS.h" // Centralized ESP32 NVS type definitions
49#include <cstdint>
50
51// ESP32-C6 NVS abstracted types for portability
52
105class EspNvs : public BaseNvs {
106public:
111 explicit EspNvs(const char* namespace_name) noexcept;
112
116 ~EspNvs() noexcept override;
117
118 //==============================================//
119 // OVERRIDDEN PURE VIRTUAL FUNCTIONS //
120 //==============================================//
121
126 hf_nvs_err_t Initialize() noexcept override;
127
132 hf_nvs_err_t Deinitialize() noexcept override;
133
140 hf_nvs_err_t SetU32(const char* key, hf_u32_t value) noexcept override;
141
148 hf_nvs_err_t GetU32(const char* key, hf_u32_t& value) noexcept override;
149
156 hf_nvs_err_t SetString(const char* key, const char* value) noexcept override;
157
166 hf_nvs_err_t GetString(const char* key, char* buffer, size_t buffer_size,
167 size_t* actual_size = nullptr) noexcept override;
168
176 hf_nvs_err_t SetBlob(const char* key, const void* data, size_t data_size) noexcept override;
177
186 hf_nvs_err_t GetBlob(const char* key, void* buffer, size_t buffer_size,
187 size_t* actual_size = nullptr) noexcept override;
188
194 hf_nvs_err_t EraseKey(const char* key) noexcept override;
195
200 hf_nvs_err_t Commit() noexcept override;
201
207 bool KeyExists(const char* key) noexcept override;
208
215 hf_nvs_err_t GetSize(const char* key, size_t& size) noexcept override;
216
221 const char* GetDescription() const noexcept override;
222
227 size_t GetMaxKeyLength() const noexcept override;
228
233 size_t GetMaxValueSize() const noexcept override;
234
235 //==============================================//
236 // STATISTICS AND DIAGNOSTICS //
237 //==============================================//
238
244 hf_nvs_err_t GetStatistics(hf_nvs_statistics_t& statistics) const noexcept override;
245
251 hf_nvs_err_t GetDiagnostics(hf_nvs_diagnostics_t& diagnostics) const noexcept override;
252
253private:
254 //==============================================//
255 // PRIVATE HELPER FUNCTIONS //
256 //==============================================//
257
267 hf_nvs_err_t ConvertMcuError(int mcu_error) const noexcept;
268
275 void UpdateStatistics(bool error_occurred) noexcept;
276
282 bool IsValidKey(const char* key) const noexcept;
283
284 //==============================================//
285 // PRIVATE MEMBER VARIABLES //
286 //==============================================//
287
289 mutable int last_error_code_;
290
291 // Statistics and performance monitoring
294
295 // Thread safety
297};
Abstract base class for Non-Volatile Storage implementations in the HardFOC system.
hf_nvs_err_t
Definition BaseNvs.h:76
ESP32 NVS type definitions for hardware abstraction.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
Cross-platform RTOS mutex and synchronization primitives.
Abstract base class for non-volatile storage operations.
Definition BaseNvs.h:147
Production-ready MCU-integrated non-volatile storage implementation.
Definition EspNvs.h:105
hf_nvs_err_t SetBlob(const char *key, const void *data, size_t data_size) noexcept override
Store binary data (blob).
hf_nvs_err_t SetU32(const char *key, hf_u32_t value) noexcept override
Store a 32-bit unsigned integer value.
hf_nvs_err_t Initialize() noexcept override
Initialize the NVS system and open the namespace.
hf_nvs_diagnostics_t diagnostics_
Diagnostic information.
Definition EspNvs.h:293
hf_nvs_err_t Commit() noexcept override
Commit any pending writes to non-volatile storage.
hf_nvs_err_t GetSize(const char *key, size_t &size) noexcept override
Get the size of a stored value.
EspNvs(const char *namespace_name) noexcept
Constructor with namespace specification.
bool IsValidKey(const char *key) const noexcept
Validate key name according to ESP32 NVS constraints.
hf_nvs_statistics_t statistics_
Operation statistics.
Definition EspNvs.h:292
PlatformMutex mutex_
Mutex for thread-safe operations.
Definition EspNvs.h:296
void * nvs_handle_
Platform-specific NVS handle (nvs_handle_t on ESP32)
Definition EspNvs.h:288
hf_nvs_err_t Deinitialize() noexcept override
Deinitialize the NVS system and close the namespace.
bool KeyExists(const char *key) noexcept override
Check if a key exists in storage.
hf_nvs_err_t GetDiagnostics(hf_nvs_diagnostics_t &diagnostics) const noexcept override
Get NVS diagnostic information.
hf_nvs_err_t GetU32(const char *key, hf_u32_t &value) noexcept override
Retrieve a 32-bit unsigned integer value.
~EspNvs() noexcept override
Destructor - ensures proper cleanup.
void UpdateStatistics(bool error_occurred) noexcept
Update operation statistics and performance counters.
hf_nvs_err_t SetString(const char *key, const char *value) noexcept override
Store a string value.
hf_nvs_err_t EraseKey(const char *key) noexcept override
Remove a key from storage.
hf_nvs_err_t GetStatistics(hf_nvs_statistics_t &statistics) const noexcept override
Get NVS operation statistics.
size_t GetMaxValueSize() const noexcept override
Get maximum value size supported.
int last_error_code_
Last MCU-specific error code for debugging.
Definition EspNvs.h:289
hf_nvs_err_t GetBlob(const char *key, void *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve binary data (blob).
hf_nvs_err_t GetString(const char *key, char *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve a string value.
const char * GetDescription() const noexcept override
Get description of this NVS implementation.
size_t GetMaxKeyLength() const noexcept override
Get maximum key length supported.
hf_nvs_err_t ConvertMcuError(int mcu_error) const noexcept
Convert MCU-specific error code to HardFOC NVS error.
Definition PlatformMutex.h:78
NVS diagnostic information.
Definition BaseNvs.h:120
NVS operation statistics.
Definition BaseNvs.h:102