From 917354ea70f7c159643f193f1e4e315d92692830 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Tue, 20 Apr 2021 23:12:07 +0800 Subject: [PATCH] update 3rdparty library version and configure parser test ok --- iotd/conf/conf.c | 81 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 74 insertions(+), 7 deletions(-) diff --git a/iotd/conf/conf.c b/iotd/conf/conf.c index 42a2b30..de7ee2e 100644 --- a/iotd/conf/conf.c +++ b/iotd/conf/conf.c @@ -20,10 +20,15 @@ _TYPE_OUTPUT, }; +/* conf format: "{light_indoor:6:0},{light_livroomL:13:0},{light_livroomR:19:0},{light_hallway:26:0}" */ int parser_gpio_info(int type, gpio_t *gpio, char *conf) { + char *ptr; char *pstart; char *pend; + char buf[64]; + int cnt = 0; + int rv = 0; if( !gpio || !conf || strlen(conf)<3 ) { @@ -31,14 +36,74 @@ return -1; } - printf("conf: %s\n", conf); - - pstart = strchr(conf, '{'); - pend = strchr(conf, '}'); + pstart = strchr(conf, '{'); + if( !pstart ) + return 0; + + pend = strchr(pstart, '}'); + + while( pstart && pend ) + { + memset(buf, 0, sizeof(buf)); + + strncpy(buf, pstart+1, pend-pstart-1); + + /* parser and get the GPIO name, BCM pin number, active power level */ + + { + /* check GPIO configure name too long or not */ + ptr = strchr(buf, ':'); + if( !ptr ) + { + log_err("Found invalid GPIO configure: %s\n", buf); + goto NEXT_LOOP; + } + + if( ptr-buf > sizeof(gpio->input[cnt].name) ) + { + log_err("Found GPIO name too long\n", buf); + goto NEXT_LOOP; + } + + /* use sscanf() to parser GPIO configured values */ + if(_TYPE_INPUT == type ) + { + rv = sscanf(buf, "%[^:]:%d:%d", gpio->input[cnt].name, &gpio->input[cnt].pin, &gpio->input[cnt].active_level); + if( 3 == rv) + { + log_nrml("parser GPIO input[%s] BCM[%d] active[%d]\n", gpio->input[cnt].name, gpio->input[cnt].pin, gpio->input[cnt].active_level); + cnt++; + gpio->incnt = cnt; + } + else + { + log_err("Found invalid GPIO configure: %s\n", buf); + } + } + else + { + rv = sscanf(buf, "%[^:]:%d:%d", gpio->output[cnt].name, &gpio->output[cnt].pin, &gpio->output[cnt].active_level); + if( 3 == rv) + { + log_nrml("parser GPIO output[%s] BCM[%d] active[%d]\n", gpio->output[cnt].name, gpio->output[cnt].pin, gpio->output[cnt].active_level); + cnt++; + gpio->outcnt = cnt; + } + else + { + log_err("Found invalid GPIO configure: %s\n", buf); + } + } + } + +NEXT_LOOP: + pstart = strchr(pend, '{'); + if( pstart ) + pend = strchr(pstart, '}'); + } - - + return gpio->outcnt; } int parser_conf(const char *conf_file, iotd_ctx_t *ctx, int debug) @@ -158,7 +223,7 @@ log_nrml("parser SHT2x sensor enabled\n"); } - hal_ctx->ds18b20_enable = iniparser_getint(ini, "hardware:sht2x", 0); + hal_ctx->ds18b20_enable = iniparser_getint(ini, "hardware:ds18b20", 0); if( hal_ctx->ds18b20_enable ) { log_nrml("parser DS18B20 sensor enabled\n"); @@ -208,6 +273,7 @@ mqtt_ctx->subQos = iniparser_getint(ini, "subsciber:subQos", 0); log_nrml("Parser subscriber topic \"%s\" with Qos[%d]\n", mqtt_ctx->subTopic, mqtt_ctx->subQos); + mqtt_ctx->sub_enable = 1; /*+------------------------------------------------------+ *| parser publisher settings | @@ -222,6 +288,7 @@ mqtt_ctx->pubQos = iniparser_getint(ini, "publisher:pubQos", 0); log_nrml("Parser publisher topic \"%s\" with Qos[%d]\n", mqtt_ctx->pubTopic, mqtt_ctx->pubQos); + mqtt_ctx->pub_enable = 1; return 0; -- Gitblit v1.9.1