Browse Source

update ...

jiejietop 5 years ago
parent
commit
21966ded19

+ 6 - 6
README.md

@@ -179,12 +179,12 @@ Location:
 ```c
 #define BASE_LEVEL      (0)
 #define ASSERT_LEVEL    (BASE_LEVEL + 1)            /* 日志输出级别:断言级别(非常高优先级) */
-#define ERR_LEVEL       (ASSERT_LEVEL + 1)          /* 日志输出级别:错误级别(高优先级) */
-#define WARN_LEVEL      (ERR_LEVEL + 1)             /* 日志输出级别:警告级别(中优先级) */
-#define INFO_LEVEL      (WARN_LEVEL + 1)            /* 日志输出级别:信息级别(低优先级) */
-#define DEBUG_LEVEL     (INFO_LEVEL + 1)            /* 日志输出级别:调试级别(更低优先级) */
+#define KAWAII_MQTT_ERR_LEVEL       (ASSERT_LEVEL + 1)          /* 日志输出级别:错误级别(高优先级) */
+#define KAWAII_MQTT_WARN_LEVEL      (KAWAII_MQTT_ERR_LEVEL + 1)             /* 日志输出级别:警告级别(中优先级) */
+#define KAWAII_MQTT_INFO_LEVEL      (KAWAII_MQTT_WARN_LEVEL + 1)            /* 日志输出级别:信息级别(低优先级) */
+#define KAWAII_MQTT_DEBUG_LEVEL     (KAWAII_MQTT_INFO_LEVEL + 1)            /* 日志输出级别:调试级别(更低优先级) */
 
-#define         LOG_LEVEL                   WARN_LEVEL      /* 日志输出级别 */
+#define         KAWAII_MQTT_LOG_LEVEL                   KAWAII_MQTT_WARN_LEVEL      /* 日志输出级别 */
 ```
 
 **日志其他选项:**
@@ -321,7 +321,7 @@ mqtt_wait_packet(c, CONNACK, &connect_timer)
 4. 连接成功后创建一个内部线程`mqtt_yield_thread`,并在合适的时候启动它:
 
 ```c
-platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, MQTT_THREAD_STACK_SIZE, MQTT_THREAD_PRIO, MQTT_THREAD_TICK)
+platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, KAWAII_MQTT_THREAD_STACK_SIZE, KAWAII_MQTT_THREAD_PRIO, KAWAII_MQTT_THREAD_TICK)
 
 if (NULL != c->thread) {
     mqtt_set_client_state(c, CLIENT_STATE_CONNECTED);

+ 2 - 1
SConscript

@@ -26,8 +26,9 @@ if GetDepend(['KAWAII_MQTT_NETWORK_TYPE_TLS']):
 
 if GetDepend(['KAWAII_MQTT_LOG_IS_SALOF']):
     src += Glob('common/log/*.c')
+    src += Glob('common/log/arch/rt-thread*.c')
     path += [cwd + '/common/log']
-    
+
 if GetDepend(['PKG_USING_KAWAII_MQTT_TEST']):
     src += Glob('test/*.c')
 

+ 0 - 98
common/log/arch/freertos/arch.c

@@ -1,98 +0,0 @@
-/*
- * @Author: jiejie
- * @Github: https://github.com/jiejieTop
- * @Date: 2019-12-26 19:11:40
- * @LastEditTime : 2019-12-28 01:15:29
- * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
- */
-#include "salof_defconfig.h"
-
-#ifdef USE_LOG
-
-void *salof_alloc(unsigned int size)
-{
-    return pvPortMalloc(size);
-}
-
-
-void salof_free(void *mem)
-{
-    vPortFree(mem);
-}
-
-salof_tcb salof_task_create(const char *name,
-                            void (*task_entry)(void *param),
-                            void * const param,
-                            unsigned int stack_size,
-                            unsigned int priority,
-                            unsigned int tick)
-{
-    salof_tcb task;
-    (void)tick;
-
-    xTaskCreate(task_entry, name, stack_size, param, priority, &task);
-    return task;
-}
-
-salof_mutex salof_mutex_create(void)
-{
-    return xSemaphoreCreateMutex();
-}
-
-
-void salof_mutex_delete(salof_mutex mutex)
-{
-    vSemaphoreDelete(mutex);
-}
-
-
-int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
-{
-    if(xSemaphoreTake(mutex, timeout) != pdPASS)
-        return -1;
-    return 0;
-}
-
-int salof_mutex_post(salof_mutex mutex)
-{
-    if(xSemaphoreGive(mutex) != pdPASS)
-        return -1;
-    return 0;
-}
-
-
-salof_sem salof_sem_create(void)
-{
-    return xSemaphoreCreateBinary();
-}
-
-void salof_sem_delete(salof_sem sem)
-{
-    vSemaphoreDelete(sem);
-}
-
-int salof_sem_pend(salof_sem sem, unsigned int timeout)
-{
-    if(xSemaphoreTake(sem, timeout) != pdPASS)
-        return -1;
-    return 0;
-}
-
-int salof_sem_post(salof_sem sem)
-{
-    if(xSemaphoreGive(sem) != pdPASS)
-        return -1;
-    return 0;
-}
-
-unsigned int salof_get_tick(void)
-{
-    return xTaskGetTickCount();
-}
-
-char *salof_get_task_name(void)
-{
-    return pcTaskGetName(xTaskGetCurrentTaskHandle());
-}
-
-#endif

+ 0 - 22
common/log/arch/linux/CMakeLists.txt

@@ -1,22 +0,0 @@
-aux_source_directory(. CURRENT_DIR_SRCS)
-
-get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
-
-string(REGEX REPLACE ".*/(.*)" "\\1" LIB_NAME ${PARENT_DIR}) 
-
-if (CURRENT_DIR_SRCS)
-    foreach(libname ${LIBNAMES})
-        if (${LIB_NAME} STREQUAL ${libname})
-            add_library(${libname} ${CMAKE_LIB_TYPE} ${CURRENT_DIR_SRCS})
-            find_package("Threads")
-            target_link_libraries(${libname} ${CMAKE_THREAD_LIBS_INIT})
-        endif()
-    endforeach()
-
-else()
-    message(WARNING "not find is src file!")
-endif()
-
-
-
-

+ 0 - 117
common/log/arch/linux/arch.c

@@ -1,117 +0,0 @@
-/*
- * @Author: jiejie
- * @Github: https://github.com/jiejieTop
- * @Date: 2019-12-26 19:11:37
- * @LastEditTime: 2020-02-25 04:01:18
- * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
- */
-#include "salof_defconfig.h"
-
-#ifdef USE_LOG
-
-void *salof_alloc(unsigned int size)
-{
-    return malloc((size_t)size);
-}
-
-void salof_free(void *mem)
-{
-    free(mem);
-}
-
-salof_tcb salof_task_create(const char *name,
-                            void (*task_entry)(void *param),
-                            void * const param,
-                            unsigned int stack_size,
-                            unsigned int priority,
-                            unsigned int tick)
-{
-    int res;
-    salof_tcb task;
-    void *(*__start_routine) (void *);
-
-    __start_routine = (void *(*)(void*))task_entry;
-    task = salof_alloc(sizeof(pthread_t));
-    res = pthread_create(task, NULL, __start_routine, param);
-    if(res != 0) {
-        salof_free(task);
-    }
-
-    return task;
-}
-
-salof_mutex salof_mutex_create(void)
-{
-    salof_mutex mutex;
-    mutex = salof_alloc(sizeof(pthread_mutex_t));
-    
-    if (NULL != mutex)
-	    pthread_mutex_init(mutex, NULL);
-    
-    return mutex;
-}
-
-void salof_mutex_delete(salof_mutex mutex)
-{
-    pthread_mutex_destroy(mutex);
-}
-
-int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
-{
-    if (timeout == 0)
-        return pthread_mutex_trylock(mutex);
-    
-    return pthread_mutex_lock(mutex);
-}
-
-int salof_mutex_post(salof_mutex mutex)
-{
-    return pthread_mutex_unlock(mutex);
-}
-
-salof_sem salof_sem_create(void)
-{
-    salof_sem sem;
-    sem = salof_alloc(sizeof(sem_t));
-    
-    if (NULL != sem)
-	    sem_init(sem, 0, 0);
-    
-    return sem;
-}
-
-void salof_sem_delete(salof_sem sem)
-{
-    sem_destroy(sem);
-}
-
-int salof_sem_pend(salof_sem sem, unsigned int timeout)
-{
-    (void) timeout;
-    return sem_wait(sem);
-}
-
-int salof_sem_post(salof_sem sem)
-{
-    return sem_post(sem);
-}
-
-unsigned int salof_get_tick(void)
-{
-    return (unsigned int)time(NULL);
-}
-
-char *salof_get_task_name(void)
-{
-    return NULL;
-}
-
-
-int send_buff(char *buf, int len)
-{
-    fputs(buf, stdout);
-	fflush(stdout);
-    return len;
-}
-
-#endif

+ 1 - 1
common/log/arch/rt-thread/arch.c

@@ -7,7 +7,7 @@
  */
 #include "config.h"
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
 void *salof_alloc(unsigned int size)
 {

+ 0 - 123
common/log/arch/tencentos-tiny/arch.c

@@ -1,123 +0,0 @@
-/*
- * @Author: jiejie
- * @Github: https://github.com/jiejieTop
- * @Date: 2019-12-26 19:11:34
- * @LastEditTime: 2020-03-02 01:32:23
- * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
- */
-#include "salof_defconfig.h"
-
-#ifdef USE_LOG
-
-void *salof_alloc(unsigned int size)
-{
-    return tos_mmheap_alloc(size);
-}
-
-
-void salof_free(void *mem)
-{
-    tos_mmheap_free(mem);
-}
-
-salof_tcb salof_task_create(const char *name,
-                            void (*task_entry)(void *param),
-                            void * const param,
-                            unsigned int stack_size,
-                            unsigned int priority,
-                            unsigned int tick)
-{
-    salof_tcb task;
-    k_err_t err;
-    k_stack_t *task_stack;
-    task = salof_alloc(sizeof(k_task_t));
-    task_stack = salof_alloc(stack_size);
-    err = tos_task_create(task, 
-                          (char*)name, 
-                          task_entry,
-                          param, 
-                          priority, 
-                          task_stack,
-                          stack_size,
-                          tick);
-    if(err != K_ERR_NONE)
-    {
-        tos_mmheap_free(task);
-        tos_mmheap_free(task_stack);
-    }
-
-    return task;
-}
-
-salof_mutex salof_mutex_create(void)
-{
-    salof_mutex mutex;
-    mutex = salof_alloc(sizeof(k_mutex_t));
-	tos_mutex_create((salof_mutex)mutex);	
-    return mutex;
-}
-
-void salof_mutex_delete(salof_mutex mutex)
-{
-	tos_mutex_destroy((salof_mutex)mutex);
-    tos_mmheap_free(mutex);
-}
-
-
-int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
-{
-
-    if(tos_mutex_pend_timed((salof_mutex)mutex, timeout) != K_ERR_NONE)
-        return -1;
-    return 0;
-}
-
-int salof_mutex_post(salof_mutex mutex)
-{
-    if(tos_mutex_post((salof_mutex)mutex) != K_ERR_NONE)
-        return -1;
-    return 0;
-}
-
-salof_sem salof_sem_create(void)
-{
-    salof_sem sem;
-    sem = salof_alloc(sizeof(k_sem_t));
-	tos_sem_create((salof_sem)sem, 0);	
-    return sem;
-}
-
-void salof_sem_delete(salof_sem sem)
-{
-	tos_sem_destroy((salof_sem)sem);
-    tos_mmheap_free(sem);
-}
-
-
-int salof_sem_pend(salof_sem sem, unsigned int timeout)
-{
-
-    if(tos_sem_pend((salof_sem)sem, timeout) != K_ERR_NONE)
-        return -1;
-    return 0;
-}
-
-int salof_sem_post(salof_sem sem)
-{
-    if(tos_sem_post((salof_sem)sem) != K_ERR_NONE)
-        return -1;
-    return 0;
-}
-
-
-unsigned int salof_get_tick(void)
-{
-    return tos_systick_get();
-}
-
-char *salof_get_task_name(void)
-{
-    return k_curr_task->name;
-}
-
-#endif 

+ 12 - 12
common/log/fifo.c

@@ -1,7 +1,7 @@
 #include "fifo.h"
 #include <string.h>
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
 static unsigned int _flbs(unsigned int x)   /* find last bit set*/
 {
@@ -32,25 +32,25 @@ static unsigned int _flbs(unsigned int x)   /* find last bit set*/
     return r;
 }
 
-static unsigned int _fifo_align(unsigned int x)
+static unsigned int _salof_fifo_align(unsigned int x)
 {
     return (1 << (_flbs(x-1)-1));       //memory down alignment
 }
 
-fifo_t fifo_create(unsigned int size)
+salof_fifo_t salof_fifo_create(unsigned int size)
 {
-    fifo_t fifo;
+    salof_fifo_t fifo;
 
     if (0 == size)
         return NULL;
 
     if (size & (size - 1))
-        size = _fifo_align(size);
+        size = _salof_fifo_align(size);
 
-    fifo = (fifo_t)salof_alloc((sizeof(struct fifo) + size));
+    fifo = (salof_fifo_t)salof_alloc((sizeof(struct salof_fifo) + size));
 
     if (NULL != fifo) {
-        fifo->buff = (unsigned char *)fifo + sizeof(struct fifo);
+        fifo->buff = (unsigned char *)fifo + sizeof(struct salof_fifo);
 
         fifo->mutex = salof_mutex_create();
         fifo->sem = salof_sem_create();
@@ -69,7 +69,7 @@ fifo_t fifo_create(unsigned int size)
     return NULL;
 }
 
-unsigned int fifo_write(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
+unsigned int salof_fifo_write(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
 {
     int err, l;
 
@@ -94,7 +94,7 @@ unsigned int fifo_write(fifo_t fifo, void *buff, unsigned int len, unsigned int
     return len;
 }
 
-unsigned int fifo_read(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
+unsigned int salof_fifo_read(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
 {
     int l;
 
@@ -114,7 +114,7 @@ unsigned int fifo_read(fifo_t fifo, void *buff, unsigned int len, unsigned int t
     return len;
 }
 
-unsigned int fifo_read_able(fifo_t fifo)
+unsigned int salof_fifo_read_able(salof_fifo_t fifo)
 {
     if(NULL == fifo)
         return 0;
@@ -128,9 +128,9 @@ unsigned int fifo_read_able(fifo_t fifo)
     return (fifo->size - (fifo->out - fifo->in));
 }
 
-unsigned int fifo_write_able(fifo_t fifo)
+unsigned int salof_fifo_write_able(salof_fifo_t fifo)
 {
-    return (fifo->size - fifo_read_able(fifo));
+    return (fifo->size - salof_fifo_read_able(fifo));
 }
 
 #endif

+ 9 - 10
common/log/fifo.h

@@ -2,7 +2,7 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-25 23:54:38
- * @LastEditTime: 2020-02-25 08:10:01
+ * @LastEditTime: 2020-06-17 15:10:03
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
 #ifndef _FIFO_H_
@@ -10,7 +10,7 @@
 
 #include "salof_defconfig.h"
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
 #define			FIFO_READ		0
 #define			FIFO_WRITE		1
@@ -18,8 +18,7 @@
 #define 		FIFO_MAX(a,b) (((a) > (b)) ? (a) : (b))
 #define 		FIFO_MIN(a,b) (((a) < (b)) ? (a) : (b))
 
-struct fifo
-{
+struct salof_fifo {
 	unsigned int    size;       /* fifo size */
 	unsigned int    in;         /* data input pointer (in % size) */
 	unsigned int    out;        /* data output pointer (out % size) */
@@ -27,13 +26,13 @@ struct fifo
 	salof_sem		sem;		/* sem */    
 	void            *buff;    /* data area */
 };
-typedef struct fifo * fifo_t;
+typedef struct salof_fifo * salof_fifo_t;
 
-fifo_t fifo_create(unsigned int size);
-unsigned int fifo_write(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
-unsigned int fifo_read(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
-unsigned int fifo_read_able(fifo_t fifo);
-unsigned int fifo_write_able(fifo_t fifo);
+salof_fifo_t salof_fifo_create(unsigned int size);
+unsigned int salof_fifo_write(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
+unsigned int salof_fifo_read(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
+unsigned int salof_fifo_read_able(salof_fifo_t fifo);
+unsigned int salof_fifo_write_able(salof_fifo_t fifo);
 
 #endif
 

+ 11 - 11
common/log/format.c

@@ -2,13 +2,13 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-25 23:54:19
- * @LastEditTime: 2020-02-25 08:12:02
- * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
+ * @LastEditTime: 2020-06-17 15:23:09
+ * @Description: the code belongs to jiejie, please keep the author insalof_formation and source code according to the license.
  */
 #include "format.h"
 #include "salof_defconfig.h"
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
 static int _get_atoi(const char **str)
 {
@@ -36,7 +36,7 @@ static void _buff_put_char(char *buf, unsigned int *pos, unsigned int max, char
  *  width - how many spaces this should have; padding
  *  flags - above F flags
  */
-static void _format_int(char *buf, unsigned int *len, unsigned int maxlen,
+static void _salof_format_int(char *buf, unsigned int *len, unsigned int maxlen,
         signed long long num, int base, int width, int flags)
 {
     char nbuf[64], sign = 0;
@@ -103,7 +103,7 @@ static void _format_int(char *buf, unsigned int *len, unsigned int maxlen,
             _buff_put_char(buf, len, maxlen, pchar);
 }
 
-static void _format_char(char *buf, unsigned int *pos, unsigned int max, char c,
+static void _salof_format_char(char *buf, unsigned int *pos, unsigned int max, char c,
         int width, int flags)
 {
     int npad = 0;
@@ -132,7 +132,7 @@ static unsigned int _str_len(char *s)
     return i;
 }
 
-static void _format_str(char *buf, unsigned int *pos, unsigned int max, char *s,
+static void _salof_format_str(char *buf, unsigned int *pos, unsigned int max, char *s,
         int width, int flags)
 {
     int npad = 0;
@@ -160,7 +160,7 @@ static void _format_str(char *buf, unsigned int *pos, unsigned int max, char *s,
  * Shrinked down, vsnprintf implementation.
  *  This will not handle floating numbers (yet).
  */
-int format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap)
+int salof_format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap)
 {
     unsigned int n = 0;
     char c, *s;
@@ -248,20 +248,20 @@ int format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap)
                 } else if (c == 'b') {
                     base = 2;
                 }
-                _format_int(buf, &n, size, num, base, width, flags);
+                _salof_format_int(buf, &n, size, num, base, width, flags);
             } else if (c == 'p') {
                 num = (size_t) va_arg(ap, void *);
                 base = 16;
                 flags |= F_SMALL | F_ALTERNATE;
-                _format_int(buf, &n, size, num, base, width, flags);
+                _salof_format_int(buf, &n, size, num, base, width, flags);
             } else if (c == 's') {
                 s = va_arg(ap, char *);
                 if (!s)
                     s = "(null)";
-                _format_str(buf, &n, size, s, width, flags);
+                _salof_format_str(buf, &n, size, s, width, flags);
             } else if (c == 'c') {
                 c = va_arg(ap, int);
-                _format_char(buf, &n, size, c, width, flags);
+                _salof_format_char(buf, &n, size, c, width, flags);
             } else if (c == '%') {
                 _buff_put_char(buf, &n, size, c);
             } else {

+ 2 - 2
common/log/format.h

@@ -2,7 +2,7 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-25 23:54:38
- * @LastEditTime: 2020-02-25 07:18:09
+ * @LastEditTime: 2020-06-17 15:22:42
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
 #ifndef _FORMAT_H_
@@ -37,7 +37,7 @@
 
 #define is_digit(c) (c >= '0' && c <= '9')
 
-int format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap);
+int salof_format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap);
 
 
 #endif // !_FORMAT_H_

+ 18 - 18
common/log/salof.c

@@ -2,14 +2,14 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-27 23:10:36
- * @LastEditTime : 2020-01-16 00:37:56
- * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
+ * @LastEditTime: 2020-06-17 15:22:56
+ * @Description: the code belongs to jiejie, please keep the author insalof_formation and source code according to the license.
  */
 /** synchronous asynchronous log output framework */
 
 #include "salof.h"
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
 #ifndef SALOF_BUFF_SIZE
     #define     SALOF_BUFF_SIZE     (1024U)
@@ -20,13 +20,13 @@
 
 static int salof_out(char *buf, int len);
 
-#if USE_SALOF
+#ifdef SALOF_USING_SALOF
 #include <string.h>
-static fifo_t _salof_fifo = NULL;
+static salof_fifo_t _salof_fifo = NULL;
 static int _len;
 static char _out_buff[SALOF_BUFF_SIZE];
 
-#if !USE_IDLE_HOOK
+#if !SALOF_USING_IDLE_HOOK
 static salof_tcb _salof_task;
 void salof_task(void *parm);
 #else
@@ -38,16 +38,16 @@ void salof_task(void *parm);
 #endif
 #endif
 
-static char _format_buff[SALOF_BUFF_SIZE];
+static char _salof_format_buff[SALOF_BUFF_SIZE];
 
 int salof_init(void)
 {
-#if USE_SALOF
-    _salof_fifo = fifo_create(SALOF_FIFO_SIZE);
+#ifdef SALOF_USING_SALOF
+    _salof_fifo = salof_fifo_create(SALOF_FIFO_SIZE);
     if(_salof_fifo == NULL)
         return -1;
 
-#if !USE_IDLE_HOOK
+#if !SALOF_USING_IDLE_HOOK
     _salof_task = salof_task_create("salof_task", salof_task, NULL, SALOF_TASK_STACK_SIZE, SALOF_TASK_PRIO, SALOF_TASK_TICK);
     if(_salof_task == NULL)
         return -1;
@@ -63,15 +63,15 @@ void salof(const char *fmt, ...)
     int len;
     va_start(args, fmt);
 
-    len = format_nstr(_format_buff, SALOF_BUFF_SIZE - 1, fmt, args);
+    len = salof_format_nstr(_salof_format_buff, SALOF_BUFF_SIZE - 1, fmt, args);
 
     if(len > SALOF_BUFF_SIZE)
         len = SALOF_BUFF_SIZE - 1;
 
-#if USE_SALOF
-    fifo_write(_salof_fifo, _format_buff, len, 100);
+#ifdef SALOF_USING_SALOF
+    salof_fifo_write(_salof_fifo, _salof_format_buff, len, 100);
 #else
-    salof_out(_format_buff, len);
+    salof_out(_salof_format_buff, len);
 #endif
 
   va_end(args);
@@ -82,10 +82,10 @@ static int salof_out(char *buf, int len)
     return send_buff(buf, len);
 }
 
-#if USE_SALOF
+#ifdef SALOF_USING_SALOF
 void salof_handler( void )
 {
-    _len = fifo_read(_salof_fifo, _out_buff, sizeof(_out_buff), 0);
+    _len = salof_fifo_read(_salof_fifo, _out_buff, sizeof(_out_buff), 0);
     if(_len > 0) {
         salof_out((char *)_out_buff, _len);
         memset(_out_buff, 0, _len);
@@ -93,13 +93,13 @@ void salof_handler( void )
 }
 #endif
 
-#if !USE_IDLE_HOOK
+#if !SALOF_USING_IDLE_HOOK
 void salof_task(void *parm)
 {   
     (void)parm;
     while(1)
     {
-#if USE_SALOF
+#ifdef SALOF_USING_SALOF
         salof_handler();
 #endif
     } 

+ 61 - 61
common/log/salof.h

@@ -10,103 +10,103 @@ int salof_init(void);
 void salof(const char *fmt, ...);
 
 /** font color */
-#define     FC_BLACK    30       
-#define     FC_RED      31
-#define     FC_GREEN    32
-#define     FC_YELLOW   33
-#define     FC_BLUE     34
-#define     FC_PURPLE   35
-#define     FC_DARK     36
-#define     FC_WHITE    37
-
-#ifdef USE_LOG
-
-#if USE_SALOF
-    #define     PRINT_LOG           salof
+#define     SALOF_FC_BLACK    30       
+#define     SALOF_FC_RED      31
+#define     SALOF_FC_GREEN    32
+#define     SALOF_FC_YELLOW   33
+#define     SALOF_FC_BLUE     34
+#define     SALOF_FC_PURPLE   35
+#define     SALOF_FC_DARK     36
+#define     SALOF_FC_WHITE    37
+
+#ifdef SALOF_USING_LOG
+
+#ifdef SALOF_USING_SALOF
+    #define     SALOF_PRINT_LOG           salof
 #else
 
-#if ((!USE_SALOF)&&(!PRINT_LOG))
-    #define         PRINT_LOG       printf
+#if ((!SALOF_USING_SALOF)&&(!SALOF_PRINT_LOG))
+    #define         SALOF_PRINT_LOG       printf
 #endif
 
-#ifndef PRINT_LOG
-    #error "If the USE_LOG macro definition is turned on, you must define PRINT_LOG as the LOG output, such as #definePRINT_LOG printf"
+#ifndef SALOF_PRINT_LOG
+    #error "If the SALOF_USING_LOG macro definition is turned on, you must define SALOF_PRINT_LOG as the LOG output, such as #definePRINT_LOG printf"
 #endif
 
 #endif
 
-#if LOG_COLOR
-    #define LOG_START(l, c)     PRINT_LOG("\033\n["#c"m["#l"] >> ")
-    #define LOG_END             PRINT_LOG("\033[0m")  
+#if SALOF_LOG_COLOR
+    #define SALOF_LOG_START(l, c)     SALOF_PRINT_LOG("\033\n["#c"m["#l"] >> ")
+    #define SALOF_LOG_END             SALOF_PRINT_LOG("\033[0m")  
 #else
-    #define LOG_START(l, c)     PRINT_LOG("\n["#l"] >> ")
-    #define LOG_END       
+    #define SALOF_LOG_START(l, c)     SALOF_PRINT_LOG("\n["#l"] >> ")
+    #define SALOF_LOG_END       
 #endif
 
-#if LOG_TS && LOG_TAR
-    #define LOG_T           PRINT_LOG("[TS: %d] [TAR: %s] ",salof_get_tick(), salof_get_task_name())
-#elif LOG_TS
-    #define LOG_T           PRINT_LOG("[TS: %d] ", salof_get_tick())
-#elif LOG_TAR
-    #define LOG_T           PRINT_LOG("[TAR: %s] ", salof_get_task_name())
+#if SALOF_LOG_TS && SALOF_LOG_TAR
+    #define SALOF_LOG_T           SALOF_PRINT_LOG("[TS: %d] [TAR: %s] ",salof_get_tick(), salof_get_task_name())
+#elif SALOF_LOG_TS
+    #define SALOF_LOG_T           SALOF_PRINT_LOG("[TS: %d] ", salof_get_tick())
+#elif SALOF_LOG_TAR
+    #define SALOF_LOG_T           SALOF_PRINT_LOG("[TAR: %s] ", salof_get_task_name())
 #else
-    #define LOG_T
+    #define SALOF_LOG_T
 #endif
 
 
-#define LOG_LINE(l, c, fmt, ...)        \
+#define SALOF_LOG_LINE(l, c, fmt, ...)        \
     do {                                \
-        LOG_START(l, c);                \
-        LOG_T;                          \
-        PRINT_LOG(fmt, ##__VA_ARGS__);  \
-        LOG_END;                        \
+        SALOF_LOG_START(l, c);                \
+        SALOF_LOG_T;                          \
+        SALOF_PRINT_LOG(fmt, ##__VA_ARGS__);  \
+        SALOF_LOG_END;                        \
     } while (0)
 
-#define BASE_LEVEL      (0)
-#define ERR_LEVEL       (BASE_LEVEL + 1)
-#define WARN_LEVEL      (ERR_LEVEL + 1)
-#define INFO_LEVEL      (WARN_LEVEL + 1)
-#define DEBUG_LEVEL     (INFO_LEVEL + 1)
+#define SALOF_BASE_LEVEL      (0)
+#define SALOF_ERR_LEVEL       (SALOF_BASE_LEVEL + 1)
+#define SALOF_WARN_LEVEL      (SALOF_ERR_LEVEL + 1)
+#define SALOF_INFO_LEVEL      (SALOF_WARN_LEVEL + 1)
+#define SALOF_DEBUG_LEVEL     (SALOF_INFO_LEVEL + 1)
 
-#ifndef LOG_LEVEL
-    #define LOG_LEVEL   DEBUG_LEVEL
+#ifndef SALOF_LOG_LEVEL
+    #define SALOF_LOG_LEVEL   SALOF_DEBUG_LEVEL
 #endif 
 
-#if LOG_LEVEL < DEBUG_LEVEL
-    #define LOG_DEBUG(fmt, ...)
+#if SALOF_LOG_LEVEL < SALOF_DEBUG_LEVEL
+    #define SALOF_LOG_DEBUG(fmt, ...)
 #else
-    #define LOG_DEBUG(fmt, ...)     LOG_LINE(D, 0, fmt, ##__VA_ARGS__)
+    #define SALOF_LOG_DEBUG(fmt, ...)     SALOF_LOG_LINE(D, 0, fmt, ##__VA_ARGS__)
 #endif
 
-#if LOG_LEVEL < INFO_LEVEL
-    #define LOG_INFO(fmt, ...)
+#if SALOF_LOG_LEVEL < SALOF_INFO_LEVEL
+    #define SALOF_LOG_INFO(fmt, ...)
 #else
-    #define LOG_INFO(fmt, ...)      LOG_LINE(I, FC_GREEN, fmt, ##__VA_ARGS__)
+    #define SALOF_LOG_INFO(fmt, ...)      SALOF_LOG_LINE(I, SALOF_FC_GREEN, fmt, ##__VA_ARGS__)
 #endif
 
-#if LOG_LEVEL < WARN_LEVEL
-    #define LOG_WARN(fmt, ...)
+#if SALOF_LOG_LEVEL < SALOF_WARN_LEVEL
+    #define SALOF_LOG_WARN(fmt, ...)
 #else
-    #define LOG_WARN(fmt, ...)      LOG_LINE(W, FC_YELLOW, fmt, ##__VA_ARGS__)
+    #define SALOF_LOG_WARN(fmt, ...)      SALOF_LOG_LINE(W, SALOF_FC_YELLOW, fmt, ##__VA_ARGS__)
 #endif
 
-#if LOG_LEVEL < ERR_LEVEL
-    #define LOG_ERR(fmt, ...)
+#if SALOF_LOG_LEVEL < SALOF_ERR_LEVEL
+    #define SALOF_LOG_ERR(fmt, ...)
 #else
-    #define LOG_ERR(fmt, ...)       LOG_LINE(E, FC_RED, fmt, ##__VA_ARGS__)
+    #define SALOF_LOG_ERR(fmt, ...)       SALOF_LOG_LINE(E, SALOF_FC_RED, fmt, ##__VA_ARGS__)
 #endif
 
-#if LOG_LEVEL < BASE_LEVEL
-    #define LOG(fmt, ...)
+#if SALOF_LOG_LEVEL < SALOF_BASE_LEVEL
+    #define SALOF_LOG(fmt, ...)
 #else
-    #define LOG(fmt, ...)           PRINT_LOG(fmt, ##__VA_ARGS__)
+    #define SALOF_LOG(fmt, ...)           SALOF_PRINT_LOG(fmt, ##__VA_ARGS__)
 #endif
 #else
-#define LOG_DEBUG(fmt, ...)
-#define LOG_INFO(fmt, ...)
-#define LOG_WARN(fmt, ...)
-#define LOG_ERR(fmt, ...)
-#define LOG(fmt, ...)
+#define SALOF_LOG_DEBUG(fmt, ...)
+#define SALOF_LOG_INFO(fmt, ...)
+#define SALOF_LOG_WARN(fmt, ...)
+#define SALOF_LOG_ERR(fmt, ...)
+#define SALOF_LOG_LOG(fmt, ...)
 #endif
 
 #endif // !_SALOF_H_

+ 1 - 1
common/log/salof_config.h

@@ -9,6 +9,6 @@
 #ifndef _SALOF_CONFIG_H_
 #define _SALOF_CONFIG_H_
 
-#include "mqtt_config.h"
+#include "rtconfig.h"
 
 #endif /* _SALOF_CONFIG_H_ */

+ 26 - 26
common/log/salof_defconfig.h

@@ -2,7 +2,7 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-25 23:56:34
- * @LastEditTime: 2020-04-28 00:46:37
+ * @LastEditTime: 2020-06-17 15:25:04
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
 #ifndef _SALOF_DEFCONFIG_H_
@@ -10,12 +10,12 @@
 
 #include "salof_config.h"
 
-#ifdef USE_LOG
+#ifdef SALOF_USING_LOG
 
-#define         USE_RTT             1
-#define         USE_FREERTOS        2
-#define         USE_TENCENTOS       3
-#define         USE_LINUX           4
+#define         SALOF_USING_RTT             1
+#define         SALOF_USING_FREERTOS        2
+#define         SALOF_USING_TENCENTOS       3
+#define         SALOF_USING_LINUX           4
 
 #define         BASE_LEVEL          (0)
 #define         ERR_LEVEL           (BASE_LEVEL + 1)
@@ -23,31 +23,31 @@
 #define         INFO_LEVEL          (WARN_LEVEL + 1)
 #define         DEBUG_LEVEL         (INFO_LEVEL + 1)
 
-#ifndef USE_SALOF
-    #define         USE_SALOF                   (1U)
+#ifndef SALOF_USING_SALOF
+    #define         SALOF_USING_SALOF                   (1U)
 #endif
 
-#ifndef USE_IDLE_HOOK
-    #define         USE_IDLE_HOOK               (0U)
+#ifndef SALOF_USING_IDLE_HOOK
+    #define         SALOF_USING_IDLE_HOOK               (0U)
 #endif
 
-#ifndef LOG_COLOR
-    #define         LOG_COLOR                   (1U)
+#ifndef SALOF_LOG_COLOR
+    #define         SALOF_LOG_COLOR                     (1U)
 #endif
 
-#ifndef LOG_TS
-    #define         LOG_TS                     (1U)
+#ifndef SALOF_LOG_TS
+    #define         SALOF_LOG_TS                        (1U)
 #endif
 
-#ifndef LOG_TAR
-    #define         LOG_TAR                     (0U)
+#ifndef SALOF_LOG_TAR
+    #define         SALOF_LOG_TAR                       (0U)
 #endif
 
-#ifndef LOG_LEVEL
-#define         LOG_LEVEL                       DEBUG_LEVEL   //WARN_LEVEL DEBUG_LEVEL
+#ifndef SALOF_LOG_LEVEL
+#define         SALOF_LOG_LEVEL                         DEBUG_LEVEL   //WARN_LEVEL DEBUG_LEVEL
 #endif
 
-#if USE_SALOF
+#ifdef SALOF_USING_SALOF
 
 #ifndef SALOF_BUFF_SIZE
     #define         SALOF_BUFF_SIZE             (512U)
@@ -71,27 +71,27 @@
     #error "SALOF_OS isn't defined in 'salof_config.h'"
 #endif
 
-#if (SALOF_OS == USE_FREERTOS)
+#if (SALOF_OS == SALOF_USING_FREERTOS)
     #include "FreeRTOS.h"
     #include "task.h"
     #include "semphr.h"
     #define salof_mutex     SemaphoreHandle_t
     #define salof_tcb       TaskHandle_t
     #define salof_sem       salof_mutex
-#if USE_IDLE_HOOK
+#if SALOF_USING_IDLE_HOOK
     #define salof_handler   vApplicationIdleHook
 #endif  
     #define SALOF_TASK_PRIO (0U)
 
-#elif (SALOF_OS == USE_TENCENTOS)
+#elif (SALOF_OS == SALOF_USING_TENCENTOS)
     #include "tos_k.h"
     #define salof_mutex     k_mutex_t*
     #define salof_sem       k_sem_t*
     #define salof_tcb       k_task_t*
     #define SALOF_TASK_PRIO (TOS_CFG_TASK_PRIO_MAX - 2u)
-    #undef  USE_IDLE_HOOK
+    #undef  SALOF_SALOF_USING_IDLE_HOOK
     
-#elif (SALOF_OS == USE_RTT)
+#elif (SALOF_OS == SALOF_USING_RTT)
     #include <rtconfig.h>
     #include <rtthread.h>
     #include <rthw.h>
@@ -101,7 +101,7 @@
     #define salof_tcb       rt_thread_t
     #define SALOF_TASK_PRIO (RT_THREAD_PRIORITY_MAX - 1)
     
-#elif (SALOF_OS == USE_LINUX)
+#elif (SALOF_OS == SALOF_USING_LINUX)
     #include "pthread.h"
     #include "memory.h"
     #include <semaphore.h>
@@ -111,7 +111,7 @@
     #define salof_sem       sem_t*
     #define salof_tcb       pthread_t*
     #define SALOF_TASK_PRIO (0U)
-    #undef  USE_IDLE_HOOK
+    #undef  SALOF_SALOF_USING_IDLE_HOOK
 
 #else
     #error "not supported OS type"

+ 31 - 31
common/mqtt_error.h

@@ -5,39 +5,39 @@
  * @LastEditTime: 2020-04-27 23:35:05
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
-#ifndef _MQTT_ERROR_H_
-#define _MQTT_ERROR_H_
+#ifndef _KAWAII_MQTT_ERROR_H_
+#define _KAWAII_MQTT_ERROR_H_
 
 typedef enum mqtt_error {
-    MQTT_SSL_CERT_ERROR                                     = -0x001C,      /* cetr parse failed */
-    MQTT_SOCKET_FAILED_ERROR                                = -0x001B,      /* socket fd failed */
-    MQTT_SOCKET_UNKNOWN_HOST_ERROR                          = -0x001A,      /* socket unknown host ip or domain */ 
-    MQTT_SET_PUBLISH_DUP_FAILED_ERROR                       = -0x0019,      /* mqtt publish packet set udp bit failed */
-    MQTT_CLEAN_SESSION_ERROR                                = -0x0018,      /* mqtt clean session error */
-    MQTT_ACK_NODE_IS_EXIST_ERROR                            = -0x0017,      /* mqtt ack list is exist ack node */
-    MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR                     = -0x0016,      /* mqtt ack handler number is too much */
-    MQTT_RESUBSCRIBE_ERROR                                  = -0x0015,      /* mqtt resubscribe error */
-    MQTT_SUBSCRIBE_ERROR                                    = -0x0014,      /* mqtt subscribe error */
-    MQTT_SEND_PACKET_ERROR                                  = -0x0013,      /* mqtt send a packet */
-    MQTT_SERIALIZE_PUBLISH_ACK_PACKET_ERROR                 = -0x0012,      /* mqtt serialize publish ack packet error */
-    MQTT_PUBLISH_PACKET_ERROR                               = -0x0011,      /* mqtt publish packet error */
-    MQTT_RECONNECT_TIMEOUT_ERROR                            = -0x0010,      /* mqtt try reconnect, but timeout */
-    MQTT_SUBSCRIBE_NOT_ACK_ERROR                            = -0x000F,      /* mqtt subscribe, but not ack */
-    MQTT_NOT_CONNECT_ERROR                                  = -0x000E,      /* mqtt not connect */
-    MQTT_SUBSCRIBE_ACK_PACKET_ERROR                         = -0x000D,      /* mqtt subscribe, but ack packet error */
-    MQTT_UNSUBSCRIBE_ACK_PACKET_ERROR                       = -0x000C,      /* mqtt unsubscribe, but ack packet error */
-    MQTT_PUBLISH_ACK_PACKET_ERROR                           = -0x000B,      /* mqtt pubilsh ack packet error */
-    MQTT_PUBLISH_ACK_TYPE_ERROR                             = -0x000A,      /* mqtt pubilsh ack type error */
-    MQTT_PUBREC_PACKET_ERROR                                = -0x0009,      /* mqtt pubrec packet error */
-    MQTT_BUFFER_TOO_SHORT_ERROR                             = -0x0008,      /* mqtt buffer too short */
-    MQTT_NOTHING_TO_READ_ERROR                              = -0x0007,      /* mqtt nothing to read */
-    MQTT_SUBSCRIBE_QOS_ERROR                                = -0x0006,      /* mqtt subsrcibe qos error */
-    MQTT_BUFFER_OVERFLOW_ERROR                              = -0x0005,      /* mqtt buffer overflow */
-    MQTT_CONNECT_FAILED_ERROR                               = -0x0004,      /* mqtt connect failed */
-    MQTT_MEM_NOT_ENOUGH_ERROR                               = -0x0003,      /* mqtt memory not enough */
-    MQTT_NULL_VALUE_ERROR                                   = -0x0002,      /* mqtt value is null */
-    MQTT_FAILED_ERROR                                       = -0x0001,      /* failed */
-    MQTT_SUCCESS_ERROR                                      = 0x0000        /* success */
+    KAWAII_MQTT_SSL_CERT_ERROR                                     = -0x001C,      /* cetr parse failed */
+    KAWAII_MQTT_SOCKET_FAILED_ERROR                                = -0x001B,      /* socket fd failed */
+    KAWAII_MQTT_SOCKET_UNKNOWN_HOST_ERROR                          = -0x001A,      /* socket unknown host ip or domain */ 
+    KAWAII_MQTT_SET_PUBLISH_DUP_FAILED_ERROR                       = -0x0019,      /* mqtt publish packet set udp bit failed */
+    KAWAII_MQTT_CLEAN_SESSION_ERROR                                = -0x0018,      /* mqtt clean session error */
+    KAWAII_MQTT_ACK_NODE_IS_EXIST_ERROR                            = -0x0017,      /* mqtt ack list is exist ack node */
+    KAWAII_MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR                     = -0x0016,      /* mqtt ack handler number is too much */
+    KAWAII_MQTT_RESUBSCRIBE_ERROR                                  = -0x0015,      /* mqtt resubscribe error */
+    KAWAII_MQTT_SUBSCRIBE_ERROR                                    = -0x0014,      /* mqtt subscribe error */
+    KAWAII_MQTT_SEND_PACKET_ERROR                                  = -0x0013,      /* mqtt send a packet */
+    KAWAII_MQTT_SERIALIZE_PUBLISH_ACK_PACKET_ERROR                 = -0x0012,      /* mqtt serialize publish ack packet error */
+    KAWAII_MQTT_PUBLISH_PACKET_ERROR                               = -0x0011,      /* mqtt publish packet error */
+    KAWAII_MQTT_RECONNECT_TIMEOUT_ERROR                            = -0x0010,      /* mqtt try reconnect, but timeout */
+    KAWAII_MQTT_SUBSCRIBE_NOT_ACK_ERROR                            = -0x000F,      /* mqtt subscribe, but not ack */
+    KAWAII_MQTT_NOT_CONNECT_ERROR                                  = -0x000E,      /* mqtt not connect */
+    KAWAII_MQTT_SUBSCRIBE_ACK_PACKET_ERROR                         = -0x000D,      /* mqtt subscribe, but ack packet error */
+    KAWAII_MQTT_UNSUBSCRIBE_ACK_PACKET_ERROR                       = -0x000C,      /* mqtt unsubscribe, but ack packet error */
+    KAWAII_MQTT_PUBLISH_ACK_PACKET_ERROR                           = -0x000B,      /* mqtt pubilsh ack packet error */
+    KAWAII_MQTT_PUBLISH_ACK_TYPE_ERROR                             = -0x000A,      /* mqtt pubilsh ack type error */
+    KAWAII_MQTT_PUBREC_PACKET_ERROR                                = -0x0009,      /* mqtt pubrec packet error */
+    KAWAII_MQTT_BUFFER_TOO_SHORT_ERROR                             = -0x0008,      /* mqtt buffer too short */
+    KAWAII_MQTT_NOTHING_TO_READ_ERROR                              = -0x0007,      /* mqtt nothing to read */
+    KAWAII_MQTT_SUBSCRIBE_QOS_ERROR                                = -0x0006,      /* mqtt subsrcibe qos error */
+    KAWAII_MQTT_BUFFER_OVERFLOW_ERROR                              = -0x0005,      /* mqtt buffer overflow */
+    KAWAII_MQTT_CONNECT_FAILED_ERROR                               = -0x0004,      /* mqtt connect failed */
+    KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR                               = -0x0003,      /* mqtt memory not enough */
+    KAWAII_MQTT_NULL_VALUE_ERROR                                   = -0x0002,      /* mqtt value is null */
+    KAWAII_MQTT_FAILED_ERROR                                       = -0x0001,      /* failed */
+    KAWAII_MQTT_SUCCESS_ERROR                                      = 0x0000        /* success */
 } mqtt_error_t;
 
 #define RETURN_ERROR(x) { return x; }

+ 2 - 2
common/mqtt_list.h

@@ -5,8 +5,8 @@
  * @LastEditTime: 2020-04-27 23:25:37
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
-#ifndef _MQTT_LIST_H_
-#define _MQTT_LIST_H_
+#ifndef _KAWAII_MQTT_LIST_H_
+#define _KAWAII_MQTT_LIST_H_
 
 typedef struct mqtt_list_node {
     struct mqtt_list_node *next;

+ 27 - 27
common/mqtt_log.h

@@ -2,7 +2,7 @@
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
  * @Date: 2019-12-27 03:25:58
- * @LastEditTime: 2020-04-27 23:38:34
+ * @LastEditTime: 2020-06-17 15:26:54
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
 #ifndef _MQTT_LOG_H_
@@ -10,51 +10,51 @@
 
 #include "mqtt_defconfig.h"
 
-#ifdef LOG_IS_SALOF
+#ifdef KAWAII_MQTT_LOG_IS_SALOF
     #include "salof.h"
 
-    #define MQTT_LOG_D(fmt, ...)   LOG_DEBUG(fmt, ##__VA_ARGS__)
-    #define MQTT_LOG_I(fmt, ...)   LOG_INFO(fmt, ##__VA_ARGS__)
-    #define MQTT_LOG_W(fmt, ...)   LOG_WARN(fmt, ##__VA_ARGS__)
-    #define MQTT_LOG_E(fmt, ...)   LOG_ERR(fmt, ##__VA_ARGS__)
+    #define KAWAII_MQTT_LOG_D(fmt, ...)   SALOF_LOG_DEBUG(fmt, ##__VA_ARGS__)
+    #define KAWAII_MQTT_LOG_I(fmt, ...)   SALOF_LOG_INFO(fmt, ##__VA_ARGS__)
+    #define KAWAII_MQTT_LOG_W(fmt, ...)   SALOF_LOG_WARN(fmt, ##__VA_ARGS__)
+    #define KAWAII_MQTT_LOG_E(fmt, ...)   SALOF_LOG_ERR(fmt, ##__VA_ARGS__)
     #define mqtt_log_init   salof_init
 #else
     #include <stdio.h>
     
-    #define BASE_LEVEL      (0)
-    #define ERR_LEVEL       (BASE_LEVEL + 1)
-    #define WARN_LEVEL      (ERR_LEVEL + 1)
-    #define INFO_LEVEL      (WARN_LEVEL + 1)
-    #define DEBUG_LEVEL     (INFO_LEVEL + 1)
-
-#if LOG_LEVEL < DEBUG_LEVEL
-    #define MQTT_LOG_D(fmt, ...)
+    #define KAWAII_MQTT_LOG_BASE_LEVEL      (0)
+    #define KAWAII_MQTT_LOG_ERR_LEVEL       (KAWAII_MQTT_LOG_BASE_LEVEL + 1)
+    #define KAWAII_MQTT_LOG_WARN_LEVEL      (KAWAII_MQTT_LOG_ERR_LEVEL + 1)
+    #define KAWAII_MQTT_LOG_INFO_LEVEL      (KAWAII_MQTT_LOG_WARN_LEVEL + 1)
+    #define KAWAII_MQTT_LOG_DEBUG_LEVEL     (KAWAII_MQTT_LOG_INFO_LEVEL + 1)
+
+#if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_DEBUG_LEVEL
+    #define KAWAII_MQTT_LOG_D(fmt, ...)
 #else
-    #define MQTT_LOG_D(fmt, ...)     { printf(fmt, ##__VA_ARGS__); printf("\n");}
+    #define KAWAII_MQTT_LOG_D(fmt, ...)        { printf(fmt, ##__VA_ARGS__); printf("\n");}
 #endif
 
-#if LOG_LEVEL < INFO_LEVEL
-    #define MQTT_LOG_I(fmt, ...)
+#if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_INFO_LEVEL
+    #define KAWAII_MQTT_LOG_I(fmt, ...)
 #else
-    #define MQTT_LOG_I(fmt, ...)      { printf(fmt, ##__VA_ARGS__); printf("\n");}
+    #define KAWAII_MQTT_LOG_I(fmt, ...)        { printf(fmt, ##__VA_ARGS__); printf("\n");}
 #endif
 
-#if LOG_LEVEL < WARN_LEVEL
-    #define MQTT_LOG_W(fmt, ...)
+#if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_WARN_LEVEL
+    #define KAWAII_MQTT_LOG_W(fmt, ...)
 #else
-    #define MQTT_LOG_W(fmt, ...)      { printf(fmt, ##__VA_ARGS__); printf("\n");}
+    #define KAWAII_MQTT_LOG_W(fmt, ...)        { printf(fmt, ##__VA_ARGS__); printf("\n");}
 #endif
 
-#if LOG_LEVEL < ERR_LEVEL
-    #define MQTT_LOG_E(fmt, ...)
+#if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_ERR_LEVEL
+    #define KAWAII_MQTT_LOG_E(fmt, ...)
 #else
-    #define MQTT_LOG_E(fmt, ...)       { printf(fmt, ##__VA_ARGS__); printf("\n");}
+    #define KAWAII_MQTT_LOG_E(fmt, ...)        { printf(fmt, ##__VA_ARGS__); printf("\n");}
 #endif
 
-#if LOG_LEVEL < BASE_LEVEL
-    #define MQTT_LOG(fmt, ...)
+#if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_BASE_LEVEL
+    #define KAWAII_MQTT_LOG(fmt, ...)
 #else
-    #define MQTT_LOG(fmt, ...)           { printf(fmt, ##__VA_ARGS__); printf("\n");}
+    #define KAWAII_MQTT_LOG(fmt, ...)          { printf(fmt, ##__VA_ARGS__); printf("\n");}
 #endif
 
     #define mqtt_log_init()

+ 4 - 4
docs/mqtt-aliyun.md

@@ -271,9 +271,9 @@ message:welcome to mqttclient, this is a publish test, a rand number: 758576923
 static void topic1_handler(void* client, message_data_t* msg)
 {
     (void) client;
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
-    MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
 }
 
 void *mqtt_publish_thread(void *arg)
@@ -323,7 +323,7 @@ int main(void)
     
     res = pthread_create(&thread1, NULL, mqtt_publish_thread, client);
     if(res != 0) {
-        MQTT_LOG_E("create mqtt publish thread fail");
+        KAWAII_MQTT_LOG_E("create mqtt publish thread fail");
         exit(res);
     }
 

+ 4 - 4
docs/mqtt-baidu.md

@@ -269,9 +269,9 @@ static const char *test_baidu_ca_crt = {
 static void topic1_handler(void* client, message_data_t* msg)
 {
     (void) client;
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
-    MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
 }
 
 void *mqtt_publish_thread(void *arg)
@@ -327,7 +327,7 @@ int main(void)
     
     res = pthread_create(&thread1, NULL, mqtt_publish_thread, client);
     if(res != 0) {
-        MQTT_LOG_E("create mqtt publish thread fail");
+        KAWAII_MQTT_LOG_E("create mqtt publish thread fail");
         exit(res);
     }
 

+ 51 - 51
docs/mqtt-config.md

@@ -1,134 +1,134 @@
 
 # mqttclient配置及裁剪工具
 
-- MQTT_TOPIC_LEN_MAX
+- KAWAII_MQTT_TOPIC_LEN_MAX
 
     配置客户端支持最大的主题名长度,主题是支持通配符的,如果主题太长则会被截断,默认值为64。
 
     ```c
-        #define     MQTT_TOPIC_LEN_MAX                  64
+        #define     KAWAII_MQTT_TOPIC_LEN_MAX                  64
     ```
 
-- MQTT_ACK_HANDLER_NUM_MAX
+- KAWAII_MQTT_ACK_HANDLER_NUM_MAX
 
     配置mqtt等待应答列表的最大记录个数,对于qos1、qos2服务质量有要求的可以将其设置大一点,当然也必须资源跟得上,它主要是保证qos1、qos2的mqtt报文能准确到达服务器,默认值为64。
 
     ```c
-        #define     MQTT_ACK_HANDLER_NUM_MAX            64
+        #define     KAWAII_MQTT_ACK_HANDLER_NUM_MAX            64
     ```
 
-- MQTT_DEFAULT_BUF_SIZE
+- KAWAII_MQTT_DEFAULT_BUF_SIZE
 
     默认的读写数据缓冲区的大小,根据要收发数据量修改即可,默认值为1024。
 
     ```c
-        #define     MQTT_DEFAULT_BUF_SIZE               1024
+        #define     KAWAII_MQTT_DEFAULT_BUF_SIZE               1024
     ```
 
-- MQTT_DEFAULT_CMD_TIMEOUT
+- KAWAII_MQTT_DEFAULT_CMD_TIMEOUT
 
     默认的命令超时,它主要是用于socket读写超时(还包括等待响应的时间、重连等待时间等),默认值为5000。
 
     ```c
-        #define     MQTT_DEFAULT_CMD_TIMEOUT            5000
+        #define     KAWAII_MQTT_DEFAULT_CMD_TIMEOUT            5000
     ```
 
-- MQTT_MAX_CMD_TIMEOUT
+- KAWAII_MQTT_MAX_CMD_TIMEOUT
 
     设置最大的命令超时时间,默认值是20000。
 
     ```c
-        #define     MQTT_MAX_CMD_TIMEOUT                20000
+        #define     KAWAII_MQTT_MAX_CMD_TIMEOUT                20000
     ```
 
-- MQTT_MIN_CMD_TIMEOUT
+- KAWAII_MQTT_MIN_CMD_TIMEOUT
 
     设置最小的命令超时时间,默认值是1000。
 
     ```c
-        #define     MQTT_MIN_CMD_TIMEOUT                1000
+        #define     KAWAII_MQTT_MIN_CMD_TIMEOUT                1000
     ```
 
-- MQTT_KEEP_ALIVE_INTERVAL
+- KAWAII_MQTT_KEEP_ALIVE_INTERVAL
 
     设置默认的保活时间,它主要是保证MQTT客户端与服务器的保持活性连接,单位为**秒**,默认值为50。比如MQTT客户端与服务器在指定时间间隔内没有发送数据,有没有接收到数据,此时MQTT客户端会发送一个心跳包,确认一下这个连接是否存在,如果收到服务器的应答,那么说明这个连接还是存在的,可以随时收发数据,而如果不存在了,就尝试重连或者清除会话。
 
     ```c
-        #define     MQTT_KEEP_ALIVE_INTERVAL            50         // unit: second
+        #define     KAWAII_MQTT_KEEP_ALIVE_INTERVAL            50         // unit: second
     ```
 
-- MQTT_VERSION
+- KAWAII_MQTT_VERSION
 
     选择MQTT协议的版本,默认为4,表示使用MQTT 3.1.1版本,而3则表示使用MQTT 3.1版本。
 
     ```c
-        #define     MQTT_VERSION                        4           // 4 is mqtt 3.1.1
+        #define     KAWAII_MQTT_VERSION                        4           // 4 is mqtt 3.1.1
     ```
 
-- MQTT_RECONNECT_DEFAULT_DURATION
+- KAWAII_MQTT_RECONNECT_DEFAULT_DURATION
 
     设置默认的重连时间间隔,当发生掉线时,会以这个时间间隔尝试重连,默认值为1000。
 
     ```c
-        #define     MQTT_RECONNECT_DEFAULT_DURATION     1000
+        #define     KAWAII_MQTT_RECONNECT_DEFAULT_DURATION     1000
     ```
 
-- MQTT_THREAD_STACK_SIZE
+- KAWAII_MQTT_THREAD_STACK_SIZE
 
-    MQTT内部维护一个线程,需要设置默认的线程属性信息,MQTT_THREAD_STACK_SIZE表示线程栈的大小,默认值是2048。在linux环境下可以是不需要理会这些参数的,而在RTOS平台则需要配置,如果不使用mbedtls,线程栈2048字节已足够,而使用mbedtls加密后,需要配置4096字节以上
+    MQTT内部维护一个线程,需要设置默认的线程属性信息,KAWAII_MQTT_THREAD_STACK_SIZE表示线程栈的大小,默认值是2048。在linux环境下可以是不需要理会这些参数的,而在RTOS平台则需要配置,如果不使用mbedtls,线程栈2048字节已足够,而使用mbedtls加密后,需要配置4096字节以上
 
     ```c
-        #define     MQTT_THREAD_STACK_SIZE              2048    // 线程栈
+        #define     KAWAII_MQTT_THREAD_STACK_SIZE              2048    // 线程栈
     ```
 
-- MQTT_THREAD_PRIO
+- KAWAII_MQTT_THREAD_PRIO
 
     设置线程优先级,默认为5。
 
     ```c
-        #define     MQTT_THREAD_PRIO                    5       // 线程优先级
+        #define     KAWAII_MQTT_THREAD_PRIO                    5       // 线程优先级
     ```
 
-- MQTT_THREAD_TICK
+- KAWAII_MQTT_THREAD_TICK
 
     设置线程优时间片,默认为50。
 
     ```c
-        #define     MQTT_THREAD_TICK                    50      // 线程时间片
+        #define     KAWAII_MQTT_THREAD_TICK                    50      // 线程时间片
     ```
 
-- MQTT_NETWORK_TYPE_NO_TLS
+- KAWAII_MQTT_NETWORK_TYPE_NO_TLS
 
     设置是否需要支持TLS加密传输,如果定义了该宏,则表示不支持TLS加密传输,否则默认将支持TLS加密传输。
 
     ```c
-        #define     MQTT_NETWORK_TYPE_NO_TLS
+        #define     KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     ```
 
 # salof相关的配置
 
 [salof](https://github.com/jiejieTop/salof) 全称是:**Synchronous Asynchronous Log Output Framework**(同步异步日志输出框架),它是一个同步异步日志输出框架,可以在空闲时候输出对应的日志信息,并且该库与mqttclient无缝衔接。
 
-- LOG_LEVEL
+- KAWAII_MQTT_LOG_LEVEL
   
     配置对应的日志输出级别,它支持以下4种级别:ERR_LEVEL、WARN_LEVEL、INFO_LEVEL、DEBUG_LEVEL。
 
     ```c
         #define BASE_LEVEL      (0)
-        #define ERR_LEVEL       (BASE_LEVEL + 1)          /* 日志输出级别:错误级别(高优先级) */
-        #define WARN_LEVEL      (ERR_LEVEL + 1)             /* 日志输出级别:警告级别(中优先级) */
-        #define INFO_LEVEL      (WARN_LEVEL + 1)            /* 日志输出级别:信息级别(低优先级) */
-        #define DEBUG_LEVEL     (INFO_LEVEL + 1)            /* 日志输出级别:调试级别(更低优先级) */
+        #define KAWAII_MQTT_ERR_LEVEL       (BASE_LEVEL + 1)          /* 日志输出级别:错误级别(高优先级) */
+        #define KAWAII_MQTT_WARN_LEVEL      (KAWAII_MQTT_ERR_LEVEL + 1)             /* 日志输出级别:警告级别(中优先级) */
+        #define KAWAII_MQTT_INFO_LEVEL      (KAWAII_MQTT_WARN_LEVEL + 1)            /* 日志输出级别:信息级别(低优先级) */
+        #define KAWAII_MQTT_DEBUG_LEVEL     (KAWAII_MQTT_INFO_LEVEL + 1)            /* 日志输出级别:调试级别(更低优先级) */
 
-        #define         LOG_LEVEL                   WARN_LEVEL      /* 日志输出级别 */
+        #define         KAWAII_MQTT_LOG_LEVEL                   KAWAII_MQTT_WARN_LEVEL      /* 日志输出级别 */
     ```
 
-- USE_SALOF
+- KAWAII_MQTT_USE_SALOF
 
     如果该宏大于0,则表示使用salof指定的后端作为日志输出,反之则使用printf作为日志输出接口。
 
     ```c
-        #define         USE_SALOF                   (1U)
+        #define         KAWAII_MQTT_USE_SALOF                   (1U)
     ```
 
 - SALOF_OS
@@ -139,68 +139,68 @@
         #define         SALOF_OS                    USE_LINUX
     ```
 
-- USE_IDLE_HOOK
+- KAWAII_MQTT_USE_IDLE_HOOK
 
     如果该宏大于0,则表示在操作系统中的空闲钩子函数中输出日志,反之则通过线程异步处理或者同步处理。
 
     ```c
-        #define         USE_IDLE_HOOK               (0U)
+        #define         KAWAII_MQTT_USE_IDLE_HOOK               (0U)
     ```
 
-- LOG_COLOR
+- KAWAII_MQTT_LOG_COLOR
 
     如果该宏大于0,则表示输出的日志是带有颜色的(需要终端的支持),反之则没有颜色。
 
     ```c
-        #define         LOG_COLOR                   (1U)
+        #define         KAWAII_MQTT_LOG_COLOR                   (1U)
     ```
 
-- LOG_TS
+- KAWAII_MQTT_LOG_TS
 
     如果该宏大于0,则表示输出的日志是带有时间戳的,反之则没有时间戳。
 
     ```c
-        #define         LOG_TS                   (0U)
+        #define         KAWAII_MQTT_LOG_TS                   (0U)
     ```
 
-- LOG_TAR
+- KAWAII_MQTT_LOG_TAR
 
     如果该宏大于0,则表示输出的日志是带有标签的(任务名字),反之则没有标签。
 
     ```c
-        #define         LOG_TAR                   (0U)
+        #define         KAWAII_MQTT_LOG_TAR                   (0U)
     ```
 
-- SALOF_BUFF_SIZE
+- KAWAII_MQTT_SALOF_BUFF_SIZE
 
     设置日志库salof输出库的buf缓冲区大小,即最大一次性能输出多少个字节。
 
     ```c
-        #define         SALOF_BUFF_SIZE                   (512U)
+        #define         KAWAII_MQTT_SALOF_BUFF_SIZE                   (512U)
     ```
 
-- SALOF_FIFO_SIZE
+- KAWAII_MQTT_SALOF_FIFO_SIZE
 
     设置日志库salof的fifo缓冲区大小,即最能缓存多少个字节的日志数据。
 
     ```c
-            #define         SALOF_FIFO_SIZE             (1024*4U)
+            #define         KAWAII_MQTT_SALOF_FIFO_SIZE             (1024*4U)
     ```
 
-- SALOF_TASK_STACK_SIZE
+- KAWAII_MQTT_SALOF_TASK_STACK_SIZE
 
     如果使用了空闲线程输出日志,则配置salof线程栈的大小。
 
     ```c
-        #define         SALOF_TASK_STACK_SIZE       (2048U)
+        #define         KAWAII_MQTT_SALOF_TASK_STACK_SIZE       (2048U)
     ```
 
-- SALOF_TASK_TICK
+- KAWAII_MQTT_SALOF_TASK_TICK
 
     如果使用了空闲线程输出日志,则配置salof线程栈的时间片大小。
 
     ```c
-        #define         SALOF_TASK_TICK             (50U)
+        #define         KAWAII_MQTT_SALOF_TASK_TICK             (50U)
     ```
 
 # 使用mqttclient裁剪配置工具

+ 20 - 20
docs/mqtt-design.md

@@ -144,9 +144,9 @@ mqtt_release()
 通过宏定义去统一设置MQTT客户端结构**mqtt_client_t**的信息,定义如下:
 
 ```c
-#define MQTT_CLIENT_SET_DEFINE(name, type, res)         \
+#define KAWAII_MQTT_CLIENT_SET_DEFINE(name, type, res)         \
     type mqtt_set_##name(mqtt_client_t *c, type t) {    \
-        MQTT_ROBUSTNESS_CHECK((c), res);                \
+        KAWAII_MQTT_ROBUSTNESS_CHECK((c), res);                \
         c->mqtt_##name = t;                             \
         return c->mqtt_##name;                          \
     }
@@ -155,23 +155,23 @@ mqtt_release()
 由编译器预处理得到相关的函数:**mqtt_set_xxx()**。
 
 ```c
-MQTT_CLIENT_SET_DEFINE(client_id, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(user_name, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(password, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(host, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(port, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(ca, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(reconnect_data, void*, NULL)
-MQTT_CLIENT_SET_DEFINE(keep_alive_interval, uint16_t, 0)
-MQTT_CLIENT_SET_DEFINE(will_flag, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(clean_session, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(version, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(cmd_timeout, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(read_buf_size, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(write_buf_size, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(reconnect_try_duration, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(reconnect_handler, reconnect_handler_t, NULL)
-MQTT_CLIENT_SET_DEFINE(interceptor_handler, interceptor_handler_t, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(client_id, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(user_name, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(password, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(host, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(port, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(ca, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_data, void*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(keep_alive_interval, uint16_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(will_flag, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(clean_session, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(version, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(cmd_timeout, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(read_buf_size, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(write_buf_size, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_try_duration, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_handler, reconnect_handler_t, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(interceptor_handler, interceptor_handler_t, NULL)
 ```
 
 ## 连接服务器
@@ -207,7 +207,7 @@ int mqtt_connect(mqtt_client_t* c);
 
     ```c
     /* connect success, and need init mqtt thread */
-    c->mqtt_thread= platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, MQTT_THREAD_STACK_SIZE, MQTT_THREAD_PRIO, MQTT_THREAD_TICK);
+    c->mqtt_thread= platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, KAWAII_MQTT_THREAD_STACK_SIZE, KAWAII_MQTT_THREAD_PRIO, KAWAII_MQTT_THREAD_TICK);
 
     if (NULL != c->mqtt_thread) {
         mqtt_set_client_state(c, CLIENT_STATE_CONNECTED);

+ 4 - 4
docs/mqtt-onenet.md

@@ -186,9 +186,9 @@ extern const char *test_ca_get();
 static void interceptor_handler(void* client, message_data_t* msg)
 {
     (void) client;
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
-    MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
-    MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
 }
 
 void *mqtt_publish_thread(void *arg)
@@ -236,7 +236,7 @@ int main(void)
     
     res = pthread_create(&thread1, NULL, mqtt_publish_thread, client);
     if(res != 0) {
-        MQTT_LOG_E("create mqtt publish thread fail");
+        KAWAII_MQTT_LOG_E("create mqtt publish thread fail");
         exit(res);
     }
 

+ 6 - 6
mqtt/MQTTConnect.h

@@ -22,12 +22,12 @@
 
 enum connack_return_codes
 {
-    MQTT_CONNECTION_ACCEPTED = 0,
-    MQTT_UNNACCEPTABLE_PROTOCOL = 1,
-    MQTT_CLIENTID_REJECTED = 2,
-    MQTT_SERVER_UNAVAILABLE = 3,
-    MQTT_BAD_USERNAME_OR_PASSWORD = 4,
-    MQTT_NOT_AUTHORIZED = 5,
+    KAWAII_MQTT_CONNECTION_ACCEPTED = 0,
+    KAWAII_MQTT_UNNACCEPTABLE_PROTOCOL = 1,
+    KAWAII_MQTT_CLIENTID_REJECTED = 2,
+    KAWAII_MQTT_SERVER_UNAVAILABLE = 3,
+    KAWAII_MQTT_BAD_USERNAME_OR_PASSWORD = 4,
+    KAWAII_MQTT_NOT_AUTHORIZED = 5,
 };
 
 #if !defined(DLLImport)

+ 2 - 2
mqtt/MQTTFormat.c

@@ -114,7 +114,7 @@ int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup,
 }
 
 
-#if defined(MQTT_CLIENT)
+#if defined(KAWAII_MQTT_CLIENT)
 char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen)
 {
 	int index = 0;
@@ -184,7 +184,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
 }
 #endif
 
-#if defined(MQTT_SERVER)
+#if defined(KAWAII_MQTT_SERVER)
 char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen)
 {
 	int index = 0;

+ 45 - 45
mqttclient/mqtt_defconfig.h

@@ -9,66 +9,66 @@
 #ifndef _DEFCONFIG_H_
 #define _DEFCONFIG_H_
 
-#include "mqtt_config.h"
+#include "rtconfig.h"
 
-#ifndef MQTT_MAX_PACKET_ID
-    #define     MQTT_MAX_PACKET_ID                  (0xFFFF - 1)
-#endif // !MQTT_MAX_PACKET_ID
+#ifndef KAWAII_MQTT_MAX_PACKET_ID
+    #define     KAWAII_MQTT_MAX_PACKET_ID                  (0xFFFF - 1)
+#endif // !KAWAII_MQTT_MAX_PACKET_ID
 
-#ifndef MQTT_TOPIC_LEN_MAX
-    #define     MQTT_TOPIC_LEN_MAX                  64
-#endif // !MQTT_TOPIC_LEN_MAX
+#ifndef KAWAII_MQTT_TOPIC_LEN_MAX
+    #define     KAWAII_MQTT_TOPIC_LEN_MAX                  64
+#endif // !KAWAII_MQTT_TOPIC_LEN_MAX
 
-#ifndef MQTT_ACK_HANDLER_NUM_MAX
-    #define     MQTT_ACK_HANDLER_NUM_MAX            64
-#endif // !MQTT_ACK_HANDLER_NUM_MAX
+#ifndef KAWAII_MQTT_ACK_HANDLER_NUM_MAX
+    #define     KAWAII_MQTT_ACK_HANDLER_NUM_MAX            64
+#endif // !KAWAII_MQTT_ACK_HANDLER_NUM_MAX
 
-#ifndef MQTT_DEFAULT_BUF_SIZE
-    #define     MQTT_DEFAULT_BUF_SIZE               1024
-#endif // !MQTT_DEFAULT_BUF_SIZE
+#ifndef KAWAII_MQTT_DEFAULT_BUF_SIZE
+    #define     KAWAII_MQTT_DEFAULT_BUF_SIZE               1024
+#endif // !KAWAII_MQTT_DEFAULT_BUF_SIZE
 
-#ifndef MQTT_DEFAULT_CMD_TIMEOUT
-    #define     MQTT_DEFAULT_CMD_TIMEOUT            4000
-#endif // !MQTT_DEFAULT_CMD_TIMEOUT
+#ifndef KAWAII_MQTT_DEFAULT_CMD_TIMEOUT
+    #define     KAWAII_MQTT_DEFAULT_CMD_TIMEOUT            4000
+#endif // !KAWAII_MQTT_DEFAULT_CMD_TIMEOUT
 
-#ifndef MQTT_MAX_CMD_TIMEOUT
-    #define     MQTT_MAX_CMD_TIMEOUT                20000
-#endif // !MQTT_MAX_CMD_TIMEOUT
+#ifndef KAWAII_MQTT_MAX_CMD_TIMEOUT
+    #define     KAWAII_MQTT_MAX_CMD_TIMEOUT                20000
+#endif // !KAWAII_MQTT_MAX_CMD_TIMEOUT
 
-#ifndef MQTT_MIN_CMD_TIMEOUT
-    #define     MQTT_MIN_CMD_TIMEOUT                1000
-#endif // !MQTT_MIN_CMD_TIMEOUT
+#ifndef KAWAII_MQTT_MIN_CMD_TIMEOUT
+    #define     KAWAII_MQTT_MIN_CMD_TIMEOUT                1000
+#endif // !KAWAII_MQTT_MIN_CMD_TIMEOUT
 
-#ifndef MQTT_KEEP_ALIVE_INTERVAL
-    #define     MQTT_KEEP_ALIVE_INTERVAL            100      // unit: second
-#endif // !MQTT_KEEP_ALIVE_INTERVAL
+#ifndef KAWAII_MQTT_KEEP_ALIVE_INTERVAL
+    #define     KAWAII_MQTT_KEEP_ALIVE_INTERVAL            100      // unit: second
+#endif // !KAWAII_MQTT_KEEP_ALIVE_INTERVAL
 
-#ifndef MQTT_VERSION
-    #define     MQTT_VERSION                        4      // 4 is mqtt 3.1.1
-#endif // !MQTT_VERSION
+#ifndef KAWAII_MQTT_VERSION
+    #define     KAWAII_MQTT_VERSION                        4      // 4 is mqtt 3.1.1
+#endif // !KAWAII_MQTT_VERSION
 
-#ifndef MQTT_RECONNECT_DEFAULT_DURATION
-    #define     MQTT_RECONNECT_DEFAULT_DURATION     1000
-#endif // !MQTT_RECONNECT_DEFAULT_DURATION
+#ifndef KAWAII_MQTT_RECONNECT_DEFAULT_DURATION
+    #define     KAWAII_MQTT_RECONNECT_DEFAULT_DURATION     1000
+#endif // !KAWAII_MQTT_RECONNECT_DEFAULT_DURATION
 
-#ifndef MQTT_THREAD_STACK_SIZE
-    #define     MQTT_THREAD_STACK_SIZE              4096
-#endif // !MQTT_THREAD_STACK_SIZE
+#ifndef KAWAII_MQTT_THREAD_STACK_SIZE
+    #define     KAWAII_MQTT_THREAD_STACK_SIZE              4096
+#endif // !KAWAII_MQTT_THREAD_STACK_SIZE
 
-#ifndef MQTT_THREAD_PRIO
-    #define     MQTT_THREAD_PRIO                    5
-#endif // !MQTT_THREAD_PRIO
+#ifndef KAWAII_MQTT_THREAD_PRIO
+    #define     KAWAII_MQTT_THREAD_PRIO                    5
+#endif // !KAWAII_MQTT_THREAD_PRIO
 
-#ifndef MQTT_THREAD_TICK
-    #define     MQTT_THREAD_TICK                    50
-#endif // !MQTT_THREAD_TICK
+#ifndef KAWAII_MQTT_THREAD_TICK
+    #define     KAWAII_MQTT_THREAD_TICK                    50
+#endif // !KAWAII_MQTT_THREAD_TICK
 
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
 
-#ifndef MQTT_TLS_HANDSHAKE_TIMEOUT
-    #define MQTT_TLS_HANDSHAKE_TIMEOUT  (5 * 1000)
-#endif // !MQTT_TLS_HANDSHAKE_TIMEOUT
+#ifndef KAWAII_MQTT_TLS_HANDSHAKE_TIMEOUT
+    #define KAWAII_MQTT_TLS_HANDSHAKE_TIMEOUT  (5 * 1000)
+#endif // !KAWAII_MQTT_TLS_HANDSHAKE_TIMEOUT
     
     #include "mbedtls/config.h"
     #include "mbedtls/ssl.h"
@@ -77,6 +77,6 @@
     #include "mbedtls/ctr_drbg.h"
     #include "mbedtls/error.h"
     #include "mbedtls/debug.h"
-#endif /* MQTT_NETWORK_TYPE_NO_TLS */
+#endif /* KAWAII_MQTT_NETWORK_TYPE_NO_TLS */
 
 #endif /* _DEFCONFIG_H_ */

+ 156 - 156
mqttclient/mqttclient.c

@@ -7,12 +7,12 @@
  */
 #include "mqttclient.h"
 
-#define     MQTT_MIN_PAYLOAD_SIZE   2               
-#define     MQTT_MAX_PAYLOAD_SIZE   268435455       // MQTT imposes a maximum payload size of 268435455 bytes.
+#define     KAWAII_MQTT_MIN_PAYLOAD_SIZE   2               
+#define     KAWAII_MQTT_MAX_PAYLOAD_SIZE   268435455       // MQTT imposes a maximum payload size of 268435455 bytes.
 
 static void default_msg_handler(void* client, message_data_t* msg)
 {
-    MQTT_LOG_I("%s:%d %s()...\ntopic: %s, qos: %d, \nmessage:%s", __FILE__, __LINE__, __FUNCTION__, 
+    KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s, qos: %d, \nmessage:%s", __FILE__, __LINE__, __FUNCTION__, 
             msg->topic_name, msg->message->qos, (char*)msg->message->payload);
 }
 
@@ -34,11 +34,11 @@ static int mqtt_is_connected(mqtt_client_t* c)
 
     state = mqtt_get_client_state(c);
     if (CLIENT_STATE_CLEAN_SESSION ==  state) {
-        RETURN_ERROR(MQTT_CLEAN_SESSION_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_CLEAN_SESSION_ERROR);
     } else if (CLIENT_STATE_CONNECTED != state) {
-        RETURN_ERROR(MQTT_NOT_CONNECT_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NOT_CONNECT_ERROR);
     }
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 static int mqtt_set_publish_dup(mqtt_client_t* c, uint8_t dup)
@@ -48,22 +48,22 @@ static int mqtt_set_publish_dup(mqtt_client_t* c, uint8_t dup)
     MQTTHeader header = {0};
 
     if (NULL == c->mqtt_write_buf)
-        RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
 
     header.byte = readChar(&read_data); /* read header */
 
     if (header.bits.type != PUBLISH)
-        RETURN_ERROR(MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SET_PUBLISH_DUP_FAILED_ERROR);
     
     header.bits.dup = dup;
     writeChar(&write_data, header.byte); /* write header */
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 static int mqtt_ack_handler_is_maximum(mqtt_client_t* c)
 {
-    return (c->mqtt_ack_handler_number >= MQTT_ACK_HANDLER_NUM_MAX) ? 1 : 0;
+    return (c->mqtt_ack_handler_number >= KAWAII_MQTT_ACK_HANDLER_NUM_MAX) ? 1 : 0;
 }
 
 static void mqtt_add_ack_handler_num(mqtt_client_t* c)
@@ -75,7 +75,7 @@ static void mqtt_add_ack_handler_num(mqtt_client_t* c)
 
 static int mqtt_subtract_ack_handler_num(mqtt_client_t* c)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     platform_mutex_lock(&c->mqtt_global_lock);
     if (c->mqtt_ack_handler_number <= 0) {
         goto exit;
@@ -91,7 +91,7 @@ exit:
 static uint16_t mqtt_get_next_packet_id(mqtt_client_t *c) 
 {
     platform_mutex_lock(&c->mqtt_global_lock);
-    c->mqtt_packet_id = (c->mqtt_packet_id == MQTT_MAX_PACKET_ID) ? 1 : c->mqtt_packet_id + 1;
+    c->mqtt_packet_id = (c->mqtt_packet_id == KAWAII_MQTT_MAX_PACKET_ID) ? 1 : c->mqtt_packet_id + 1;
     platform_mutex_unlock(&c->mqtt_global_lock);
     return c->mqtt_packet_id;
 }
@@ -152,7 +152,7 @@ static int mqtt_read_packet(mqtt_client_t* c, int* packet_type, platform_timer_t
     int remain_len = 0;
     
     if (NULL == packet_type)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     platform_timer_init(timer);
     platform_timer_cutdown(timer, c->mqtt_cmd_timeout);
@@ -160,7 +160,7 @@ static int mqtt_read_packet(mqtt_client_t* c, int* packet_type, platform_timer_t
     /* 1. read the header byte.  This has the packet type in it */
     rc = network_read(c->mqtt_network, c->mqtt_read_buf, len, platform_timer_remain(timer));
     if (rc != len)
-        RETURN_ERROR(MQTT_NOTHING_TO_READ_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NOTHING_TO_READ_ERROR);
 
     /* 2. read the remaining length.  This is variable in itself */
     mqtt_decode_packet(c, &remain_len, platform_timer_remain(timer));
@@ -173,19 +173,19 @@ static int mqtt_read_packet(mqtt_client_t* c, int* packet_type, platform_timer_t
         /* mqtt buffer is too short, read and discard all corrupted data */
         mqtt_packet_drain(c, timer, remain_len);
 
-        RETURN_ERROR(MQTT_BUFFER_TOO_SHORT_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_BUFFER_TOO_SHORT_ERROR);
     }
 
     /* 3. read the rest of the buffer using a callback to supply the rest of the data */
     if ((remain_len > 0) && ((rc = network_read(c->mqtt_network, c->mqtt_read_buf + len, remain_len, platform_timer_remain(timer))) != remain_len))
-        RETURN_ERROR(MQTT_NOTHING_TO_READ_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NOTHING_TO_READ_ERROR);
 
     header.byte = c->mqtt_read_buf[0];
     *packet_type = header.bits.type;
     
     platform_timer_cutdown(&c->mqtt_last_received, (c->mqtt_keep_alive_interval * 1000)); 
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 static int mqtt_send_packet(mqtt_client_t* c, int length, platform_timer_t* timer)
@@ -206,10 +206,10 @@ static int mqtt_send_packet(mqtt_client_t* c, int length, platform_timer_t* time
 
     if (sent == length) {
         platform_timer_cutdown(&c->mqtt_last_sent, (c->mqtt_keep_alive_interval * 1000));
-        RETURN_ERROR(MQTT_SUCCESS_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
     }
     
-    RETURN_ERROR(MQTT_SEND_PACKET_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SEND_PACKET_ERROR);
 }
 
 static int mqtt_is_topic_equals(const char *topic_filter, const char *topic)
@@ -260,7 +260,7 @@ static char mqtt_topic_is_matched(char* topic_filter, MQTTString* topic_name)
 static void mqtt_new_message_data(message_data_t* md, MQTTString* topic_name, mqtt_message_t* message)
 {
     int len;
-    len = (topic_name->lenstring.len < MQTT_TOPIC_LEN_MAX - 1) ? topic_name->lenstring.len : MQTT_TOPIC_LEN_MAX - 1;
+    len = (topic_name->lenstring.len < KAWAII_MQTT_TOPIC_LEN_MAX - 1) ? topic_name->lenstring.len : KAWAII_MQTT_TOPIC_LEN_MAX - 1;
     memcpy(md->topic_name, topic_name->lenstring.data, len);
     md->topic_name[len] = '\0';     /* the topic name is too long and will be truncated */
     md->message = message;
@@ -286,7 +286,7 @@ static message_handlers_t *mqtt_get_msg_handler(mqtt_client_t* c, MQTTString* to
 
 static int mqtt_deliver_message(mqtt_client_t* c, MQTTString* topic_name, mqtt_message_t* message)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     message_handlers_t *msg_handler;
     
     /* get mqtt message handler */
@@ -296,12 +296,12 @@ static int mqtt_deliver_message(mqtt_client_t* c, MQTTString* topic_name, mqtt_m
         message_data_t md;
         mqtt_new_message_data(&md, topic_name, message);    /* make a message data */
         msg_handler->handler(c, &md);       /* deliver the message */
-        rc = MQTT_SUCCESS_ERROR;
+        rc = KAWAII_MQTT_SUCCESS_ERROR;
     } else if (NULL != c->mqtt_interceptor_handler) {
         message_data_t md;
         mqtt_new_message_data(&md, topic_name, message);    /* make a message data */
         c->mqtt_interceptor_handler(c, &md);
-        rc = MQTT_SUCCESS_ERROR;
+        rc = KAWAII_MQTT_SUCCESS_ERROR;
     }
     
     memset(message->payload, 0, strlen(message->payload));
@@ -351,7 +351,7 @@ static void mqtt_ack_handler_resend(mqtt_client_t* c, ack_handlers_t* ack_handle
     memcpy(c->mqtt_write_buf, ack_handler->payload, ack_handler->payload_len);   /* copy data to write buf form ack handler */
     
     mqtt_send_packet(c, ack_handler->payload_len, &timer);      /* resend data */
-    MQTT_LOG_W("%s:%d %s()... resend %d package, packet_id is %d ", __FILE__, __LINE__, __FUNCTION__, ack_handler->type, ack_handler->packet_id);
+    KAWAII_MQTT_LOG_W("%s:%d %s()... resend %d package, packet_id is %d ", __FILE__, __LINE__, __FUNCTION__, ack_handler->type, ack_handler->packet_id);
     platform_mutex_unlock(&c->mqtt_write_lock);
 }
 
@@ -377,17 +377,17 @@ static int mqtt_ack_list_node_is_exist(mqtt_client_t* c, int type, uint16_t pack
 
 static int mqtt_ack_list_record(mqtt_client_t* c, int type, uint16_t packet_id, uint16_t payload_len, message_handlers_t* handler)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     ack_handlers_t *ack_handler = NULL;
     
     /* Determine if the node already exists */
     if (mqtt_ack_list_node_is_exist(c, type, packet_id))
-        RETURN_ERROR(MQTT_ACK_NODE_IS_EXIST_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_ACK_NODE_IS_EXIST_ERROR);
 
     /* create a ack handler node */
     ack_handler = mqtt_ack_handler_create(c, type, packet_id, payload_len, handler);
     if (NULL == ack_handler)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
 
     mqtt_add_ack_handler_num(c);
 
@@ -402,7 +402,7 @@ static int mqtt_ack_list_unrecord(mqtt_client_t* c, int type, uint16_t packet_id
     ack_handlers_t *ack_handler;
 
     if (mqtt_list_is_empty(&c->mqtt_ack_handler_list))
-        RETURN_ERROR(MQTT_SUCCESS_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 
     LIST_FOR_EACH_SAFE(curr, next, &c->mqtt_ack_handler_list) {
         ack_handler = LIST_ENTRY(curr, ack_handlers_t, list);
@@ -417,7 +417,7 @@ static int mqtt_ack_list_unrecord(mqtt_client_t* c, int type, uint16_t packet_id
         mqtt_ack_handler_destroy(ack_handler);
         mqtt_subtract_ack_handler_num(c);
     }
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 
@@ -459,7 +459,7 @@ static int mqtt_msg_handler_is_exist(mqtt_client_t* c, message_handlers_t *handl
 
         /* determine whether a node already exists by mqtt topic, but wildcards are not supported */
         if ((NULL != msg_handler->topic_filter) && (mqtt_is_topic_equals(msg_handler->topic_filter, handler->topic_filter))) {
-            MQTT_LOG_W("%s:%d %s()...msg_handler->topic_filter: %s, handler->topic_filter: %s", 
+            KAWAII_MQTT_LOG_W("%s:%d %s()...msg_handler->topic_filter: %s, handler->topic_filter: %s", 
                         __FILE__, __LINE__, __FUNCTION__, msg_handler->topic_filter, handler->topic_filter);
             return 1;
         }
@@ -471,17 +471,17 @@ static int mqtt_msg_handler_is_exist(mqtt_client_t* c, message_handlers_t *handl
 static int mqtt_msg_handlers_install(mqtt_client_t* c, message_handlers_t *handler)
 {
     if ((NULL == c) || (NULL == handler))
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
     
     if (mqtt_msg_handler_is_exist(c, handler)) {
         mqtt_msg_handler_destory(handler);
-        RETURN_ERROR(MQTT_SUCCESS_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
     }
 
     /* install to  msg_handler_list*/
     mqtt_list_add_tail(&handler->list, &c->mqtt_msg_handler_list);
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 
@@ -546,21 +546,21 @@ static void mqtt_ack_list_scan(mqtt_client_t* c, uint8_t flag)
 
 static int mqtt_try_resubscribe(mqtt_client_t* c)
 {
-    int rc = MQTT_RESUBSCRIBE_ERROR;
+    int rc = KAWAII_MQTT_RESUBSCRIBE_ERROR;
     mqtt_list_t *curr, *next;
     message_handlers_t *msg_handler;
 
-    MQTT_LOG_W("%s:%d %s()... mqtt try resubscribe ...", __FILE__, __LINE__, __FUNCTION__);
+    KAWAII_MQTT_LOG_W("%s:%d %s()... mqtt try resubscribe ...", __FILE__, __LINE__, __FUNCTION__);
     
     if (mqtt_list_is_empty(&c->mqtt_msg_handler_list))
-        RETURN_ERROR(MQTT_SUCCESS_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
     
     LIST_FOR_EACH_SAFE(curr, next, &c->mqtt_msg_handler_list) {
         msg_handler = LIST_ENTRY(curr, message_handlers_t, list);
 
         /* resubscribe topic */
-        if ((rc = mqtt_subscribe(c, msg_handler->topic_filter, msg_handler->qos, msg_handler->handler)) == MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR)
-            MQTT_LOG_W("%s:%d %s()... mqtt ack handler num too much ...", __FILE__, __LINE__, __FUNCTION__);
+        if ((rc = mqtt_subscribe(c, msg_handler->topic_filter, msg_handler->qos, msg_handler->handler)) == KAWAII_MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR)
+            KAWAII_MQTT_LOG_W("%s:%d %s()... mqtt ack handler num too much ...", __FILE__, __LINE__, __FUNCTION__);
 
     }
 
@@ -569,33 +569,33 @@ static int mqtt_try_resubscribe(mqtt_client_t* c)
 
 static int mqtt_try_do_reconnect(mqtt_client_t* c)
 {
-    int rc = MQTT_CONNECT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_CONNECT_FAILED_ERROR;
 
     if (CLIENT_STATE_CONNECTED != mqtt_get_client_state(c))
         rc = mqtt_connect(c);       /* reconnect */
     
-    if (MQTT_SUCCESS_ERROR == rc) {
+    if (KAWAII_MQTT_SUCCESS_ERROR == rc) {
         rc = mqtt_try_resubscribe(c);   /* resubscribe */
         /* process these ack messages immediately after reconnecting */
         mqtt_ack_list_scan(c, 0);
     }
 
-    MQTT_LOG_D("%s:%d %s()... mqtt try connect result is -0x%04x", __FILE__, __LINE__, __FUNCTION__, -rc);
+    KAWAII_MQTT_LOG_D("%s:%d %s()... mqtt try connect result is -0x%04x", __FILE__, __LINE__, __FUNCTION__, -rc);
     
     RETURN_ERROR(rc);
 }
 
 static int mqtt_try_reconnect(mqtt_client_t* c)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
 
     rc = mqtt_try_do_reconnect(c);
 
-    if ((MQTT_SUCCESS_ERROR != rc) && (platform_timer_is_expired(&c->mqtt_reconnect_timer))) {
+    if ((KAWAII_MQTT_SUCCESS_ERROR != rc) && (platform_timer_is_expired(&c->mqtt_reconnect_timer))) {
         platform_timer_cutdown(&c->mqtt_reconnect_timer, c->mqtt_reconnect_try_duration);
         if (NULL != c->mqtt_reconnect_handler)
             c->mqtt_reconnect_handler(c, c->mqtt_reconnect_data);
-        RETURN_ERROR(MQTT_RECONNECT_TIMEOUT_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_RECONNECT_TIMEOUT_ERROR);
     } 
     
     RETURN_ERROR(rc);
@@ -604,7 +604,7 @@ static int mqtt_try_reconnect(mqtt_client_t* c)
 static int mqtt_publish_ack_packet(mqtt_client_t *c, uint16_t packet_id, int packet_type)
 {
     int len = 0;
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     platform_timer_t timer;
     platform_timer_init(&timer);
     platform_timer_cutdown(&timer, c->mqtt_cmd_timeout);
@@ -615,7 +615,7 @@ static int mqtt_publish_ack_packet(mqtt_client_t *c, uint16_t packet_id, int pac
         case PUBREC:
             len = MQTTSerialize_ack(c->mqtt_write_buf, c->mqtt_write_buf_size, PUBREL, 0, packet_id); /* make a PUBREL ack packet */
             rc = mqtt_ack_list_record(c, PUBCOMP, packet_id, len, NULL);   /* record ack, expect to receive PUBCOMP*/
-            if (MQTT_SUCCESS_ERROR != rc)
+            if (KAWAII_MQTT_SUCCESS_ERROR != rc)
                 goto exit;
             break;
             
@@ -624,12 +624,12 @@ static int mqtt_publish_ack_packet(mqtt_client_t *c, uint16_t packet_id, int pac
             break;
             
         default:
-            rc = MQTT_PUBLISH_ACK_TYPE_ERROR;
+            rc = KAWAII_MQTT_PUBLISH_ACK_TYPE_ERROR;
             goto exit;
     }
 
     if (len <= 0) {
-        rc = MQTT_PUBLISH_ACK_PACKET_ERROR;
+        rc = KAWAII_MQTT_PUBLISH_ACK_PACKET_ERROR;
         goto exit;
     }
 
@@ -643,16 +643,16 @@ exit:
 
 static int mqtt_puback_and_pubcomp_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     uint16_t packet_id;
     uint8_t dup, packet_type;
 
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     if (MQTTDeserialize_ack(&packet_type, &dup, &packet_id, c->mqtt_read_buf, c->mqtt_read_buf_size) != 1)
-        rc = MQTT_PUBREC_PACKET_ERROR;
+        rc = KAWAII_MQTT_PUBREC_PACKET_ERROR;
     
     (void) dup;
     rc = mqtt_ack_list_unrecord(c, packet_type, packet_id, NULL);   /* unrecord ack handler */
@@ -662,7 +662,7 @@ static int mqtt_puback_and_pubcomp_packet_handle(mqtt_client_t *c, platform_time
 
 static int mqtt_suback_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     int count = 0;
     int granted_qos = 0;
     uint16_t packet_id;
@@ -670,24 +670,24 @@ static int mqtt_suback_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
     message_handlers_t *msg_handler = NULL;
 
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     /* deserialize subscribe ack packet */
     if (MQTTDeserialize_suback(&packet_id, 1, &count, (int*)&granted_qos, c->mqtt_read_buf, c->mqtt_read_buf_size) != 1) 
-        RETURN_ERROR(MQTT_SUBSCRIBE_ACK_PACKET_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUBSCRIBE_ACK_PACKET_ERROR);
 
     is_nack = (granted_qos == SUBFAIL);
     
     rc = mqtt_ack_list_unrecord(c, SUBACK, packet_id, &msg_handler);
     
     if (!msg_handler)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
     
     if (is_nack) {
         mqtt_msg_handler_destory(msg_handler);  /* subscribe topic failed, destory message handler */
-        MQTT_LOG_D("subscribe topic failed...");
-        RETURN_ERROR(MQTT_SUBSCRIBE_NOT_ACK_ERROR);
+        KAWAII_MQTT_LOG_D("subscribe topic failed...");
+        RETURN_ERROR(KAWAII_MQTT_SUBSCRIBE_NOT_ACK_ERROR);
     }
     
     rc = mqtt_msg_handlers_install(c, msg_handler);
@@ -697,21 +697,21 @@ static int mqtt_suback_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 
 static int mqtt_unsuback_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     message_handlers_t *msg_handler;
     uint16_t packet_id = 0;
     
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     if (MQTTDeserialize_unsuback(&packet_id, c->mqtt_read_buf, c->mqtt_read_buf_size) != 1)
-        RETURN_ERROR(MQTT_UNSUBSCRIBE_ACK_PACKET_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_UNSUBSCRIBE_ACK_PACKET_ERROR);
 
     rc = mqtt_ack_list_unrecord(c, UNSUBACK, packet_id, &msg_handler);  /* unrecord ack handler, and get message handler */
     
     if (!msg_handler)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
     
     mqtt_msg_handler_destory(msg_handler);  /* destory message handler */
 
@@ -720,19 +720,19 @@ static int mqtt_unsuback_packet_handle(mqtt_client_t *c, platform_timer_t *timer
 
 static int mqtt_publish_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 {
-    int len = 0, rc = MQTT_SUCCESS_ERROR;
+    int len = 0, rc = KAWAII_MQTT_SUCCESS_ERROR;
     MQTTString topic_name;
     mqtt_message_t msg;
     int qos;
     msg.payloadlen = 0; 
     
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     if (MQTTDeserialize_publish(&msg.dup, &qos, &msg.retained, &msg.id, &topic_name,
         (uint8_t**)&msg.payload, (int*)&msg.payloadlen, c->mqtt_read_buf, c->mqtt_read_buf_size) != 1)
-        RETURN_ERROR(MQTT_PUBLISH_PACKET_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_PUBLISH_PACKET_ERROR);
     
     msg.qos = (mqtt_qos_t)qos;
 
@@ -746,7 +746,7 @@ static int mqtt_publish_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
             len = MQTTSerialize_ack(c->mqtt_write_buf, c->mqtt_write_buf_size, PUBREC, 0, msg.id);
 
         if (len <= 0)
-            rc = MQTT_SERIALIZE_PUBLISH_ACK_PACKET_ERROR;
+            rc = KAWAII_MQTT_SERIALIZE_PUBLISH_ACK_PACKET_ERROR;
         else
             rc = mqtt_send_packet(c, len, timer);
         
@@ -760,7 +760,7 @@ static int mqtt_publish_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
         mqtt_deliver_message(c, &topic_name, &msg);
     else {
         /* record the received of a qos2 message and only processes it when the qos2 message is received for the first time */
-        if ((rc = mqtt_ack_list_record(c, PUBREL, msg.id, len, NULL)) != MQTT_ACK_NODE_IS_EXIST_ERROR)
+        if ((rc = mqtt_ack_list_record(c, PUBREL, msg.id, len, NULL)) != KAWAII_MQTT_ACK_NODE_IS_EXIST_ERROR)
             mqtt_deliver_message(c, &topic_name, &msg);
     }
     
@@ -770,16 +770,16 @@ static int mqtt_publish_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 
 static int mqtt_pubrec_and_pubrel_packet_handle(mqtt_client_t *c, platform_timer_t *timer)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     uint16_t packet_id;
     uint8_t dup, packet_type;
     
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     if (MQTTDeserialize_ack(&packet_type, &dup, &packet_id, c->mqtt_read_buf, c->mqtt_read_buf_size) != 1)
-        RETURN_ERROR(MQTT_PUBREC_PACKET_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_PUBREC_PACKET_ERROR);
 
     (void) dup;
     rc = mqtt_publish_ack_packet(c, packet_id, packet_type);    /* make a ack packet and send it */
@@ -790,7 +790,7 @@ static int mqtt_pubrec_and_pubrel_packet_handle(mqtt_client_t *c, platform_timer
 
 static int mqtt_packet_handle(mqtt_client_t* c, platform_timer_t* timer)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     int packet_type = 0;
     
     rc = mqtt_read_packet(c, &packet_type, timer);
@@ -835,7 +835,7 @@ static int mqtt_packet_handle(mqtt_client_t* c, platform_timer_t* timer)
     rc = mqtt_keep_alive(c);
 
 exit:
-    if (rc == MQTT_SUCCESS_ERROR)
+    if (rc == KAWAII_MQTT_SUCCESS_ERROR)
         rc = packet_type;
 
     RETURN_ERROR(rc);
@@ -843,7 +843,7 @@ exit:
 
 static int mqtt_wait_packet(mqtt_client_t* c, int packet_type, platform_timer_t* timer)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
 
     do {
         if (platform_timer_is_expired(timer))
@@ -856,12 +856,12 @@ static int mqtt_wait_packet(mqtt_client_t* c, int packet_type, platform_timer_t*
 
 static int mqtt_yield(mqtt_client_t* c, int timeout_ms)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     client_state_t state;
     platform_timer_t timer;
 
     if (NULL == c)
-        RETURN_ERROR(MQTT_FAILED_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_FAILED_ERROR);
 
     if (0 == timeout_ms)
         timeout_ms = c->mqtt_cmd_timeout;
@@ -872,12 +872,12 @@ static int mqtt_yield(mqtt_client_t* c, int timeout_ms)
     while (!platform_timer_is_expired(&timer)) {
         state = mqtt_get_client_state(c);
         if (CLIENT_STATE_CLEAN_SESSION ==  state) {
-            RETURN_ERROR(MQTT_CLEAN_SESSION_ERROR);
+            RETURN_ERROR(KAWAII_MQTT_CLEAN_SESSION_ERROR);
         } else if (CLIENT_STATE_CONNECTED != state) {
             /* mqtt not connect, need reconnect */
             rc = mqtt_try_reconnect(c);
 
-            if (MQTT_RECONNECT_TIMEOUT_ERROR == rc)
+            if (KAWAII_MQTT_RECONNECT_TIMEOUT_ERROR == rc)
                 RETURN_ERROR(rc);
             continue;
         }
@@ -889,8 +889,8 @@ static int mqtt_yield(mqtt_client_t* c, int timeout_ms)
             /* scan ack list, destroy ack handler that have timed out or resend them */
             mqtt_ack_list_scan(c, 1);
 
-        } else if (MQTT_NOT_CONNECT_ERROR == rc) {
-            MQTT_LOG_E("%s:%d %s()... mqtt not connect", __FILE__, __LINE__, __FUNCTION__);
+        } else if (KAWAII_MQTT_NOT_CONNECT_ERROR == rc) {
+            KAWAII_MQTT_LOG_E("%s:%d %s()... mqtt not connect", __FILE__, __LINE__, __FUNCTION__);
             
             /* reconnect timer cutdown */
             platform_timer_cutdown(&c->mqtt_reconnect_timer, c->mqtt_reconnect_try_duration);
@@ -910,19 +910,19 @@ static void mqtt_yield_thread(void *arg)
 
     state = mqtt_get_client_state(c);
         if (CLIENT_STATE_CONNECTED !=  state) {
-            MQTT_LOG_W("%s:%d %s()..., mqtt is not connected to the server...",  __FILE__, __LINE__, __FUNCTION__);
+            KAWAII_MQTT_LOG_W("%s:%d %s()..., mqtt is not connected to the server...",  __FILE__, __LINE__, __FUNCTION__);
             platform_thread_stop(c->mqtt_thread);    /* mqtt is not connected to the server, stop thread */
     }
 
     while (1) {
         rc = mqtt_yield(c, c->mqtt_cmd_timeout);
-        if (MQTT_CLEAN_SESSION_ERROR == rc) {
-            MQTT_LOG_E("%s:%d %s()..., mqtt clean session....", __FILE__, __LINE__, __FUNCTION__);
+        if (KAWAII_MQTT_CLEAN_SESSION_ERROR == rc) {
+            KAWAII_MQTT_LOG_E("%s:%d %s()..., mqtt clean session....", __FILE__, __LINE__, __FUNCTION__);
             network_disconnect(c->mqtt_network);
             mqtt_clean_session(c);
             goto exit;
-        } else if (MQTT_RECONNECT_TIMEOUT_ERROR == rc) {
-            MQTT_LOG_E("%s:%d %s()..., mqtt reconnect timeout....", __FILE__, __LINE__, __FUNCTION__);
+        } else if (KAWAII_MQTT_RECONNECT_TIMEOUT_ERROR == rc) {
+            KAWAII_MQTT_LOG_E("%s:%d %s()..., mqtt reconnect timeout....", __FILE__, __LINE__, __FUNCTION__);
         }
     }
     
@@ -933,38 +933,38 @@ exit:
 static int mqtt_connect_with_results(mqtt_client_t* c)
 {
     int len = 0;
-    int rc = MQTT_CONNECT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_CONNECT_FAILED_ERROR;
     platform_timer_t connect_timer;
     mqtt_connack_data_t connack_data = {0};
     MQTTPacket_connectData connect_data = MQTTPacket_connectData_initializer;
 
     if (NULL == c)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     if (CLIENT_STATE_CONNECTED == mqtt_get_client_state(c))
-        RETURN_ERROR(MQTT_SUCCESS_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 
-    if ((MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_read_buf_size) || (MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_read_buf_size))
-        c->mqtt_read_buf_size = MQTT_DEFAULT_BUF_SIZE;
-    if ((MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_write_buf_size) || (MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_write_buf_size))
-        c->mqtt_write_buf_size = MQTT_DEFAULT_BUF_SIZE;
+    if ((KAWAII_MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_read_buf_size) || (KAWAII_MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_read_buf_size))
+        c->mqtt_read_buf_size = KAWAII_MQTT_DEFAULT_BUF_SIZE;
+    if ((KAWAII_MQTT_MIN_PAYLOAD_SIZE >= c->mqtt_write_buf_size) || (KAWAII_MQTT_MAX_PAYLOAD_SIZE <= c->mqtt_write_buf_size))
+        c->mqtt_write_buf_size = KAWAII_MQTT_DEFAULT_BUF_SIZE;
     
     c->mqtt_read_buf = (uint8_t*) platform_memory_alloc(c->mqtt_write_buf_size);
     c->mqtt_write_buf = (uint8_t*) platform_memory_alloc(c->mqtt_write_buf_size);
     
     if ((NULL == c->mqtt_read_buf) || (NULL == c->mqtt_write_buf)) {
-        MQTT_LOG_E("%s:%d %s()... malloc buf failed...", __FILE__, __LINE__, __FUNCTION__);
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        KAWAII_MQTT_LOG_E("%s:%d %s()... malloc buf failed...", __FILE__, __LINE__, __FUNCTION__);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
     }
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     rc = network_init(c->mqtt_network, c->mqtt_host, c->mqtt_port, c->mqtt_ca);
 #else
     rc = network_init(c->mqtt_network, c->mqtt_host, c->mqtt_port, NULL);
 #endif
 
     rc = network_connect(c->mqtt_network);
-    if (MQTT_SUCCESS_ERROR != rc) {
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc) {
         if (NULL != c->mqtt_network) {
             network_release(c->mqtt_network);
             platform_memory_free(c->mqtt_network);
@@ -973,7 +973,7 @@ static int mqtt_connect_with_results(mqtt_client_t* c)
         }  
     }
     
-    MQTT_LOG_I("%s:%d %s()... mqtt connect success...", __FILE__, __LINE__, __FUNCTION__);
+    KAWAII_MQTT_LOG_I("%s:%d %s()... mqtt connect success...", __FILE__, __LINE__, __FUNCTION__);
 
     connect_data.keepAliveInterval = c->mqtt_keep_alive_interval;
     connect_data.cleansession = c->mqtt_clean_session;
@@ -1002,23 +1002,23 @@ static int mqtt_connect_with_results(mqtt_client_t* c)
     platform_timer_cutdown(&connect_timer, c->mqtt_cmd_timeout);
 
     /* send connect packet */
-    if ((rc = mqtt_send_packet(c, len, &connect_timer)) != MQTT_SUCCESS_ERROR)
+    if ((rc = mqtt_send_packet(c, len, &connect_timer)) != KAWAII_MQTT_SUCCESS_ERROR)
         goto exit;
 
     if (mqtt_wait_packet(c, CONNACK, &connect_timer) == CONNACK) {
         if (MQTTDeserialize_connack(&connack_data.session_present, &connack_data.rc, c->mqtt_read_buf, c->mqtt_read_buf_size) == 1)
             rc = connack_data.rc;
         else
-            rc = MQTT_CONNECT_FAILED_ERROR;
+            rc = KAWAII_MQTT_CONNECT_FAILED_ERROR;
     } else
-        rc = MQTT_CONNECT_FAILED_ERROR;
+        rc = KAWAII_MQTT_CONNECT_FAILED_ERROR;
 
 exit:
-    if (rc == MQTT_SUCCESS_ERROR) {
+    if (rc == KAWAII_MQTT_SUCCESS_ERROR) {
         if(NULL == c->mqtt_thread) {
 
             /* connect success, and need init mqtt thread */
-            c->mqtt_thread= platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, MQTT_THREAD_STACK_SIZE, MQTT_THREAD_PRIO, MQTT_THREAD_TICK);
+            c->mqtt_thread= platform_thread_init("mqtt_yield_thread", mqtt_yield_thread, c, KAWAII_MQTT_THREAD_STACK_SIZE, KAWAII_MQTT_THREAD_PRIO, KAWAII_MQTT_THREAD_TICK);
 
             if (NULL != c->mqtt_thread) {
                 mqtt_set_client_state(c, CLIENT_STATE_CONNECTED);
@@ -1046,15 +1046,15 @@ static int mqtt_init(mqtt_client_t* c)
     c->mqtt_network = (network_t*) platform_memory_alloc(sizeof(network_t));
 
     if (NULL == c->mqtt_network) {
-        MQTT_LOG_E("%s:%d %s()... malloc memory failed...", __FILE__, __LINE__, __FUNCTION__);
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        KAWAII_MQTT_LOG_E("%s:%d %s()... malloc memory failed...", __FILE__, __LINE__, __FUNCTION__);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
     }
     memset(c->mqtt_network, 0, sizeof(network_t));
 
     c->mqtt_packet_id = 1;
     c->mqtt_clean_session = 0;          //no clear session by default
     c->mqtt_will_flag = 0;
-    c->mqtt_cmd_timeout = MQTT_DEFAULT_CMD_TIMEOUT;
+    c->mqtt_cmd_timeout = KAWAII_MQTT_DEFAULT_CMD_TIMEOUT;
     c->mqtt_client_state = CLIENT_STATE_INITIALIZED;
     
     c->mqtt_ping_outstanding = 0;
@@ -1062,9 +1062,9 @@ static int mqtt_init(mqtt_client_t* c)
     c->mqtt_client_id_len = 0;
     c->mqtt_user_name_len = 0;
     c->mqtt_password_len = 0;
-    c->mqtt_keep_alive_interval = MQTT_KEEP_ALIVE_INTERVAL;
-    c->mqtt_version = MQTT_VERSION;
-    c->mqtt_reconnect_try_duration = MQTT_RECONNECT_DEFAULT_DURATION;
+    c->mqtt_keep_alive_interval = KAWAII_MQTT_KEEP_ALIVE_INTERVAL;
+    c->mqtt_version = KAWAII_MQTT_VERSION;
+    c->mqtt_reconnect_try_duration = KAWAII_MQTT_RECONNECT_DEFAULT_DURATION;
 
     c->mqtt_will_options = NULL;
     c->mqtt_reconnect_data = NULL;
@@ -1081,28 +1081,28 @@ static int mqtt_init(mqtt_client_t* c)
     platform_timer_init(&c->mqtt_last_sent);
     platform_timer_init(&c->mqtt_last_received);
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 /********************************************************* mqttclient global function ********************************************************/
 
-MQTT_CLIENT_SET_DEFINE(client_id, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(user_name, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(password, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(host, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(port, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(ca, char*, NULL)
-MQTT_CLIENT_SET_DEFINE(reconnect_data, void*, NULL)
-MQTT_CLIENT_SET_DEFINE(keep_alive_interval, uint16_t, 0)
-MQTT_CLIENT_SET_DEFINE(will_flag, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(clean_session, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(version, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(cmd_timeout, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(read_buf_size, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(write_buf_size, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(reconnect_try_duration, uint32_t, 0)
-MQTT_CLIENT_SET_DEFINE(reconnect_handler, reconnect_handler_t, NULL)
-MQTT_CLIENT_SET_DEFINE(interceptor_handler, interceptor_handler_t, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(client_id, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(user_name, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(password, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(host, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(port, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(ca, char*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_data, void*, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(keep_alive_interval, uint16_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(will_flag, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(clean_session, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(version, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(cmd_timeout, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(read_buf_size, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(write_buf_size, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_try_duration, uint32_t, 0)
+KAWAII_MQTT_CLIENT_SET_DEFINE(reconnect_handler, reconnect_handler_t, NULL)
+KAWAII_MQTT_CLIENT_SET_DEFINE(interceptor_handler, interceptor_handler_t, NULL)
 
 void mqtt_sleep_ms(int ms)
 {
@@ -1111,21 +1111,21 @@ void mqtt_sleep_ms(int ms)
 
 int mqtt_keep_alive(mqtt_client_t* c)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     
     rc = mqtt_is_connected(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         RETURN_ERROR(rc);
 
     if (platform_timer_is_expired(&c->mqtt_last_sent) || platform_timer_is_expired(&c->mqtt_last_received)) {
         if (c->mqtt_ping_outstanding) {
-            MQTT_LOG_W("%s:%d %s()... ping outstanding", __FILE__, __LINE__, __FUNCTION__);
+            KAWAII_MQTT_LOG_W("%s:%d %s()... ping outstanding", __FILE__, __LINE__, __FUNCTION__);
             mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
-            rc = MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
+            rc = KAWAII_MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
         } else {
             platform_timer_t timer;
             int len = MQTTSerialize_pingreq(c->mqtt_write_buf, c->mqtt_write_buf_size);
-            if (len > 0 && (rc = mqtt_send_packet(c, len, &timer)) == MQTT_SUCCESS_ERROR) // send the ping packet
+            if (len > 0 && (rc = mqtt_send_packet(c, len, &timer)) == KAWAII_MQTT_SUCCESS_ERROR) // send the ping packet
                 c->mqtt_ping_outstanding++;
         }
     }
@@ -1145,7 +1145,7 @@ mqtt_client_t *mqtt_lease(void)
     memset(c, 0, sizeof(mqtt_client_t));
 
     rc = mqtt_init(c);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         return NULL;
     
     return c;
@@ -1156,7 +1156,7 @@ int mqtt_release(mqtt_client_t* c)
     platform_timer_t timer;
 
     if (NULL == c)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     platform_timer_init(&timer);
     platform_timer_cutdown(&timer, c->mqtt_cmd_timeout);
@@ -1165,8 +1165,8 @@ int mqtt_release(mqtt_client_t* c)
     while ((CLIENT_STATE_INVALID != mqtt_get_client_state(c))) {
         // platform_timer_usleep(1000);            // 1ms avoid compiler optimization.
         if (platform_timer_is_expired(&timer)) {
-            MQTT_LOG_E("%s:%d %s()... mqtt release failed...", __FILE__, __LINE__, __FUNCTION__);
-            RETURN_ERROR(MQTT_FAILED_ERROR)
+            KAWAII_MQTT_LOG_E("%s:%d %s()... mqtt release failed...", __FILE__, __LINE__, __FUNCTION__);
+            RETURN_ERROR(KAWAII_MQTT_FAILED_ERROR)
         }    
     }
     
@@ -1187,7 +1187,7 @@ int mqtt_release(mqtt_client_t* c)
 
     memset(c, 0, sizeof(mqtt_client_t));
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 int mqtt_connect(mqtt_client_t* c)
@@ -1198,7 +1198,7 @@ int mqtt_connect(mqtt_client_t* c)
 
 int mqtt_disconnect(mqtt_client_t* c)
 {
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     platform_timer_t timer;
     int len = 0;
 
@@ -1221,7 +1221,7 @@ int mqtt_disconnect(mqtt_client_t* c)
 
 int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, message_handler_t handler)
 {
-    int rc = MQTT_SUBSCRIBE_ERROR;
+    int rc = KAWAII_MQTT_SUBSCRIBE_ERROR;
     int len = 0;
     uint16_t packet_id;
     platform_timer_t timer;
@@ -1230,7 +1230,7 @@ int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, m
     message_handlers_t *msg_handler = NULL;
 
     if (CLIENT_STATE_CONNECTED != mqtt_get_client_state(c))
-        RETURN_ERROR(MQTT_NOT_CONNECT_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NOT_CONNECT_ERROR);
     
     platform_mutex_lock(&c->mqtt_write_lock);
 
@@ -1241,7 +1241,7 @@ int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, m
     if (len <= 0)
         goto exit;
     
-    if ((rc = mqtt_send_packet(c, len, &timer)) != MQTT_SUCCESS_ERROR)
+    if ((rc = mqtt_send_packet(c, len, &timer)) != KAWAII_MQTT_SUCCESS_ERROR)
         goto exit; 
 
     if (NULL == handler)
@@ -1250,7 +1250,7 @@ int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, m
     /* create a message and record it */
     msg_handler = mqtt_msg_handler_create(topic_filter, qos, handler);
     if (NULL == msg_handler)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
 
     rc = mqtt_ack_list_record(c, SUBACK, packet_id, len, msg_handler);
 
@@ -1264,7 +1264,7 @@ exit:
 int mqtt_unsubscribe(mqtt_client_t* c, const char* topic_filter)
 {
     int len = 0;
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     uint16_t packet_id;
     platform_timer_t timer;
     MQTTString topic = MQTTString_initializer;
@@ -1272,7 +1272,7 @@ int mqtt_unsubscribe(mqtt_client_t* c, const char* topic_filter)
     message_handlers_t *msg_handler = NULL;
 
     if (CLIENT_STATE_CONNECTED != mqtt_get_client_state(c))
-        RETURN_ERROR(MQTT_NOT_CONNECT_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NOT_CONNECT_ERROR);
     
     platform_mutex_lock(&c->mqtt_write_lock);
 
@@ -1281,13 +1281,13 @@ int mqtt_unsubscribe(mqtt_client_t* c, const char* topic_filter)
     /* serialize unsubscribe packet and send it */
     if ((len = MQTTSerialize_unsubscribe(c->mqtt_write_buf, c->mqtt_write_buf_size, 0, packet_id, 1, &topic)) <= 0)
         goto exit;
-    if ((rc = mqtt_send_packet(c, len, &timer)) != MQTT_SUCCESS_ERROR)
+    if ((rc = mqtt_send_packet(c, len, &timer)) != KAWAII_MQTT_SUCCESS_ERROR)
         goto exit; 
 
     /* create a message and record it */
     msg_handler = mqtt_msg_handler_create((const char*)topic_filter, QOS0, NULL);
     if (NULL == msg_handler)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
 
     rc = mqtt_ack_list_record(c, UNSUBACK, packet_id, len, msg_handler);
 
@@ -1301,13 +1301,13 @@ exit:
 int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg)
 {
     int len = 0;
-    int rc = MQTT_FAILED_ERROR;
+    int rc = KAWAII_MQTT_FAILED_ERROR;
     platform_timer_t timer;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topic_filter;
 
     if (CLIENT_STATE_CONNECTED != mqtt_get_client_state(c)) {
-        rc = MQTT_NOT_CONNECT_ERROR;
+        rc = KAWAII_MQTT_NOT_CONNECT_ERROR;
         goto exit;
     }
 
@@ -1318,7 +1318,7 @@ int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg
 
     if (QOS0 != msg->qos) {
         if (mqtt_ack_handler_is_maximum(c)) {
-            rc = MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR; /* the recorded ack handler has reached the maximum */
+            rc = KAWAII_MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR; /* the recorded ack handler has reached the maximum */
             goto exit;
         }
         msg->id = mqtt_get_next_packet_id(c);
@@ -1330,7 +1330,7 @@ int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg
     if (len <= 0)
         goto exit;
     
-    if ((rc = mqtt_send_packet(c, len, &timer)) != MQTT_SUCCESS_ERROR)
+    if ((rc = mqtt_send_packet(c, len, &timer)) != KAWAII_MQTT_SUCCESS_ERROR)
         goto exit;
     
     if (QOS0 != msg->qos) {
@@ -1351,8 +1351,8 @@ exit:
 
     platform_mutex_unlock(&c->mqtt_write_lock);
 
-    if ((MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR == rc) || (MQTT_MEM_NOT_ENOUGH_ERROR == rc)) {
-        MQTT_LOG_W("%s:%d %s()... there is not enough memory space to record...", __FILE__, __LINE__, __FUNCTION__);
+    if ((KAWAII_MQTT_ACK_HANDLER_NUM_TOO_MUCH_ERROR == rc) || (KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR == rc)) {
+        KAWAII_MQTT_LOG_W("%s:%d %s()... there is not enough memory space to record...", __FILE__, __LINE__, __FUNCTION__);
 
         /* record too much retransmitted data, may be disconnected, need to reconnect */
         mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
@@ -1369,30 +1369,30 @@ int mqtt_list_subscribe_topic(mqtt_client_t* c)
     message_handlers_t *msg_handler;
     
     if (NULL == c)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     if (mqtt_list_is_empty(&c->mqtt_msg_handler_list))
-        MQTT_LOG_I("%s:%d %s()... there are no subscribed topics...", __FILE__, __LINE__, __FUNCTION__);
+        KAWAII_MQTT_LOG_I("%s:%d %s()... there are no subscribed topics...", __FILE__, __LINE__, __FUNCTION__);
 
     LIST_FOR_EACH_SAFE(curr, next, &c->mqtt_msg_handler_list) {
         msg_handler = LIST_ENTRY(curr, message_handlers_t, list);
         /* determine whether a node already exists by mqtt topic, but wildcards are not supported */
         if (NULL != msg_handler->topic_filter) {
-            MQTT_LOG_I("%s:%d %s()...[%d] subscribe topic: %s", __FILE__, __LINE__, __FUNCTION__, ++i ,msg_handler->topic_filter);
+            KAWAII_MQTT_LOG_I("%s:%d %s()...[%d] subscribe topic: %s", __FILE__, __LINE__, __FUNCTION__, ++i ,msg_handler->topic_filter);
         }
     }
     
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 int mqtt_set_will_options(mqtt_client_t* c, char *topic, mqtt_qos_t qos, uint8_t retained, char *message)
 {
     if ((NULL == c) || (NULL == topic))
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     if (NULL == c->mqtt_will_options) {
         c->mqtt_will_options = platform_memory_alloc(sizeof(mqtt_will_options_t));
-        MQTT_ROBUSTNESS_CHECK(c->mqtt_will_options, MQTT_MEM_NOT_ENOUGH_ERROR);
+        KAWAII_MQTT_ROBUSTNESS_CHECK(c->mqtt_will_options, KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
     }
 
     if (0 == c->mqtt_will_flag)
@@ -1403,5 +1403,5 @@ int mqtt_set_will_options(mqtt_client_t* c, char *topic, mqtt_qos_t qos, uint8_t
     c->mqtt_will_options->will_retained = retained;
     c->mqtt_will_options->will_message = message;
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }

+ 23 - 23
mqttclient/mqttclient.h

@@ -54,7 +54,7 @@ typedef struct mqtt_message {
 } mqtt_message_t;
 
 typedef struct message_data {
-    char                topic_name[MQTT_TOPIC_LEN_MAX];
+    char                topic_name[KAWAII_MQTT_TOPIC_LEN_MAX];
     mqtt_message_t      *message;
 } message_data_t;
 
@@ -126,37 +126,37 @@ typedef struct mqtt_client {
 } mqtt_client_t;
 
 
-#define MQTT_ROBUSTNESS_CHECK(item, err) if (!(item)) {                                         \
-        MQTT_LOG_E("%s:%d %s()... check for error.", __FILE__, __LINE__, __FUNCTION__);         \
+#define KAWAII_MQTT_ROBUSTNESS_CHECK(item, err) if (!(item)) {                                         \
+        KAWAII_MQTT_LOG_E("%s:%d %s()... check for error.", __FILE__, __LINE__, __FUNCTION__);         \
         return err; }
 
-#define MQTT_CLIENT_SET_DEFINE(name, type, res)         \
+#define KAWAII_MQTT_CLIENT_SET_DEFINE(name, type, res)         \
     type mqtt_set_##name(mqtt_client_t *c, type t) {    \
-        MQTT_ROBUSTNESS_CHECK((c), res);                \
+        KAWAII_MQTT_ROBUSTNESS_CHECK((c), res);                \
         c->mqtt_##name = t;                             \
         return c->mqtt_##name;                          \
     }
 
-#define MQTT_CLIENT_SET_STATEMENT(name, type)           \
+#define KAWAII_MQTT_CLIENT_SET_STATEMENT(name, type)           \
     type mqtt_set_##name(mqtt_client_t *, type);
 
-MQTT_CLIENT_SET_STATEMENT(client_id, char*)
-MQTT_CLIENT_SET_STATEMENT(user_name, char*)
-MQTT_CLIENT_SET_STATEMENT(password, char*)
-MQTT_CLIENT_SET_STATEMENT(host, char*)
-MQTT_CLIENT_SET_STATEMENT(port, char*)
-MQTT_CLIENT_SET_STATEMENT(ca, char*)
-MQTT_CLIENT_SET_STATEMENT(reconnect_data, void*)
-MQTT_CLIENT_SET_STATEMENT(keep_alive_interval, uint16_t)
-MQTT_CLIENT_SET_STATEMENT(will_flag, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(clean_session, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(version, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(cmd_timeout, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(read_buf_size, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(write_buf_size, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(reconnect_try_duration, uint32_t)
-MQTT_CLIENT_SET_STATEMENT(reconnect_handler, reconnect_handler_t)
-MQTT_CLIENT_SET_STATEMENT(interceptor_handler, interceptor_handler_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(client_id, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(user_name, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(password, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(host, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(port, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(ca, char*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(reconnect_data, void*)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(keep_alive_interval, uint16_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(will_flag, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(clean_session, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(version, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(cmd_timeout, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(read_buf_size, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(write_buf_size, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(reconnect_try_duration, uint32_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(reconnect_handler, reconnect_handler_t)
+KAWAII_MQTT_CLIENT_SET_STATEMENT(interceptor_handler, interceptor_handler_t)
 
 void mqtt_sleep_ms(int ms);
 mqtt_client_t *mqtt_lease(void);

+ 1 - 1
network/nettype_tcp.c

@@ -24,7 +24,7 @@ int nettype_tcp_connect(network_t* n)
     if (n->socket < 0)
         RETURN_ERROR(n->socket);
     
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 void nettype_tcp_disconnect(network_t* n)

+ 22 - 22
network/nettype_tls.c

@@ -11,7 +11,7 @@
 #include "platform_timer.h"
 #include "random.h"
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
 
 #include "mbedtls/platform.h"
 #include "mbedtls/ssl.h"
@@ -27,7 +27,7 @@
 static int server_certificate_verify(void *hostname, mbedtls_x509_crt *crt, int depth, uint32_t *flags)
 {
     if (0 != *flags)
-        MQTT_LOG_E("%s:%d %s()... server_certificate_verify failed returned 0x%04x\n", __FILE__, __LINE__, __FUNCTION__, *flags);
+        KAWAII_MQTT_LOG_E("%s:%d %s()... server_certificate_verify failed returned 0x%04x\n", __FILE__, __LINE__, __FUNCTION__, *flags);
     return *flags;
 }
 #endif
@@ -50,7 +50,7 @@ static int nettype_tls_entropy_source(void *data, uint8_t *output, size_t len, s
 
 static int nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_params)
 {
-    int rc = MQTT_SUCCESS_ERROR;
+    int rc = KAWAII_MQTT_SUCCESS_ERROR;
     
     mbedtls_platform_set_calloc_free(platform_memory_calloc, platform_memory_free);
     
@@ -69,13 +69,13 @@ static int nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_para
 
     if ((rc = mbedtls_ctr_drbg_seed(&(nettype_tls_params->ctr_drbg), mbedtls_entropy_func,
                                     &(nettype_tls_params->entropy), NULL, 0)) != 0) {
-        MQTT_LOG_E("mbedtls_ctr_drbg_seed failed returned 0x%04x", (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("mbedtls_ctr_drbg_seed failed returned 0x%04x", (rc < 0 )? -rc : rc);
         RETURN_ERROR(rc);
     }
 
     if ((rc = mbedtls_ssl_config_defaults(&(nettype_tls_params->ssl_conf), MBEDTLS_SSL_IS_CLIENT,
                                            MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
-        MQTT_LOG_E("mbedtls_ssl_config_defaults failed returned 0x%04x", (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("mbedtls_ssl_config_defaults failed returned 0x%04x", (rc < 0 )? -rc : rc);
         RETURN_ERROR(rc);
     }
 
@@ -87,7 +87,7 @@ static int nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_para
 
         if (0 != (rc = (mbedtls_x509_crt_parse(&(nettype_tls_params->ca_cert), (unsigned char *)n->ca_crt,
                                           (n->ca_crt_len + 1))))) {
-            MQTT_LOG_E("%s:%d %s()... parse ca crt failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+            KAWAII_MQTT_LOG_E("%s:%d %s()... parse ca crt failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
             RETURN_ERROR(rc);
         }
     }
@@ -96,7 +96,7 @@ static int nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_para
 
     if ((rc = mbedtls_ssl_conf_own_cert(&(nettype_tls_params->ssl_conf),
                                          &(nettype_tls_params->client_cert), &(nettype_tls_params->private_key))) != 0) {
-        MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_conf_own_cert failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_conf_own_cert failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
         RETURN_ERROR(rc);
     }
     
@@ -108,20 +108,20 @@ static int nettype_tls_init(network_t* n, nettype_tls_params_t* nettype_tls_para
     mbedtls_ssl_conf_read_timeout(&(nettype_tls_params->ssl_conf), n->timeout_ms);
 
     if ((rc = mbedtls_ssl_setup(&(nettype_tls_params->ssl), &(nettype_tls_params->ssl_conf))) != 0) {
-        MQTT_LOG_E("mbedtls_ssl_setup failed returned 0x%04x", (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("mbedtls_ssl_setup failed returned 0x%04x", (rc < 0 )? -rc : rc);
         RETURN_ERROR(rc);
     }
 
 #if defined(MBEDTLS_X509_CRT_PARSE_C)
     if ((rc = mbedtls_ssl_set_hostname(&(nettype_tls_params->ssl), n->host)) != 0) {
-        MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_set_hostname failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_set_hostname failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
         RETURN_ERROR(rc);
     }
 #endif
 
     mbedtls_ssl_set_bio(&(nettype_tls_params->ssl), &(nettype_tls_params->socket_fd), mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 
@@ -129,16 +129,16 @@ int nettype_tls_connect(network_t* n)
 {
     int rc;
     if (NULL == n)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
     
     nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) platform_memory_alloc(sizeof(nettype_tls_params_t));
 
     if (NULL == nettype_tls_params)
-        RETURN_ERROR(MQTT_MEM_NOT_ENOUGH_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_MEM_NOT_ENOUGH_ERROR);
 
 
     rc = nettype_tls_init(n, nettype_tls_params);
-    if (MQTT_SUCCESS_ERROR != rc)
+    if (KAWAII_MQTT_SUCCESS_ERROR != rc)
         goto exit;
 
     if (0 != (rc = mbedtls_net_connect(&(nettype_tls_params->socket_fd), n->host, n->port, MBEDTLS_NET_PROTO_TCP)))
@@ -146,10 +146,10 @@ int nettype_tls_connect(network_t* n)
 
     while ((rc = mbedtls_ssl_handshake(&(nettype_tls_params->ssl))) != 0) {
         if (rc != MBEDTLS_ERR_SSL_WANT_READ && rc != MBEDTLS_ERR_SSL_WANT_WRITE) {
-            MQTT_LOG_E("%s:%d %s()...mbedtls handshake failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+            KAWAII_MQTT_LOG_E("%s:%d %s()...mbedtls handshake failed returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
 #if defined(MBEDTLS_X509_CRT_PARSE_C)
             if (rc == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
-                MQTT_LOG_E("%s:%d %s()...unable to verify the server's certificate", __FILE__, __LINE__, __FUNCTION__);
+                KAWAII_MQTT_LOG_E("%s:%d %s()...unable to verify the server's certificate", __FILE__, __LINE__, __FUNCTION__);
             }
 #endif
             goto exit;
@@ -157,12 +157,12 @@ int nettype_tls_connect(network_t* n)
     }
 
     if ((rc = mbedtls_ssl_get_verify_result(&(nettype_tls_params->ssl))) != 0) {
-        MQTT_LOG_E("%s:%d %s()...mbedtls_ssl_get_verify_result returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+        KAWAII_MQTT_LOG_E("%s:%d %s()...mbedtls_ssl_get_verify_result returned 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
         goto exit;
     }
 
     n->nettype_tls_params = nettype_tls_params;
-    RETURN_ERROR(MQTT_SUCCESS_ERROR)
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR)
 
 exit:
     platform_memory_free(nettype_tls_params);
@@ -203,7 +203,7 @@ int nettype_tls_write(network_t *n, unsigned char *buf, int len, int timeout)
     platform_timer_t timer;
 
     if (NULL == n)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
     
     nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) n->nettype_tls_params;
 
@@ -216,7 +216,7 @@ int nettype_tls_write(network_t *n, unsigned char *buf, int len, int timeout)
         if (rc > 0) {
             write_len += rc;
         } else if ((rc == 0) || ((rc != MBEDTLS_ERR_SSL_WANT_WRITE) && (rc != MBEDTLS_ERR_SSL_WANT_READ) && (rc != MBEDTLS_ERR_SSL_TIMEOUT))) {
-            MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_write failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+            KAWAII_MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_write failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
             break;
         } 
     } while((!platform_timer_is_expired(&timer)) && (write_len < len));
@@ -231,7 +231,7 @@ int nettype_tls_read(network_t *n, unsigned char *buf, int len, int timeout)
     platform_timer_t timer;
 
     if (NULL == n)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
     
     nettype_tls_params_t *nettype_tls_params = (nettype_tls_params_t *) n->nettype_tls_params;
 
@@ -244,7 +244,7 @@ int nettype_tls_read(network_t *n, unsigned char *buf, int len, int timeout)
         if (rc > 0) {
             read_len += rc;
         } else if ((rc == 0) || ((rc != MBEDTLS_ERR_SSL_WANT_WRITE) && (rc != MBEDTLS_ERR_SSL_WANT_READ) && (rc != MBEDTLS_ERR_SSL_TIMEOUT))) {
-            // MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_read failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
+            // KAWAII_MQTT_LOG_E("%s:%d %s()... mbedtls_ssl_read failed: 0x%04x", __FILE__, __LINE__, __FUNCTION__, (rc < 0 )? -rc : rc);
             break;
         } 
     } while((!platform_timer_is_expired(&timer)) && (read_len < len));
@@ -252,4 +252,4 @@ int nettype_tls_read(network_t *n, unsigned char *buf, int len, int timeout)
     return read_len;
 }
 
-#endif /* MQTT_NETWORK_TYPE_NO_TLS */
+#endif /* KAWAII_MQTT_NETWORK_TYPE_NO_TLS */

+ 2 - 2
network/nettype_tls.h

@@ -14,7 +14,7 @@
 #include "mqtt_error.h"
 #include "mqtt_log.h"
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
 
 typedef struct nettype_tls_params {
     mbedtls_net_context         socket_fd;        /**< mbed TLS network context. */
@@ -34,6 +34,6 @@ int nettype_tls_write(network_t *n, unsigned char *buf, int len, int timeout);
 int nettype_tls_connect(network_t* n);
 void nettype_tls_disconnect(network_t* n);
 
-#endif /* MQTT_NETWORK_TYPE_NO_TLS */
+#endif /* KAWAII_MQTT_NETWORK_TYPE_NO_TLS */
 
 #endif

+ 15 - 15
network/network.c

@@ -9,13 +9,13 @@
 #include "platform_memory.h"
 #include "nettype_tcp.h"
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
 #include "nettype_tls.h"
 #endif
 
 int network_read(network_t *n, unsigned char *buf, int len, int timeout)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     if (n->channel)
         return nettype_tls_read(n, buf, len, timeout);
 #endif
@@ -24,7 +24,7 @@ int network_read(network_t *n, unsigned char *buf, int len, int timeout)
 
 int network_write(network_t *n, unsigned char *buf, int len, int timeout)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     if (n->channel)
         return nettype_tls_write(n, buf, len, timeout);
 #endif
@@ -33,7 +33,7 @@ int network_write(network_t *n, unsigned char *buf, int len, int timeout)
 
 int network_connect(network_t *n)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     if (n->channel)
         return nettype_tls_connect(n);
 #endif
@@ -43,7 +43,7 @@ int network_connect(network_t *n)
 
 void network_disconnect(network_t *n)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     if (n->channel)
         nettype_tls_disconnect(n);
     else
@@ -54,20 +54,20 @@ void network_disconnect(network_t *n)
 int network_init(network_t *n, const char *host, const char *port, const char *ca)
 {
     if (NULL == n)
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     n->socket = -1;
     n->host = host;
     n->port = port;
 
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     n->channel = 0;
 
     if (NULL != ca) {
         network_set_ca(n, ca);
     }
 #endif
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 void network_release(network_t* n)
@@ -80,33 +80,33 @@ void network_release(network_t* n)
 
 void network_set_channel(network_t *n, int channel)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     n->channel = channel;
 #endif
 }
 
 int network_set_ca(network_t *n, const char *ca)
 {
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     if ((NULL == n) || (NULL == ca))
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
     
     n->ca_crt = ca;
     n->ca_crt_len = strlen(ca);
     n->channel = NETWORK_CHANNEL_TLS;
-    n->timeout_ms = MQTT_TLS_HANDSHAKE_TIMEOUT;
+    n->timeout_ms = KAWAII_MQTT_TLS_HANDSHAKE_TIMEOUT;
 #endif
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 
 int network_set_host_port(network_t* n, char *host, char *port)
 {
     if (!(n && host && port))
-        RETURN_ERROR(MQTT_NULL_VALUE_ERROR);
+        RETURN_ERROR(KAWAII_MQTT_NULL_VALUE_ERROR);
 
     n->host = host;
     n->port = port;
 
-    RETURN_ERROR(MQTT_SUCCESS_ERROR);
+    RETURN_ERROR(KAWAII_MQTT_SUCCESS_ERROR);
 }
 

+ 1 - 1
network/network.h

@@ -17,7 +17,7 @@ typedef struct network {
     const char                  *host;
     const char                  *port;
     int                         socket;
-#ifndef MQTT_NETWORK_TYPE_NO_TLS
+#ifndef KAWAII_MQTT_NETWORK_TYPE_NO_TLS
     int                         channel;        /* tcp or tls */
     const char                  *ca_crt;
     unsigned int                ca_crt_len;

+ 3 - 3
platform/RT-Thread/platform_net_socket.c

@@ -9,7 +9,7 @@
 
 int platform_net_socket_connect(const char *host, const char *port, int proto)
 {
-    int fd, ret = MQTT_SOCKET_UNKNOWN_HOST_ERROR;
+    int fd, ret = KAWAII_MQTT_SOCKET_UNKNOWN_HOST_ERROR;
     struct addrinfo hints, *addr_list, *cur;
     
     /* Do name resolution with both IPv6 and IPv4 */
@@ -25,7 +25,7 @@ int platform_net_socket_connect(const char *host, const char *port, int proto)
     for (cur = addr_list; cur != NULL; cur = cur->ai_next) {
         fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
         if (fd < 0) {
-            ret = MQTT_SOCKET_FAILED_ERROR;
+            ret = KAWAII_MQTT_SOCKET_FAILED_ERROR;
             continue;
         }
 
@@ -35,7 +35,7 @@ int platform_net_socket_connect(const char *host, const char *port, int proto)
         }
 
         platform_net_socket_close(fd);
-        ret = MQTT_CONNECT_FAILED_ERROR;
+        ret = KAWAII_MQTT_CONNECT_FAILED_ERROR;
     }
 
     freeaddrinfo(addr_list);

+ 2 - 2
platform/RT-Thread/platform_net_socket.h

@@ -11,7 +11,7 @@
 #include "network.h"
 #include "mqtt_error.h"
 
-#ifdef MQTT_NETSOCKET_USE_SAL
+#ifdef KAWAII_MQTT_NETSOCKET_USE_SAL
 
 #include <sys/socket.h>
 #include <sys/time.h>
@@ -28,7 +28,7 @@
 #include <lwip/sockets.h>
 #include "lwip/netdb.h"
 
-#endif // MQTT_NETSOCKET_USE_SAL
+#endif // KAWAII_MQTT_NETSOCKET_USE_SAL
 
 #define PLATFORM_NET_PROTO_TCP  0 /**< The TCP transport protocol */
 #define PLATFORM_NET_PROTO_UDP  1 /**< The UDP transport protocol */

+ 36 - 46
test/test.c

@@ -1,76 +1,66 @@
+
 /*
  * @Author: jiejie
  * @Github: https://github.com/jiejieTop
- * @Date: 2019-12-11 21:53:07
- * @LastEditTime: 2020-02-26 22:43:54
+ * @LastEditTime: 2020-06-17 14:35:29
  * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  */
+#include <stdio.h>
+#include <stdint.h>
 #include <rtthread.h>
 #include <rtdevice.h>
 #include <board.h>
 #include "mqttclient.h"
 
-mqtt_client_t client;
-client_init_params_t init_params;
 
-static void topic_test1_handler(void* client, message_data_t* msg)
+static void sub_topic_handle1(void* client, message_data_t* msg)
 {
     (void) client;
-    LOG_I("-----------------------------------------------------------------------------------");
-    LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
-    LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
+    KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
+    KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
 }
 
-int main(void)
+
+static int mqtt_publish_handle1(mqtt_client_t *client)
 {
-    int err;
-    char buf[100] = { 0 };
     mqtt_message_t msg;
     memset(&msg, 0, sizeof(msg));
 
     msg.qos = QOS0;
-    msg.payload = (void *) buf;
+    msg.payload = (void *) "T2MB7TIlYNL7F5pJ4Qp0";
+
+    return mqtt_publish(client, "sub_topic1", &msg);
+}
+
 
-    log_init();
+int main(void)
+{
+    mqtt_client_t *client = NULL;
 
     rt_thread_delay(6000);
     
-    init_params.read_buf_size = 1024;
-    init_params.write_buf_size = 1024;
-#ifdef KAWAII_MQTT_NETWORK_TYPE_TLS
-    extern const char *test_ca_get();
-    init_params.connect_params.network_params.network_ssl_params.ca_crt = test_ca_get();
-    init_params.connect_params.network_params.port = "8883";
-#else
-    init_params.connect_params.network_params.port = "1883";
-#endif
-    init_params.connect_params.network_params.addr = "www.jiejie01.top"; //"47.95.164.112";//"jiejie01.top"; //"129.204.201.235"; //"192.168.1.101";
+    mqtt_log_init();
 
-    init_params.connect_params.user_name = random_string(10); // random_string(10); //"jiejietop-acer1";
-    init_params.connect_params.password = random_string(10);; //random_string(10); // "123456";
-    init_params.connect_params.client_id = random_string(10);; //random_string(10); // "clientid-acer1";
-    init_params.connect_params.clean_session = 1;
+    client = mqtt_lease();
 
-    mqtt_init(&client, &init_params);
+    mqtt_set_host(client, "www.jiejie01.top");
+    mqtt_set_port(client, "1883");
+    mqtt_set_user_name(client, "FoBxDRFwe6");
+    mqtt_set_password(client, "EDgftkg6rY");
+    mqtt_set_client_id(client, "5PtUa6aJ5h");
+    mqtt_set_clean_session(client, 1);
+    mqtt_set_keep_alive_interval(client, 50);
+    mqtt_set_cmd_timeout(client, 5000);
+    mqtt_set_read_buf_size(client, 2048);
+    mqtt_set_write_buf_size(client, 2048);
 
-    err = mqtt_connect(&client);
-    
-    LOG_I("mqtt connect return %d", err);
-    
-    err = mqtt_subscribe(&client, "rtt-topic1", QOS0, topic_test1_handler);
-    err += mqtt_subscribe(&client, "rtt-topic2", QOS0, NULL);
-    
-    LOG_I("mqtt subscribe return %d", err);
-    
-    while (1) {
+    mqtt_connect(client);
+    mqtt_subscribe(client, "sub_topic1", QOS0, sub_topic_handle1);
 
-        sprintf(buf, "welcome to mqttclient, this is a publish test, a rand number: %d ...", random_number());
-        mqtt_publish(&client, "rtt-topic1", &msg);
-        rt_thread_mdelay(1000);
-        
-        sprintf(buf, "welcome to mqttclient, this is a publish test, a rand number: %d ...", random_number());
-        mqtt_publish(&client, "rtt-topic2", &msg);
-        rt_thread_mdelay(1000);
+    while (1) {
+        mqtt_publish_handle1(client);
+                                                                                
+        mqtt_sleep_ms(4 * 1000);
     }
 }
-