|
MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
|
MeshX GPIO KV Engine Persistence Implementation. More...
#include <string.h>#include <stdbool.h>#include "interface/gpio/meshx_gpio.h"#include "interface/gpio/meshx_gpio_types.h"#include "interface/gpio/meshx_gpio_kv.h"#include "interface/utils/meshx_fal_interface.h"#include "meshx_kv_engine.h"#include "meshx_err.h"#include "interface/logging/meshx_log.h"#include "module_id.h"Macros | |
| #define | MESHX_GPIO_KV_MAX_CONFIG_SIZE 512 |
| Maximum buffer size for GPIO configuration serialization. | |
| #define | MESHX_GPIO_KV_MAX_PINS 32 |
| Maximum number of pins supported in KV storage. | |
Functions | |
| static meshx_err_t | serialize_gpio_config (const meshx_gpio_pin_config_t *configs, uint8_t pin_count, uint8_t *buf, uint16_t buf_len, uint16_t *out_size) |
| Serialize GPIO configuration to buffer. | |
| static meshx_err_t | deserialize_gpio_config (const uint8_t *buf, uint16_t buf_len, meshx_gpio_pin_config_t *configs, uint8_t max_pins, uint8_t *out_pin_count) |
| Deserialize GPIO configuration from buffer. | |
| meshx_err_t | meshx_gpio_kv_init (const meshx_fal_partition_t *kv_partition, const char *product_name) |
| Initialize GPIO KV Engine persistence. | |
| meshx_err_t | meshx_gpio_save_config_to_kv (const meshx_gpio_pin_config_t *configs, uint8_t pin_count) |
| Save GPIO configuration to KV Engine. | |
| meshx_err_t | meshx_gpio_load_config_from_kv (meshx_gpio_pin_config_t *configs, uint8_t max_pins, uint8_t *out_pin_count) |
| Load GPIO configuration from KV Engine. | |
| meshx_err_t | meshx_gpio_config_exists_in_kv (bool *exists) |
| Check if GPIO configuration exists in KV Engine. | |
| meshx_err_t | meshx_gpio_save_pin_state_to_kv (uint8_t logical_pin, const meshx_gpio_pin_state_t *state) |
| Save current pin state to KV Engine. | |
| meshx_err_t | meshx_gpio_load_pin_state_from_kv (uint8_t logical_pin, meshx_gpio_pin_state_t *state) |
| Load pin state from KV Engine. | |
| meshx_err_t | meshx_gpio_export_config (const meshx_gpio_pin_config_t *configs, uint8_t pin_count, uint8_t *buf, uint16_t buf_len, uint16_t *out_size) |
| Export GPIO configuration to serialized format. | |
| meshx_err_t | meshx_gpio_import_config (const uint8_t *buf, uint16_t buf_len, meshx_gpio_pin_config_t *configs, uint8_t max_pins, uint8_t *out_pin_count) |
| Import GPIO configuration from serialized format. | |
| meshx_err_t | meshx_gpio_clear_config_in_kv (void) |
| Clear GPIO configuration from KV Engine. | |
| meshx_err_t | meshx_gpio_kv_deinit (void) |
| Deinitialize GPIO KV Engine persistence. | |
| bool | meshx_gpio_kv_is_initialized (void) |
| Check if GPIO KV persistence is initialized. | |
Variables | |
| static const meshx_fal_partition_t * | gpio_kv_partition = NULL |
| KV Engine partition reference (set during initialization). | |
| static char | current_product_name [16+1] = {0} |
| Current product name for key prefix. | |
| static bool | kv_persistence_initialized = false |
| Flag indicating if KV persistence is initialized. | |
MeshX GPIO KV Engine Persistence Implementation.
This file implements the GPIO configuration persistence API using the MeshX KV Engine. It provides save/load functions for GPIO configuration with versioning, CRC validation, and corruption fallback to compiled defaults.
| #define MESHX_GPIO_KV_MAX_CONFIG_SIZE 512 |
Maximum buffer size for GPIO configuration serialization.
| #define MESHX_GPIO_KV_MAX_PINS 32 |
Maximum number of pins supported in KV storage.
|
static |
Deserialize GPIO configuration from buffer.
| buf | Input buffer | |
| buf_len | Buffer length | |
| configs | Array to store pin configurations | |
| max_pins | Maximum pins that can be stored | |
| [out] | out_pin_count | Actual pin count read |
| meshx_err_t meshx_gpio_clear_config_in_kv | ( | void | ) |
Clear GPIO configuration from KV Engine.
Removes the stored GPIO configuration, forcing fallback to defaults on next load.
| meshx_err_t meshx_gpio_config_exists_in_kv | ( | bool * | exists | ) |
Check if GPIO configuration exists in KV Engine.
| [out] | exists | true if configuration exists, false otherwise |
| meshx_err_t meshx_gpio_export_config | ( | const meshx_gpio_pin_config_t * | configs, |
| uint8_t | pin_count, | ||
| uint8_t * | buf, | ||
| uint16_t | buf_len, | ||
| uint16_t * | out_size ) |
Export GPIO configuration to serialized format.
Exports the configuration in binary format for transfer to another device.
| configs | Array of pin configurations | |
| pin_count | Number of pins | |
| [out] | buf | Output buffer |
| buf_len | Buffer length | |
| [out] | out_size | Actual exported size |
| meshx_err_t meshx_gpio_import_config | ( | const uint8_t * | buf, |
| uint16_t | buf_len, | ||
| meshx_gpio_pin_config_t * | configs, | ||
| uint8_t | max_pins, | ||
| uint8_t * | out_pin_count ) |
Import GPIO configuration from serialized format.
Imports configuration from binary format received from another device.
| buf | Input buffer | |
| buf_len | Buffer length | |
| [out] | configs | Array to store imported configurations |
| max_pins | Maximum pins that can be stored | |
| [out] | out_pin_count | Actual number of pins imported |
| meshx_err_t meshx_gpio_kv_deinit | ( | void | ) |
Deinitialize GPIO KV Engine persistence.
Cleans up KV persistence resources. Does not affect the underlying KV Engine partition.
| meshx_err_t meshx_gpio_kv_init | ( | const meshx_fal_partition_t * | kv_partition, |
| const char * | product_name ) |
Initialize GPIO KV Engine persistence.
This function initializes the KV Engine for GPIO configuration storage. It must be called before any other GPIO KV functions.
| kv_partition | Pointer to the flash partition to use for KV storage |
| product_name | Product name for key prefix (max 16 chars) |
| bool meshx_gpio_kv_is_initialized | ( | void | ) |
Check if GPIO KV persistence is initialized.
| meshx_err_t meshx_gpio_load_config_from_kv | ( | meshx_gpio_pin_config_t * | configs, |
| uint8_t | max_pins, | ||
| uint8_t * | out_pin_count ) |
Load GPIO configuration from KV Engine.
This function loads and deserializes GPIO configuration from KV Engine. If the configuration is not found or corrupted, returns MESHX_NOT_FOUND to allow fallback to compiled defaults.
| configs | Array to store loaded pin configurations | |
| max_pins | Maximum pins that can be stored | |
| [out] | out_pin_count | Actual number of pins loaded |
| meshx_err_t meshx_gpio_load_pin_state_from_kv | ( | uint8_t | logical_pin, |
| meshx_gpio_pin_state_t * | state ) |
Load pin state from KV Engine.
Loads previously persisted runtime state of a GPIO pin.
| logical_pin | Logical pin number | |
| [out] | state | Pointer to store loaded pin state |
| meshx_err_t meshx_gpio_save_config_to_kv | ( | const meshx_gpio_pin_config_t * | configs, |
| uint8_t | pin_count ) |
Save GPIO configuration to KV Engine.
This function serializes and saves the GPIO configuration to KV Engine with versioning and CRC validation.
| configs | Array of pin configurations to save |
| pin_count | Number of pins in configuration |
| meshx_err_t meshx_gpio_save_pin_state_to_kv | ( | uint8_t | logical_pin, |
| const meshx_gpio_pin_state_t * | state ) |
Save current pin state to KV Engine.
Persists the runtime state of a GPIO pin across reboots.
| logical_pin | Logical pin number |
| state | Pointer to pin state to save |
|
static |
Serialize GPIO configuration to buffer.
| configs | Array of pin configurations | |
| pin_count | Number of pins | |
| buf | Output buffer | |
| buf_len | Buffer length | |
| [out] | out_size | Actual serialized size |
|
static |
Current product name for key prefix.
|
static |
KV Engine partition reference (set during initialization).
|
static |
Flag indicating if KV persistence is initialized.