mqtt client release v1.1.0 ...
This commit is contained in:
21
components/connectivity/mqttclient/common/CMakeLists.txt
Normal file
21
components/connectivity/mqttclient/common/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
set(SUBDIRS "log")
|
||||
|
||||
aux_source_directory(. DIR_SRCS)
|
||||
|
||||
string(REGEX REPLACE ".*/(.*)" "\\1" LIB_NAME ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if (DIR_SRCS)
|
||||
foreach(libname ${LIBNAMES})
|
||||
if (${LIB_NAME} STREQUAL ${libname})
|
||||
add_library(${libname} ${CMAKE_LIB_TYPE} ${DIR_SRCS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
else()
|
||||
message(WARNING "not find is src file!")
|
||||
endif()
|
||||
|
||||
|
||||
foreach(subdir ${SUBDIRS})
|
||||
add_subdirectory(${subdir})
|
||||
endforeach()
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 22:46:33
|
||||
* @LastEditTime : 2020-01-05 17:01:51
|
||||
* @Description: the following code references TencentOS tiny, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
# include "list.h"
|
||||
|
||||
static void _list_add(list_t *node, list_t *prev, list_t *next)
|
||||
{
|
||||
next->prev = node;
|
||||
node->next = next;
|
||||
node->prev = prev;
|
||||
prev->next = node;
|
||||
}
|
||||
|
||||
static void _list_del(list_t *prev, list_t *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
static void _list_del_entry(list_t *entry)
|
||||
{
|
||||
_list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
void list_init(list_t *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
void list_add(list_t *node, list_t *list)
|
||||
{
|
||||
_list_add(node, list, list->next);
|
||||
}
|
||||
|
||||
void list_add_tail(list_t *node, list_t *list)
|
||||
{
|
||||
_list_add(node, list->prev, list);
|
||||
}
|
||||
|
||||
void list_del(list_t *entry)
|
||||
{
|
||||
_list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
void list_del_init(list_t *entry)
|
||||
{
|
||||
_list_del_entry(entry);
|
||||
list_init(entry);
|
||||
}
|
||||
|
||||
void list_move(list_t *node, list_t *list)
|
||||
{
|
||||
_list_del_entry(node);
|
||||
list_add(node, list);
|
||||
}
|
||||
|
||||
void list_move_tail(list_t *node, list_t *list)
|
||||
{
|
||||
_list_del_entry(node);
|
||||
list_add_tail(node, list);
|
||||
}
|
||||
|
||||
int list_is_empty(list_t *list)
|
||||
{
|
||||
return list->next == list;
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-27 03:25:58
|
||||
* @LastEditTime: 2020-02-25 05:42:32
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _LOG_H_
|
||||
#define _LOG_H_
|
||||
|
||||
#include "mqtt_defconfig.h"
|
||||
|
||||
#ifdef LOG_IS_SALOF
|
||||
#include "salof.h"
|
||||
|
||||
#define LOG_D(fmt, ...) LOG_DEBUG(fmt, ##__VA_ARGS__)
|
||||
#define LOG_I(fmt, ...) LOG_INFO(fmt, ##__VA_ARGS__)
|
||||
#define LOG_W(fmt, ...) LOG_WARN(fmt, ##__VA_ARGS__)
|
||||
#define LOG_E(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
|
||||
#define log_init salof_init
|
||||
#else
|
||||
#include <stdio.h>
|
||||
|
||||
#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)
|
||||
|
||||
#if LOG_LEVEL < DEBUG_LEVEL
|
||||
#define LOG_D(fmt, ...)
|
||||
#else
|
||||
#define LOG_D(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < INFO_LEVEL
|
||||
#define LOG_I(fmt, ...)
|
||||
#else
|
||||
#define LOG_I(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < WARN_LEVEL
|
||||
#define LOG_W(fmt, ...)
|
||||
#else
|
||||
#define LOG_W(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < ERR_LEVEL
|
||||
#define LOG_E(fmt, ...)
|
||||
#else
|
||||
#define LOG_E(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < ASSERT_LEVEL
|
||||
#define LOG_ASSERT(fmt, ...)
|
||||
#define ASSERT(x)
|
||||
#else
|
||||
#define LOG_ASSERT(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#define ASSERT(x) if((x)==0) LOG_ASSERT("%s, %d\n",__FILE__,__LINE__)
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < BASE_LEVEL
|
||||
#define LOG(fmt, ...)
|
||||
#else
|
||||
#define LOG(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#define log_init()
|
||||
#endif
|
||||
|
||||
#endif /* _LOG_H_ */
|
21
components/connectivity/mqttclient/common/log/CMakeLists.txt
Normal file
21
components/connectivity/mqttclient/common/log/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
set(INCDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SUBDIRS "arch")
|
||||
set(LIBNAMES "arch" "salof")
|
||||
set(OUTDIRS "build")
|
||||
|
||||
aux_source_directory(. LOG_DIR_SRCS)
|
||||
|
||||
add_library("salof" ${CMAKE_LIB_TYPE} ${LOG_DIR_SRCS})
|
||||
target_link_libraries("salof" "arch")
|
||||
|
||||
foreach(incdir ${INCDIRS})
|
||||
include_directories(${incdir})
|
||||
endforeach()
|
||||
|
||||
foreach(subdir ${SUBDIRS})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${subdir})
|
||||
endforeach()
|
||||
|
||||
link_directories(${LIBRARY_OUTPUT_PATH})
|
@@ -0,0 +1,7 @@
|
||||
set(SUBDIRS "linux")
|
||||
|
||||
foreach(subdir ${SUBDIRS})
|
||||
add_subdirectory(${subdir})
|
||||
endforeach()
|
||||
|
||||
|
@@ -7,17 +7,13 @@
|
||||
*/
|
||||
#include "salof_defconfig.h"
|
||||
|
||||
#ifdef USE_LOG
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
void *salof_alloc(unsigned int size)
|
||||
{
|
||||
return tos_mmheap_alloc(size);
|
||||
}
|
||||
|
||||
void *salof_calloc(size_t num, size_t size)
|
||||
{
|
||||
return tos_mmheap_calloc(num, size);
|
||||
}
|
||||
|
||||
void salof_free(void *mem)
|
||||
{
|
||||
@@ -34,13 +30,13 @@ salof_tcb salof_task_create(const char *name,
|
||||
salof_tcb task;
|
||||
k_err_t err;
|
||||
k_stack_t *task_stack;
|
||||
task = salof_calloc(1, sizeof(k_task_t));
|
||||
task = salof_alloc(sizeof(k_task_t));
|
||||
task_stack = salof_alloc(stack_size);
|
||||
err = tos_task_create(task,
|
||||
(char*)name,
|
||||
err = tos_task_create(task,
|
||||
(char*)name,
|
||||
task_entry,
|
||||
param,
|
||||
priority,
|
||||
param,
|
||||
priority,
|
||||
task_stack,
|
||||
stack_size,
|
||||
tick);
|
||||
@@ -57,7 +53,7 @@ salof_mutex salof_mutex_create(void)
|
||||
{
|
||||
salof_mutex mutex;
|
||||
mutex = salof_alloc(sizeof(k_mutex_t));
|
||||
tos_mutex_create((salof_mutex)mutex);
|
||||
tos_mutex_create((salof_mutex)mutex);
|
||||
return mutex;
|
||||
}
|
||||
|
||||
@@ -87,7 +83,7 @@ salof_sem salof_sem_create(void)
|
||||
{
|
||||
salof_sem sem;
|
||||
sem = salof_alloc(sizeof(k_sem_t));
|
||||
tos_sem_create((salof_sem)sem, 0);
|
||||
tos_sem_create((salof_sem)sem, 0);
|
||||
return sem;
|
||||
}
|
||||
|
||||
@@ -124,4 +120,4 @@ char *salof_get_task_name(void)
|
||||
return k_curr_task->name;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:56:34
|
||||
* @LastEditTime : 2020-01-18 13:50:21
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _SALOF_CONFIG_H_
|
||||
#define _SALOF_CONFIG_H_
|
||||
|
||||
#define USE_RTT 0
|
||||
#define USE_UCOSIII 1
|
||||
#define USE_FREERTOS 2
|
||||
#define USE_TENCENTOS 3
|
||||
#define USE_LINUX 4
|
||||
|
||||
#define USE_LOG (1U)
|
||||
#define USE_SALOF (1U)
|
||||
#define SALOF_OS USE_TENCENTOS
|
||||
#define USE_IDLE_HOOK (0U)
|
||||
|
||||
#define LOG_LEVEL DEBUG_LEVEL //WARN_LEVEL DEBUG_LEVEL
|
||||
#define LOG_COLOR (0U)
|
||||
#define LOG_TS (0U)
|
||||
#define LOG_TAR (0U)
|
||||
|
||||
#if USE_SALOF
|
||||
#define SALOF_BUFF_SIZE (512U)
|
||||
#define SALOF_FIFO_SIZE (1024*2U)
|
||||
#define SALOF_TASK_STACK_SIZE (1024U)
|
||||
#define SALOF_TASK_TICK (20U)
|
||||
#endif
|
||||
|
||||
#if !defined(SALOF_OS)
|
||||
#error "SALOF_OS isn't defined in 'cmb_cfg.h'"
|
||||
#endif
|
||||
|
||||
#if (SALOF_OS == USE_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
|
||||
#define salof_handler vApplicationIdleHook
|
||||
#endif
|
||||
#define SALOF_TASK_PRIO (0U)
|
||||
|
||||
#elif (SALOF_OS == USE_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
|
||||
|
||||
#elif (SALOF_OS == USE_LINUX)
|
||||
#include "pthread.h"
|
||||
#include "memory.h"
|
||||
#include <semaphore.h>
|
||||
#include <stdio.h>
|
||||
#define salof_mutex pthread_mutex_t*
|
||||
#define salof_sem sem_t*
|
||||
#define salof_tcb pthread_t*
|
||||
#define SALOF_TASK_PRIO (0U)
|
||||
#undef USE_IDLE_HOOK
|
||||
|
||||
#else
|
||||
#error "not supported OS type"
|
||||
#endif
|
||||
|
||||
void *salof_alloc(unsigned int size);
|
||||
void salof_free(void *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_mutex salof_mutex_create(void);
|
||||
void salof_mutex_delete(salof_mutex mutex);
|
||||
int salof_mutex_pend(salof_mutex mutex, unsigned int timeout);
|
||||
int salof_mutex_post(salof_mutex mutex);
|
||||
salof_sem salof_sem_create(void);
|
||||
void salof_sem_delete(salof_sem sem);
|
||||
int salof_sem_pend(salof_sem sem, unsigned int timeout);
|
||||
int salof_sem_post(salof_sem sem);
|
||||
unsigned int salof_get_tick(void);
|
||||
char *salof_get_task_name(void);
|
||||
extern int send_buff(char *buf, int len);
|
||||
#endif // !_SALOF_CONFIG_H_
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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,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_
|
||||
|
@@ -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
|
||||
#if 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);
|
||||
#if 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);
|
||||
#if 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
|
||||
#if 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
|
||||
#if SALOF_USING_SALOF
|
||||
salof_handler();
|
||||
#endif
|
||||
}
|
||||
|
@@ -10,113 +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
|
||||
#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 USE_LOG
|
||||
#ifdef SALOF_USING_LOG
|
||||
|
||||
#if USE_SALOF
|
||||
#define PRINT_LOG salof
|
||||
#if 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 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 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 < ASSERT_LEVEL
|
||||
#define LOG_ASSERT(fmt, ...)
|
||||
#define ASSERT(x)
|
||||
#if SALOF_LOG_LEVEL < SALOF_BASE_LEVEL
|
||||
#define SALOF_LOG(fmt, ...)
|
||||
#else
|
||||
#define LOG_ASSERT(fmt, ...) LOG_LINE(A, FC_RED, fmt, ##__VA_ARGS__)
|
||||
#define ASSERT(x) if((x)==0) LOG_ASSERT("%s, %d\n",__FILE__,__LINE__)
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL < BASE_LEVEL
|
||||
#define 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 ASSERT(x)
|
||||
#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_
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-25 23:56:34
|
||||
* @LastEditTime: 2020-03-02 01:32:32
|
||||
* @LastEditTime: 2020-06-17 18:50:26
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _SALOF_DEFCONFIG_H_
|
||||
@@ -10,45 +10,44 @@
|
||||
|
||||
#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 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 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 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 SALOF_DEBUG_LEVEL //SALOF_WARN_LEVEL SALOF_DEBUG_LEVEL
|
||||
#endif
|
||||
|
||||
#if USE_SALOF
|
||||
#if SALOF_USING_SALOF
|
||||
|
||||
#ifndef SALOF_BUFF_SIZE
|
||||
#define SALOF_BUFF_SIZE (512U)
|
||||
@@ -72,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_USING_IDLE_HOOK
|
||||
|
||||
#elif (SALOF_OS == USE_RTT)
|
||||
#elif (SALOF_OS == SALOF_USING_RTT)
|
||||
#include <rtconfig.h>
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
@@ -102,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>
|
||||
@@ -112,7 +111,7 @@
|
||||
#define salof_sem sem_t*
|
||||
#define salof_tcb pthread_t*
|
||||
#define SALOF_TASK_PRIO (0U)
|
||||
#undef USE_IDLE_HOOK
|
||||
#undef SALOF_USING_IDLE_HOOK
|
||||
|
||||
#else
|
||||
#error "not supported OS type"
|
||||
|
@@ -0,0 +1,13 @@
|
||||
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_ROOT_PATH}/${OUTDIRS}/bin/")
|
||||
|
||||
aux_source_directory(. CURRENT_DIR_SRCS)
|
||||
|
||||
add_executable(${TARGETS} ${CURRENT_DIR_SRCS})
|
||||
|
||||
foreach(findlib ${LIBNAMES})
|
||||
target_link_libraries(${TARGETS} ${findlib})
|
||||
endforeach()
|
||||
|
||||
find_package("Threads")
|
||||
target_link_libraries(${TARGETS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-11 02:04:49
|
||||
* @LastEditTime : 2020-01-11 02:12:16
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "random.h"
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
|
||||
static int mbedtls_get_random(unsigned char *buf, size_t len)
|
||||
{
|
||||
int i, j;
|
||||
unsigned long tmp;
|
||||
|
||||
for (i = 0; i < ((len + 3) & ~3) / 4; i++) {
|
||||
tmp = random_number();
|
||||
|
||||
for (j = 0; j < 4; j++) {
|
||||
if ((i * 4 + j) < len) {
|
||||
buf[i * 4 + j] = (unsigned char)(tmp >> (j * 8));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen)
|
||||
{
|
||||
mbedtls_get_random(output, len);
|
||||
*olen = len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-08 21:48:09
|
||||
* @LastEditTime : 2020-01-12 00:23:42
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_NET_C)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "platform_net_socket.h"
|
||||
#include "platform_timer.h"
|
||||
|
||||
/*
|
||||
* Initialize a context
|
||||
*/
|
||||
void mbedtls_net_init(mbedtls_net_context *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->fd = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initiate a TCP connection with host:port and the given protocol
|
||||
*/
|
||||
int mbedtls_net_connect(mbedtls_net_context *ctx, const char *host, const char *port, int proto)
|
||||
{
|
||||
int net_proto;
|
||||
|
||||
net_proto = (proto == MBEDTLS_NET_PROTO_UDP) ? PLATFORM_NET_PROTO_UDP : PLATFORM_NET_PROTO_TCP;
|
||||
|
||||
ctx->fd = platform_net_socket_connect(host, port, net_proto);
|
||||
|
||||
if (ctx->fd < 0) {
|
||||
return ctx->fd;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the socket blocking or non-blocking
|
||||
*/
|
||||
int mbedtls_net_set_block( mbedtls_net_context *ctx )
|
||||
{
|
||||
return platform_net_socket_set_block(ctx->fd);
|
||||
}
|
||||
|
||||
int mbedtls_net_set_nonblock( mbedtls_net_context *ctx )
|
||||
{
|
||||
return platform_net_socket_set_nonblock(ctx->fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read at most 'len' characters
|
||||
*/
|
||||
int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
int fd = ((mbedtls_net_context *)ctx)->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
return MBEDTLS_ERR_NET_INVALID_CONTEXT;
|
||||
}
|
||||
|
||||
ret = platform_net_socket_recv(fd, buf, len, 0);
|
||||
|
||||
if (ret == 0) {
|
||||
return MBEDTLS_ERR_SSL_WANT_READ;
|
||||
} else if (ret < 0) {
|
||||
return MBEDTLS_ERR_NET_RECV_FAILED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read at most 'len' characters, blocking for at most 'timeout' ms
|
||||
*/
|
||||
int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
int ret;
|
||||
int fd = ((mbedtls_net_context *)ctx)->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
return MBEDTLS_ERR_NET_INVALID_CONTEXT;
|
||||
}
|
||||
|
||||
ret = platform_net_socket_recv_timeout(fd, buf, len, timeout);
|
||||
|
||||
if (ret == 0) {
|
||||
return MBEDTLS_ERR_SSL_TIMEOUT;
|
||||
} else if (ret < 0) {
|
||||
return MBEDTLS_ERR_NET_RECV_FAILED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write at most 'len' characters
|
||||
*/
|
||||
|
||||
int mbedtls_net_send(void *ctx, const unsigned char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
int fd = ((mbedtls_net_context *) ctx)->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
return MBEDTLS_ERR_NET_INVALID_CONTEXT;
|
||||
}
|
||||
|
||||
ret = platform_net_socket_write(fd, (unsigned char*)buf, len);
|
||||
|
||||
if (ret == 0) {
|
||||
return MBEDTLS_ERR_SSL_WANT_WRITE;
|
||||
} else if (ret < 0) {
|
||||
return MBEDTLS_ERR_NET_SEND_FAILED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gracefully close the connection
|
||||
*/
|
||||
|
||||
void mbedtls_net_free(mbedtls_net_context *ctx)
|
||||
{
|
||||
if (ctx->fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// shutdown(ctx->fd, 2);
|
||||
platform_net_socket_close(ctx->fd);
|
||||
|
||||
ctx->fd = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Portable usleep helper
|
||||
*/
|
||||
void mbedtls_net_usleep( unsigned long usec )
|
||||
{
|
||||
platform_timer_usleep(usec);
|
||||
}
|
||||
|
||||
/* dtls */
|
||||
void mbedtls_dtls_net_init(mbedtls_net_context *ctx)
|
||||
{
|
||||
mbedtls_net_init(ctx);
|
||||
}
|
||||
|
||||
int mbedtls_dtls_net_connect(mbedtls_net_context *ctx, const char *host, const char *port, int proto)
|
||||
{
|
||||
return mbedtls_net_connect(ctx, host, port, proto);
|
||||
}
|
||||
|
||||
void mbedtls_dtls_net_usleep(unsigned long usec)
|
||||
{
|
||||
mbedtls_net_usleep(usec);
|
||||
}
|
||||
|
||||
int mbedtls_dtls_net_recv(void *ctx, unsigned char *buf, size_t len)
|
||||
{
|
||||
return mbedtls_net_recv(ctx, buf, len);
|
||||
}
|
||||
|
||||
int mbedtls_dtls_net_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return mbedtls_net_recv_timeout(ctx, buf, len, timeout);
|
||||
}
|
||||
|
||||
int mbedtls_dtls_net_send(void *ctx, const unsigned char *buf, size_t len)
|
||||
{
|
||||
return mbedtls_net_send(ctx, buf, len);
|
||||
}
|
||||
|
||||
void mbedtls_dtls_net_free(mbedtls_net_context *ctx)
|
||||
{
|
||||
mbedtls_net_free(ctx);
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_NET_C */
|
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-08 19:44:56
|
||||
* @LastEditTime : 2020-01-13 01:01:39
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "platform_timer.h"
|
||||
#include "timing_alt.h"
|
||||
|
||||
unsigned long mbedtls_timing_hardclock( void )
|
||||
{
|
||||
return 1600*1000*1000;
|
||||
}
|
||||
|
||||
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
|
||||
{
|
||||
struct mbedtls_timing_hr_time now;
|
||||
|
||||
now.timer_ms = platform_timer_now();
|
||||
|
||||
if (reset) {
|
||||
val->timer_ms = now.timer_ms;
|
||||
}
|
||||
|
||||
return (unsigned long)(now.timer_ms - val->timer_ms);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set delays to watch
|
||||
*/
|
||||
void mbedtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
|
||||
{
|
||||
mbedtls_timing_delay_context *ctx;
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = (mbedtls_timing_delay_context*)data;
|
||||
|
||||
ctx->int_ms = int_ms;
|
||||
ctx->fin_ms = fin_ms;
|
||||
|
||||
if (fin_ms != 0) {
|
||||
(void)mbedtls_timing_get_timer(&ctx->timer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get number of delays expired
|
||||
*/
|
||||
int mbedtls_timing_get_delay(void *data)
|
||||
{
|
||||
unsigned long elapsed_ms;
|
||||
mbedtls_timing_delay_context *ctx;
|
||||
|
||||
if (!data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx = (mbedtls_timing_delay_context*)data;
|
||||
|
||||
if (ctx->fin_ms == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
elapsed_ms = mbedtls_timing_get_timer(&ctx->timer, 0);
|
||||
|
||||
if (elapsed_ms >= ctx->fin_ms) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (elapsed_ms >= ctx->int_ms) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-08 19:41:14
|
||||
* @LastEditTime: 2020-01-08 19:44:11
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
/**
|
||||
* \file timing_alt.h
|
||||
*
|
||||
* \brief Portable interface to the CPU cycle counter
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#ifndef _TIMING_ALT_H_
|
||||
#define _TIMING_ALT_H_
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/**
|
||||
* @brief timer structure
|
||||
*/
|
||||
struct mbedtls_timing_hr_time {
|
||||
uint64_t timer_ms;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Context for mbedtls_timing_set/get_delay()
|
||||
*/
|
||||
typedef struct {
|
||||
struct mbedtls_timing_hr_time timer;
|
||||
uint32_t int_ms;
|
||||
uint32_t fin_ms;
|
||||
} mbedtls_timing_delay_context;
|
||||
|
||||
/**
|
||||
* @brief Return the elapsed time in milliseconds
|
||||
*
|
||||
* @param val points to a timer structure
|
||||
* @param reset if set to 1, the timer is restarted
|
||||
*/
|
||||
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset);
|
||||
|
||||
/**
|
||||
* @brief Set a pair of delays to watch
|
||||
* Must point to a valid mbedtls_timing_delay_context struct.
|
||||
*
|
||||
* @param data Pointer to timing data
|
||||
* @param int_ms First (intermediate) delay in milliseconds.
|
||||
* @param fin_ms Second (final) delay in milliseconds.
|
||||
* Pass 0 to cancel the current delay.
|
||||
*/
|
||||
void mbedtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms);
|
||||
|
||||
/**
|
||||
* @brief Get the status of delays
|
||||
* (Memory helper: number of delays passed.)
|
||||
*
|
||||
* @param data Pointer to timing data
|
||||
* Must point to a valid mbedtls_timing_delay_context struct.
|
||||
*
|
||||
* @return -1 if cancelled (fin_ms = 0)
|
||||
* 0 if none of the delays are passed,
|
||||
* 1 if only the intermediate delay is passed,
|
||||
* 2 if the final delay is passed.
|
||||
*/
|
||||
int mbedtls_timing_get_delay(void *data);
|
||||
|
||||
#endif
|
||||
|
@@ -2,11 +2,11 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 00:42:16
|
||||
* @LastEditTime: 2020-04-25 18:59:08
|
||||
* @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 _ERROR_H_
|
||||
#define _ERROR_H_
|
||||
#ifndef _MQTT_ERROR_H_
|
||||
#define _MQTT_ERROR_H_
|
||||
|
||||
typedef enum mqtt_error {
|
||||
MQTT_SSL_CERT_ERROR = -0x001C, /* cetr parse failed */
|
72
components/connectivity/mqttclient/common/mqtt_list.c
Normal file
72
components/connectivity/mqttclient/common/mqtt_list.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 22:46:33
|
||||
* @LastEditTime: 2020-04-27 23:28:12
|
||||
* @Description: the following code references TencentOS tiny, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
# include "mqtt_list.h"
|
||||
|
||||
static void _mqtt_list_add(mqtt_list_t *node, mqtt_list_t *prev, mqtt_list_t *next)
|
||||
{
|
||||
next->prev = node;
|
||||
node->next = next;
|
||||
node->prev = prev;
|
||||
prev->next = node;
|
||||
}
|
||||
|
||||
static void _mqtt_list_del(mqtt_list_t *prev, mqtt_list_t *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
static void _mqtt_list_del_entry(mqtt_list_t *entry)
|
||||
{
|
||||
_mqtt_list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
void mqtt_list_init(mqtt_list_t *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
void mqtt_list_add(mqtt_list_t *node, mqtt_list_t *list)
|
||||
{
|
||||
_mqtt_list_add(node, list, list->next);
|
||||
}
|
||||
|
||||
void mqtt_list_add_tail(mqtt_list_t *node, mqtt_list_t *list)
|
||||
{
|
||||
_mqtt_list_add(node, list->prev, list);
|
||||
}
|
||||
|
||||
void mqtt_list_del(mqtt_list_t *entry)
|
||||
{
|
||||
_mqtt_list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
void mqtt_list_del_init(mqtt_list_t *entry)
|
||||
{
|
||||
_mqtt_list_del_entry(entry);
|
||||
mqtt_list_init(entry);
|
||||
}
|
||||
|
||||
void mqtt_list_move(mqtt_list_t *node, mqtt_list_t *list)
|
||||
{
|
||||
_mqtt_list_del_entry(node);
|
||||
mqtt_list_add(node, list);
|
||||
}
|
||||
|
||||
void mqtt_list_move_tail(mqtt_list_t *node, mqtt_list_t *list)
|
||||
{
|
||||
_mqtt_list_del_entry(node);
|
||||
mqtt_list_add_tail(node, list);
|
||||
}
|
||||
|
||||
int mqtt_list_is_empty(mqtt_list_t *list)
|
||||
{
|
||||
return list->next == list;
|
||||
}
|
@@ -2,16 +2,16 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-11 22:47:55
|
||||
* @LastEditTime : 2020-01-08 20:39:26
|
||||
* @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 _LIST_H_
|
||||
#define _LIST_H_
|
||||
#ifndef _MQTT_LIST_H_
|
||||
#define _MQTT_LIST_H_
|
||||
|
||||
typedef struct list_node {
|
||||
struct list_node *next;
|
||||
struct list_node *prev;
|
||||
} list_t;
|
||||
typedef struct mqtt_list_node {
|
||||
struct mqtt_list_node *next;
|
||||
struct mqtt_list_node *prev;
|
||||
} mqtt_list_t;
|
||||
|
||||
#define OFFSET_OF_FIELD(type, field) \
|
||||
((size_t)&(((type *)0)->field))
|
||||
@@ -23,7 +23,7 @@ typedef struct list_node {
|
||||
{ &(node), &(node) }
|
||||
|
||||
#define LIST_DEFINE(list) \
|
||||
list_t list = { &(list), &(list) }
|
||||
mqtt_list_t list = { &(list), &(list) }
|
||||
|
||||
#define LIST_ENTRY(list, type, field) \
|
||||
CONTAINER_OF_FIELD(list, type, field)
|
||||
@@ -32,7 +32,7 @@ typedef struct list_node {
|
||||
LIST_ENTRY((list)->next, type, field)
|
||||
|
||||
#define LIST_FIRST_ENTRY_OR_NULL(list, type, field) \
|
||||
(list_is_empty(list) ? NULL : LIST_FIRST_ENTRY(list, type, field))
|
||||
(mqtt_list_is_empty(list) ? NULL : LIST_FIRST_ENTRY(list, type, field))
|
||||
|
||||
#define LIST_FOR_EACH(curr, list) \
|
||||
for (curr = (list)->next; curr != (list); curr = curr->next)
|
||||
@@ -49,14 +49,14 @@ typedef struct list_node {
|
||||
curr != (list); \
|
||||
curr = next, next = curr->prev)
|
||||
|
||||
void list_init(list_t *list);
|
||||
void list_add(list_t *node, list_t *list);
|
||||
void list_add_tail(list_t *node, list_t *list);
|
||||
void list_del(list_t *entry);
|
||||
void list_del_init(list_t *entry);
|
||||
void list_move(list_t *node, list_t *list);
|
||||
void list_move_tail(list_t *node, list_t *list);
|
||||
int list_is_empty(list_t *list);
|
||||
void mqtt_list_init(mqtt_list_t *list);
|
||||
void mqtt_list_add(mqtt_list_t *node, mqtt_list_t *list);
|
||||
void mqtt_list_add_tail(mqtt_list_t *node, mqtt_list_t *list);
|
||||
void mqtt_list_del(mqtt_list_t *entry);
|
||||
void mqtt_list_del_init(mqtt_list_t *entry);
|
||||
void mqtt_list_move(mqtt_list_t *node, mqtt_list_t *list);
|
||||
void mqtt_list_move_tail(mqtt_list_t *node, mqtt_list_t *list);
|
||||
int mqtt_list_is_empty(mqtt_list_t *list);
|
||||
|
||||
#endif /* _LIST_H_ */
|
||||
|
63
components/connectivity/mqttclient/common/mqtt_log.h
Normal file
63
components/connectivity/mqttclient/common/mqtt_log.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-27 03:25:58
|
||||
* @LastEditTime: 2020-06-17 20:28:18
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTT_LOG_H_
|
||||
#define _MQTT_LOG_H_
|
||||
|
||||
#include "mqtt_defconfig.h"
|
||||
|
||||
#define MQTT_LOG_BASE_LEVEL (0)
|
||||
#define MQTT_LOG_ERR_LEVEL (MQTT_LOG_BASE_LEVEL + 1)
|
||||
#define MQTT_LOG_WARN_LEVEL (MQTT_LOG_ERR_LEVEL + 1)
|
||||
#define MQTT_LOG_INFO_LEVEL (MQTT_LOG_WARN_LEVEL + 1)
|
||||
#define MQTT_LOG_DEBUG_LEVEL (MQTT_LOG_INFO_LEVEL + 1)
|
||||
|
||||
#ifdef MQTT_LOG_IS_SALOF
|
||||
#include "salof.h"
|
||||
|
||||
#define MQTT_LOG_D(fmt, ...) SALOF_LOG_DEBUG(fmt, ##__VA_ARGS__)
|
||||
#define MQTT_LOG_I(fmt, ...) SALOF_LOG_INFO(fmt, ##__VA_ARGS__)
|
||||
#define MQTT_LOG_W(fmt, ...) SALOF_LOG_WARN(fmt, ##__VA_ARGS__)
|
||||
#define MQTT_LOG_E(fmt, ...) SALOF_LOG_ERR(fmt, ##__VA_ARGS__)
|
||||
#define mqtt_log_init salof_init
|
||||
#else
|
||||
#include <stdio.h>
|
||||
|
||||
#if MQTT_LOG_LEVEL < MQTT_LOG_DEBUG_LEVEL
|
||||
#define MQTT_LOG_D(fmt, ...)
|
||||
#else
|
||||
#define MQTT_LOG_D(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if MQTT_LOG_LEVEL < MQTT_LOG_INFO_LEVEL
|
||||
#define MQTT_LOG_I(fmt, ...)
|
||||
#else
|
||||
#define MQTT_LOG_I(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if MQTT_LOG_LEVEL < MQTT_LOG_WARN_LEVEL
|
||||
#define MQTT_LOG_W(fmt, ...)
|
||||
#else
|
||||
#define MQTT_LOG_W(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if MQTT_LOG_LEVEL < MQTT_LOG_ERR_LEVEL
|
||||
#define MQTT_LOG_E(fmt, ...)
|
||||
#else
|
||||
#define MQTT_LOG_E(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#if MQTT_LOG_LEVEL < MQTT_LOG_BASE_LEVEL
|
||||
#define MQTT_LOG(fmt, ...)
|
||||
#else
|
||||
#define MQTT_LOG(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
|
||||
#endif
|
||||
|
||||
#define mqtt_log_init()
|
||||
#endif
|
||||
|
||||
#endif /* _LOG_H_ */
|
@@ -2,7 +2,7 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-09 19:25:05
|
||||
* @LastEditTime : 2020-01-10 08:54:24
|
||||
* @LastEditTime: 2020-06-16 14:50:33
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
@@ -25,6 +25,12 @@ int random_number(void)
|
||||
return do_random(last_seed ^ seed);
|
||||
}
|
||||
|
||||
// random number range interval [min, max)
|
||||
int random_number_range(unsigned int min, unsigned int max)
|
||||
{
|
||||
return (random_number() % (max - min)) + min;
|
||||
}
|
||||
|
||||
char *random_string(unsigned int len)
|
||||
{
|
||||
unsigned int i, flag, seed, random;
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#define RANDOM_MAX 0x7FFFFFFF
|
||||
|
||||
int random_number(void);
|
||||
int random_number_range(unsigned int min, unsigned int max);
|
||||
char *random_string(unsigned int len);
|
||||
|
||||
#endif /* _RANDOM_H_ */
|
||||
|
Reference in New Issue
Block a user