From 5126638d46398579c26d3c7bd908fe17b8508b13 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Fri, 19 Feb 2021 18:30:53 +0100 Subject: battery calc and unstable levels --- json/jsonparse.c | 122 ++++--------------------------------------------------- 1 file changed, 9 insertions(+), 113 deletions(-) (limited to 'json/jsonparse.c') diff --git a/json/jsonparse.c b/json/jsonparse.c index 6cfae2e..34587b5 100644 --- a/json/jsonparse.c +++ b/json/jsonparse.c @@ -22,6 +22,10 @@ void json_parse_array(char *json, void *temp, jsmntok_t *t, int r, char type) { int8_t *p = (int8_t*)(intptr_t)temp+sizeof(int8_t)*i; *p = atoi(val); } + if (type == 'f') { + float *p = (float*)(intptr_t)temp+sizeof(float)*i; + *p = atof(val); + } } } } @@ -35,10 +39,13 @@ void json_dump_array (char *str, void *arr, int len, char type) { cur = strlen(str); } if (type == 'c') { - printf("%d\n", ((int8_t*)(intptr_t)(arr))[i]); sprintf(str+cur, "%d", ((int8_t*)(intptr_t)(arr))[i]); cur = strlen(str); } + if (type == 'f') { + sprintf(str+cur, "%f", ((float*)(intptr_t)(arr))[i]); + cur = strlen(str); + } if (i < len-1) { sprintf(str+cur, ", "); cur = strlen(str); } @@ -53,115 +60,4 @@ int json_parse_subtokens (char *json, jsmntok_t *t, int r, int i) { else { break; } } return rt; -} - -/* DEPRECATED TRIALS, delete after backup -// parses a pair set with a set of already parsed tokens -int json_parse_dict_ci_init (char *json, - pair_ci *dict, jsmntok_t *t, int r) { - int obj_i = 0, dict_i = -1; - for (int i=0; i pair set with a set of already parsed tokens -int json_parse_dict_cf_init (char *json, - pair_cf *dict, jsmntok_t *t, int r) { - int obj_i = 0, dict_i = -1; - for (int i=0; i pair set -int json_parse_dict_ci (char *json, pair_ci *dict) { - jsmn_parser p; jsmn_init(&p); - jsmntok_t t[MAXTOKENS]; - int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); - json_parse_dict_ci_init(json, dict, t, r); -} - -// parses a pair set -int json_parse_dict_cf (char *json, pair_cf *dict) { - jsmn_parser p; jsmn_init(&p); - jsmntok_t t[MAXTOKENS]; - int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); - json_parse_dict_cf_init(json, dict, t, r); -} - - - -// parses a list of objects which are lists of pairs -int json_parse_list_ci (char *json, list_ci *list) { - jsmn_parser p; jsmn_init(&p); - jsmntok_t t[MAXTOKENS]; - int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); - int list_i = 0; - for (int i=1; i -int json_parse_list_cf (char *json, list_cf *list) { - jsmn_parser p; jsmn_init(&p); - jsmntok_t t[MAXTOKENS]; - int r = jsmn_parse(&p, json, strlen(json), t, MAXTOKENS); - int list_i = 0; - for (int i=1; i