Modbus Vault v1.0
Loading...
Searching...
No Matches
system_config.c File Reference

Implementation of the system configurations. More...

#include "esp_partition.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "system_config_internal.h"
#include "utils.h"
#include "wifi_manager.h"
#include <string.h>
Include dependency graph for system_config.c:

Functions

static void save_parameters_callback (void *arg_void_ptr)
 Callback to save parameters to NVS on timer timeout.
 
esp_err_t system_config_setup_defaults (void)
 Setup default configurations.
 
esp_err_t system_config_setup (void)
 Setup system configurations.
 
mqtt_bridge_config_tsystem_config_get_mqtt_config (void)
 Get MQTT bridge configuration.
 
rs485_driver_config_tsystem_config_get_rs485_driver_config (void)
 Get rs485 driver configuration.
 
modbus_analyzer_config_tsystem_config_get_modbus_analyzer_config (void)
 Get Modbus analyzer configuration.
 
blackbox_logger_config_tsystem_config_get_blackbox_logger_config (void)
 Get Blackbox logger configuration.
 
wifi_config_t * system_config_get_wifi_config (void)
 Get WiFi configuration.
 
nvs_manager_ops_tsystem_config_get_nvs_manager_ops (void)
 Get NVS operations.
 
void system_config_reset (void)
 Reset system config.
 

Variables

static const char * TAG = "SYSTEM_CONFIG"
 
static uint8_t sector_buf [BLACKBOX_LOGGER_SECTOR_SIZE]
 
static uint8_t batch_buf [BLACKBOX_LOGGER_BATCH_SIZE]
 
static char system_config_mqtt_uri [NVS_MANAGER_MAX_MQTT_URI_SIZE]
 
static char system_config_mqtt_user [NVS_MANAGER_MAX_MQTT_USER_SIZE]
 
static char system_config_mqtt_pass [NVS_MANAGER_MAX_MQTT_PASSWORD_SIZE]
 
static esp_timer_handle_t save_param_timer_handle
 
static system_config_t global_config
 

Detailed Description

Implementation of the system configurations.

Author
Abanoub Salah
  • Setup system configuration from
    • kconfig
    • NVS manager
    • Macro defines
  • Glues different aspects of system to configuration to allow initialization
  • Provides APIs to allow other system components to get their needed configuration
  • Provides helper function(s) needed by the system to work
    • Save parameters of logger to NVS

Function Documentation

◆ save_parameters_callback()

static void save_parameters_callback ( void *  arg_void_ptr)
static

Callback to save parameters to NVS on timer timeout.

Parameters
arg_void_ptrVoid pointer to argument
Here is the call graph for this function:
Here is the caller graph for this function:

◆ system_config_get_blackbox_logger_config()

blackbox_logger_config_t * system_config_get_blackbox_logger_config ( void  )

Get Blackbox logger configuration.

Returns
blackbox_logger_config_t*
Here is the caller graph for this function:

◆ system_config_get_modbus_analyzer_config()

modbus_analyzer_config_t * system_config_get_modbus_analyzer_config ( void  )

Get Modbus analyzer configuration.

Returns
modbus_analyzer_config_t*
Here is the caller graph for this function:

◆ system_config_get_mqtt_config()

mqtt_bridge_config_t * system_config_get_mqtt_config ( void  )

Get MQTT bridge configuration.

Returns
mqtt_bridge_config_t*
Here is the caller graph for this function:

◆ system_config_get_nvs_manager_ops()

nvs_manager_ops_t * system_config_get_nvs_manager_ops ( void  )

Get NVS operations.

Returns
nvs_manager_ops_t*
Here is the caller graph for this function:

◆ system_config_get_rs485_driver_config()

rs485_driver_config_t * system_config_get_rs485_driver_config ( void  )

Get rs485 driver configuration.

Returns
rs485_driver_config_t*

◆ system_config_get_wifi_config()

wifi_config_t * system_config_get_wifi_config ( void  )

Get WiFi configuration.

Returns
wifi_config_t*
Here is the caller graph for this function:

◆ system_config_setup()

esp_err_t system_config_setup ( void  )

Setup system configurations.

  • Configure components using preset values or loaded from NVS before system initialization
  • Setup a periodic timer to save updated parameters
Returns
esp_err_t Setup result
Return values
ESP_OKSetup success
ESP_ERR_INVALID_ARGProvided invalid argument(s)
ESP_ERR_INVALID_STATEConfiguration in invalid state
ESP_ERR_NO_MEMNo available memory for resource allocation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ system_config_setup_defaults()

esp_err_t system_config_setup_defaults ( void  )

Setup default configurations.

Returns
esp_err_t Set result
Return values
ESP_OKSet success
ESP_ERR_INVALID_ARGProvided invalid argument(s)

Must be called before NVS initialization

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ batch_buf

uint8_t batch_buf[BLACKBOX_LOGGER_BATCH_SIZE]
static

Expected batch buffer by Blackbox Logger

◆ global_config

system_config_t global_config
static
Initial value:
= {
.rs485_driver = {.baudrate = CONFIG_RS484_DRIVER_UART_BAUDRATE,
.port = CONFIG_RS484_DRIVER_UART_PORT,
.data_bits = CONFIG_RS484_DRIVER_UART_DATA_BITS,
.parity = CONFIG_RS484_DRIVER_UART_PARITY,
.rx_pin = CONFIG_RS484_DRIVER_UART_RX_PIN,
.rx_buffer_size = RS485_DRIVER_RX_BUFFER_SIZE,
.analyzer = {.rs485_driver_config_ptr = NULL},
.mqtt = {.device_id = CONFIG_MQTT_DEVICE_ID},
.nvs_ops = {.init = nvs_flash_init,
.open = nvs_open,
.read = nvs_get_blob,
.write = nvs_set_blob,
.erase = nvs_flash_erase,
.commit = nvs_commit,
.close = nvs_close,
.deinit = nvs_flash_deinit},
.logger = {.sector_buf_ptr = sector_buf,
.sector_buf_size = sizeof (sector_buf),
.batch_buf_ptr = batch_buf,
.batch_buf_size = sizeof (batch_buf),
.address_align = BLACKBOX_LOGGER_ALIGN,
.flush_timer_timeout_us = BLACKBOX_LOGGER_DISK_FLUSH_TIMEOUT_US,
.write_func = esp_partition_write,
.read_func = esp_partition_read,
.erase_func = esp_partition_erase_range}}
static uint8_t sector_buf[BLACKBOX_LOGGER_SECTOR_SIZE]
Definition system_config.c:35
static uint8_t batch_buf[BLACKBOX_LOGGER_BATCH_SIZE]
Definition system_config.c:37
#define RS485_DRIVER_RX_QUEUE_SIZE
Definition system_config.h:26
#define BLACKBOX_LOGGER_DISK_FLUSH_TIMEOUT_US
Definition system_config.h:43
#define RS485_DRIVER_RX_BUFFER_SIZE
Definition system_config.h:25
#define BLACKBOX_LOGGER_ALIGN
Definition system_config.h:47

System's configurations structure

◆ save_param_timer_handle

esp_timer_handle_t save_param_timer_handle
static

Timer handle for saving parameters

◆ sector_buf

uint8_t sector_buf[BLACKBOX_LOGGER_SECTOR_SIZE]
static

Expected sector buffer by Blackbox Logger

◆ system_config_mqtt_pass

char system_config_mqtt_pass[NVS_MANAGER_MAX_MQTT_PASSWORD_SIZE]
static

Buffer to save MQTT password

◆ system_config_mqtt_uri

char system_config_mqtt_uri[NVS_MANAGER_MAX_MQTT_URI_SIZE]
static

Buffer to save MQTT URI

◆ system_config_mqtt_user

char system_config_mqtt_user[NVS_MANAGER_MAX_MQTT_USER_SIZE]
static

Buffer to save MQTT user

◆ TAG

const char* TAG = "SYSTEM_CONFIG"
static

System config TAG name