From 4c4969d0cb0f817de2aa866a7d8abfde6ecaff82 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sat, 25 Feb 2017 14:20:28 -0500 Subject: initial commit of config parser --- Makefile | 2 +- src/survive_config.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/survive_config.h | 36 ++++++++++ 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 src/survive_config.c create mode 100644 src/survive_config.h diff --git a/Makefile b/Makefile index 5724274..988394b 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ calibrate : calibrate.c lib/libsurvive.so redist/os_generic.c redist/DrawFuncti lib: mkdir lib -lib/libsurvive.so : src/survive.o src/survive_usb.o src/survive_data.o src/survive_process.o redist/jsmn.o src/ootx_decoder.o $(DEBUGSTUFF) $(CALS) +lib/libsurvive.so : src/survive.o src/survive_usb.o src/survive_data.o src/survive_process.o redist/jsmn.o src/ootx_decoder.o src/survive_config.o $(DEBUGSTUFF) $(CALS) gcc -o $@ $^ $(LDFLAGS) -shared clean : diff --git a/src/survive_config.c b/src/survive_config.c new file mode 100644 index 0000000..42c2c89 --- /dev/null +++ b/src/survive_config.c @@ -0,0 +1,182 @@ +#include +#include +#include "survive_config.h" + +#define MAX_CONFIG_ENTRIES 100 + +config_val config_values[MAX_CONFIG_ENTRIES]; +static uint16_t used_entries = 0; + +static FILE *config_file = NULL; + +void config_init() { + uint16_t i = 0; + for (i=0;i< Joshua Allen, Under MIT/x11 License. + + +#ifndef _SURVIVE_CONFIG_H +#define _SURVIVE_CONFIG_H + +#include "survive_internal.h" + +typedef enum { + CONFIG_UNKNOWN = 0, + CONFIG_FLOAT = 1, + CONFIG_UINT32 = 2, + CONFIG_STRING = 3 +} cval_type; +/* +typedef union { + uint32_t i; + float f; + } Numeric; +*/ +typedef struct { + char *tag; + cval_type type; + union { + uint32_t i; + float f; + } numeric; + char *str; +} config_val; + + +void config_open(const char* path, const char* mode); +void config_close(); +void config_write_lighthouse(struct BaseStationData* bsd, uint8_t length); + +#endif \ No newline at end of file -- cgit v1.2.3 From bf096a3e3dfa67a9776e47eb0e651b46ee4e8319 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sat, 25 Feb 2017 14:25:41 -0500 Subject: use -std=gnu99 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6d44661..dedf4ef 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all : lib data_recorder test calibrate -CFLAGS:=-Iinclude -fPIC -g -O0 -Iredist -flto -DUSE_DOUBLE +CFLAGS:=-Iinclude -fPIC -g -O0 -Iredist -flto -DUSE_DOUBLE -std=gnu99 LDFLAGS:=-lpthread -lusb-1.0 -lz -lX11 -lm -flto -g -- cgit v1.2.3 From 3baabd2f8aa69a986bbb29739e6353d9a95336c5 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sat, 25 Feb 2017 14:34:10 -0500 Subject: float to FLT --- src/survive_config.c | 20 ++++++-------------- src/survive_config.h | 13 +++++++++++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/survive_config.c b/src/survive_config.c index 42c2c89..254e52f 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -19,11 +19,11 @@ void config_init() { used_entries = 0; } -void write_float(char* tag, float x) { +void write_float(char* tag, FLT x) { fprintf(config_file, "\"%s\":\"%f\"\n", tag, x); } -void write_float_a(char* tag, float *x, uint8_t count) { +void write_float_a(char* tag, FLT *x, uint8_t count) { uint8_t i = 0; char idx[4]; for (i=0;i Date: Sat, 25 Feb 2017 15:14:10 -0500 Subject: integer not float --- src/survive_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/survive_config.c b/src/survive_config.c index 254e52f..ed3f6cd 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -163,7 +163,7 @@ void config_save(const char* path) { if (config_values[i].type == CONFIG_FLOAT) { fprintf(f, "\"%s\":\"%F\"\n", config_values[i].tag, config_values[i].numeric.f); } else if (config_values[i].type == CONFIG_UINT32) { - fprintf(f, "\"%s\":\"%F\"\n", config_values[i].tag, config_values[i].numeric.i); + fprintf(f, "\"%s\":\"%d\"\n", config_values[i].tag, config_values[i].numeric.i); } else if (config_values[i].type == CONFIG_STRING) { fprintf(f, "\"%s\":\"%s\"\n", config_values[i].tag, config_values[i].str); } -- cgit v1.2.3