Implement config read function

This commit is contained in:
2020-10-30 23:12:39 +01:00
parent dcec366b0a
commit 3ca5e41602
2 changed files with 88 additions and 5 deletions

View File

@@ -29,6 +29,7 @@
#define _CONFIG_PARSER_H_
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <fatfs/ff.h>
@@ -37,6 +38,7 @@ struct config_parser {
bool write;
FIL file;
char *buffer;
size_t buff_size;
};
typedef void * config_parser_handle_t;
@@ -44,7 +46,6 @@ typedef void * config_parser_handle_t;
enum config_parser_value_type {
CONFIG_PARSER_TYPE_UINT = 0,
CONFIG_PARSER_TYPE_INT,
CONFIG_PARSER_TYPE_STRING,
CONFIG_PARSER_TYPE_FLOAT,
};
@@ -53,6 +54,7 @@ enum config_parser_ret {
CONFIG_PARSER_PARAM_ERR,
CONFIG_PARSER_GENERIC_ERR,
CONFIG_PARSER_IOERR,
CONFIG_PARSER_LINE_COMMENT,
CONFIG_PARSER_LINE_TOO_LONG,
CONFIG_PARSER_LINE_MALFORM,
CONFIG_PARSER_END_REACHED,
@@ -65,13 +67,12 @@ struct config_parser_entry {
union {
uint32_t uint_val;
int32_t int_val;
const char *string_val;
float float_val;
} value;
};
config_parser_handle_t config_parser_open_file(struct config_parser *config_parser, bool write, const char *file_name,
char *working_buffer);
char *working_buffer, size_t buff_size);
/**
* @brief Parse the current line in the config file.