guowenxue
2021-04-20 917354ea70f7c159643f193f1e4e315d92692830
update 3rdparty library version and configure parser test ok
4 files modified
95 ■■■■ changed files
iotd/3rdlib/build.sh 8 ●●●● patch | view | raw | blame | history
iotd/conf/conf.c 81 ●●●●● patch | view | raw | blame | history
iotd/conf/conf.h 4 ●●● patch | view | raw | blame | history
iotd/hal/gpio.h 2 ●●● patch | view | raw | blame | history
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
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;
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;
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;