diff options
author | Joshua Allen <axlecrusher@gmail.com> | 2017-03-06 22:05:02 -0500 |
---|---|---|
committer | Joshua Allen <axlecrusher@gmail.com> | 2017-03-06 22:05:02 -0500 |
commit | 0ebe84be5824202aecfd87ac58005afa76b36be9 (patch) | |
tree | 4590bd233e8d7e205d69d7d7abbd71e6fac502b2 /src | |
parent | 19d18fef008792e8918d4ded2dd7fa015bb2fedb (diff) | |
download | libsurvive-0ebe84be5824202aecfd87ac58005afa76b36be9.tar.gz libsurvive-0ebe84be5824202aecfd87ac58005afa76b36be9.tar.bz2 |
Load strings from config files.
I need to finish the loading of numeric values and arrays.
Diffstat (limited to 'src')
-rw-r--r-- | src/survive_cal.c | 2 | ||||
-rw-r--r-- | src/survive_config.c | 57 | ||||
-rw-r--r-- | src/survive_config.h | 3 |
3 files changed, 60 insertions, 2 deletions
diff --git a/src/survive_cal.c b/src/survive_cal.c index f372309..33d1faa 100644 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -53,7 +53,7 @@ void ootx_packet_clbk_d(ootx_decoder_context *ct, ootx_packet* packet) b->OOTXSet = 1; config_set_lighthouse(b,id); - config_save("config.json"); +// config_save("config.json"); } int survive_cal_get_status( struct SurviveContext * ctx, char * description, int description_length ) diff --git a/src/survive_config.c b/src/survive_config.c index c46e300..d91596f 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -109,6 +109,14 @@ FLT config_read_float(config_group *cg, const char *tag, const FLT def) { config_entry* next_unused_entry(config_group *cg) { config_entry *cv = cg->config_entries + cg->used_entries; assert(cg->used_entries < cg->max_entries); + +/* + if (cg->used_entries >= cg->max_entries) { + cg->max_entries+=10; + cg->config_entries = realloc(cg->config_entries, sizeof(config_entry)*cg->max_entries); + } +*/ + cg->used_entries++; return cv; } @@ -213,3 +221,52 @@ void config_save(const char* path) { fclose(f); } +void print_json_value(char* tag, char** values, uint16_t count) { + uint16_t i = 0; + for (i=0;i<count; ++i) { + printf("%s:%s \n", tag, values[i]); + } +} + +config_group* cg_stack[10]; //handle 10 nested objects deep +uint8_t cg_stack_head = 0; + +void handle_config_group(char* tag) { + cg_stack_head++; + if (strcmp("lighthouse0",tag) == 0) { + cg_stack[cg_stack_head] = lh_config; + } else if (strcmp("lighthouse1",tag) == 0) { + cg_stack[cg_stack_head] = lh_config+1; + } else { + cg_stack[cg_stack_head] = &global_config_values; + } +} + +void pop_config_group() { + cg_stack_head--; +} + +void handle_tag_value(char* tag, char** values, uint16_t count) { + print_json_value(tag,values,count); + config_group* cg = cg_stack[cg_stack_head]; + + //parse out numeric values + + if (count == 1) config_set_str(cg,tag,values[0]); +// else if (count>1) config_set_str +} + +void config_read(const char* path) { + json_begin_object = handle_config_group; + json_end_object = pop_config_group; + json_tag_value = handle_tag_value; + + cg_stack[0] = &global_config_values; + + json_load_file(path); + + json_begin_object = NULL; + json_end_object = NULL; + json_tag_value = NULL; +} + diff --git a/src/survive_config.h b/src/survive_config.h index 14e2fc6..2610e2e 100644 --- a/src/survive_config.h +++ b/src/survive_config.h @@ -37,7 +37,8 @@ extern config_group lh_config[2]; //lighthouse configs void config_init(); -void config_open(const char* path, const char* mode); +//void config_open(const char* path, const char* mode); +void config_read(const char* path); void config_close(); //void config_write_lighthouse(struct BaseStationData* bsd, uint8_t length); void config_set_lighthouse(struct BaseStationData* bsd, uint8_t idx); |