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 +++++++++++++++++++++++++++++++++++++--- iotd/3rdlib/build.sh | 8 ++-- iotd/hal/gpio.h | 2 iotd/conf/conf.h | 4 + 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/iotd/3rdlib/build.sh b/iotd/3rdlib/build.sh index 86da6c2..b5129c7 100755 --- a/iotd/3rdlib/build.sh +++ b/iotd/3rdlib/build.sh @@ -56,7 +56,7 @@ function compile_libgpiod() { PREFIX_PATH=${INST_PATH} - SRC_NAME=libgpiod-1.6.2 + SRC_NAME=libgpiod-1.6.3 PACK_SUFIX=tar.gz IMG_NAME=libgpiod.so @@ -121,7 +121,7 @@ function compile_mosquitto() { PREFIX_PATH=${INST_PATH} - SRC_NAME=mosquitto-2.0.5 + SRC_NAME=mosquitto-2.0.10 PACK_SUFIX=tar.gz IMG_NAME=libmosquitto.so @@ -160,9 +160,9 @@ if [[ $# == 1 ]] && [[ $1 == clean ]] ; then rm -rf install - rm -rf libgpiod-1.6.2 + rm -rf libgpiod-1.6.3 rm -rf cJSON-1.7.14 - rm -rf mosquitto-2.0.5 + rm -rf mosquitto-2.0.10 exit 0; fi 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; diff --git a/iotd/conf/conf.h b/iotd/conf/conf.h index 00427fd..b905f39 100644 --- a/iotd/conf/conf.h +++ b/iotd/conf/conf.h @@ -43,13 +43,15 @@ int keepalive; /* MQTT broker send PING message to subsciber/publisher keepalive timeout<seconds> */ /* Subscriber settings */ + int sub_enable; /* Subscriber enable or not */ char subTopic[256]; /* Subscriber topic */ int subQos; /* Subscriber Qos */ /* Publisher settings */ + int pub_enable; /* Publisher enable or not */ char pubTopic[256]; /* Publisher topic */ int pubQos; /* Publisher Qos */ - int interval; /* publish interval */ + int interval; /* Publish interval */ } mqtt_ctx_t; diff --git a/iotd/hal/gpio.h b/iotd/hal/gpio.h index eddba34..d1a2a23 100644 --- a/iotd/hal/gpio.h +++ b/iotd/hal/gpio.h @@ -25,7 +25,7 @@ typedef struct gpio_info_s { char name[32]; /* GPIO connected module name */ - int pins; /* GPIO BCM pin number */ + int pin; /* GPIO BCM pin number */ int active_level; /* active power level */ struct gpiod_line *lines; /* gpiod lines */ } gpio_info_t; -- Gitblit v1.9.1