From d3eadc9360f6ebe9214c3fc084fc599b0299c5f4 Mon Sep 17 00:00:00 2001 From: andaesung Date: Thu, 11 May 2017 16:47:00 +0900 Subject: [PATCH] Fix iotbus bugs - applying gpio changed logic. - add iotapi log configs --- framework/src/iotbus/iotapi_evt_handler.c | 10 ++++++++-- framework/src/iotbus/iotbus_gpio.c | 13 +++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/src/iotbus/iotapi_evt_handler.c b/framework/src/iotbus/iotapi_evt_handler.c index 0b296eb..a5ac51a 100644 --- a/framework/src/iotbus/iotapi_evt_handler.c +++ b/framework/src/iotbus/iotapi_evt_handler.c @@ -26,7 +26,12 @@ #include "iotapi_evt_handler.h" #define IOTAPI_QUEUE_SIZE 19 -#define IOTAPI_LOG printf +#ifdef IOTAPI_DEBUG +#define IOTAPI_LOG(format, ...) printf(format, ##__VA_ARGS__) +#else +#define IOTAPI_LOG(x...) +#endif + struct _iotapi_msg_queue { int type; // 1 is insert, 2 is remove, 0 is empty @@ -102,7 +107,8 @@ void *iotapi_handler(void *data) } if (g_ia_evtlist[0].revents & POLLIN) { - int readed = read(g_ia_evtlist[0].fd, buf, 3); + int readed; + readed = read(g_ia_evtlist[0].fd, buf, 3); IOTAPI_LOG("[iotcom] receive command(%d)\n", readed); if (buf[0] == 's' && buf[1] == 't') break; diff --git a/framework/src/iotbus/iotbus_gpio.c b/framework/src/iotbus/iotbus_gpio.c index 878ff1c..26d9b0b 100644 --- a/framework/src/iotbus/iotbus_gpio.c +++ b/framework/src/iotbus/iotbus_gpio.c @@ -71,8 +71,8 @@ iotbus_gpio_context_h iotbus_gpio_open(int gpiopin) { struct _iotbus_gpio_s *dev = (struct _iotbus_gpio_s *)malloc(sizeof(struct _iotbus_gpio_s)); - char gpio_dev[32] = { 0, }; - snprintf(gpio_dev, 32, "/dev/gpio%d", gpiopin); + char gpio_dev[16] = { 0, }; + snprintf(gpio_dev, 16, "/dev/gpio%d", gpiopin); dev->fd = open(gpio_dev, O_RDWR); if (dev->fd < 0) { @@ -301,19 +301,19 @@ int iotbus_gpio_unregister_cb(iotbus_gpio_context_h dev) */ int iotbus_gpio_read(iotbus_gpio_context_h dev) { - int state = 0; + char buf[4]; if (!dev) return IOTBUS_ERROR_INVALID_PARAMETER; - int ret = read(dev->fd, &state, sizeof(int)); + int ret = read(dev->fd, buf, sizeof(buf)); if (ret < 0) return IOTBUS_ERROR_UNKNOWN; ret = lseek(dev->fd, 0, SEEK_SET); if (ret < 0) return IOTBUS_ERROR_UNKNOWN; - return state; + return buf[0] == '1'; } /** @@ -322,6 +322,7 @@ int iotbus_gpio_read(iotbus_gpio_context_h dev) int iotbus_gpio_write(iotbus_gpio_context_h dev, int value) { int ret; + char buf[4]; if (!dev) return IOTBUS_ERROR_INVALID_PARAMETER; @@ -329,7 +330,7 @@ int iotbus_gpio_write(iotbus_gpio_context_h dev, int value) if (value != 0 && value != 1) return IOTBUS_ERROR_INVALID_PARAMETER; - ret = write(dev->fd, &value, sizeof(int)); + ret = write(dev->fd, buf, snprintf(buf, sizeof(buf), "%d", !!value)); if (ret < 0) return IOTBUS_ERROR_UNKNOWN; -- 2.7.4