add mqttclient to the component, and add fire stm32f429 board demo.

This commit is contained in:
jiejieTop
2020-02-20 00:09:00 +08:00
committed by jiejieTop
parent 6731d4692d
commit 8f76e16646
281 changed files with 145740 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-26 19:11:34
* @LastEditTime : 2019-12-28 01:51:38
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "config.h"
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;
}

View File

@@ -0,0 +1,6 @@
#!/bin/bash
mkdir -p build
cd build
cmake ..
make

View File

@@ -0,0 +1,93 @@
/*
* @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_

View File

@@ -0,0 +1,133 @@
#include "fifo.h"
#include <string.h>
static unsigned int _flbs(unsigned int x) /* find last bit set*/
{
unsigned int r = 32;
if (!x)
return 0;
if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
}
return r;
}
static unsigned int _fifo_align(unsigned int x)
{
return (1 << (_flbs(x-1)-1)); //memory down alignment
}
fifo_t fifo_create(unsigned int size)
{
fifo_t fifo;
if (0 == size)
return NULL;
if (size & (size - 1))
size = _fifo_align(size);
fifo = (fifo_t)salof_alloc((sizeof(struct fifo) + size));
if (NULL != fifo) {
fifo->buff = (unsigned char *)fifo + sizeof(struct fifo);
fifo->mutex = salof_mutex_create();
fifo->sem = salof_sem_create();
if ((NULL == fifo->mutex) || (NULL == fifo->sem)) {
salof_free(fifo);
return NULL;
}
fifo->size = size;
fifo->in = 0;
fifo->out = 0;
return fifo;
}
return NULL;
}
unsigned int fifo_write(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
{
int err, l;
if((!fifo) || (!buff) || (!len))
return 0;
err = salof_mutex_pend(fifo->mutex, timeout);
if(err == -1)
return 0;
len = FIFO_MIN(len, (fifo->size - fifo->in + fifo->out));
l = FIFO_MIN(len, (fifo->size - (fifo->in & (fifo->size -1))));
memcpy(((unsigned char *)fifo->buff + (fifo->in & (fifo->size -1))), buff, l);
memcpy(fifo->buff, (unsigned char *)buff + l, len - l);
fifo->in += len;
salof_mutex_post(fifo->mutex);
salof_sem_post(fifo->sem);
return len;
}
unsigned int fifo_read(fifo_t fifo, void *buff, unsigned int len, unsigned int timeout)
{
int l;
salof_sem_pend(fifo->sem, timeout);
if((!fifo) || (!buff) || (!len))
return 0;
len = FIFO_MIN(len, fifo->in - fifo->out);
l = FIFO_MIN(len, (fifo->size - (fifo->out & (fifo->size -1))));
memcpy(buff, ((unsigned char *)fifo->buff + (fifo->out & (fifo->size -1))), l);
memcpy((unsigned char *)buff + l, fifo->buff, len - l);
fifo->out += len;
return len;
}
unsigned int fifo_read_able(fifo_t fifo)
{
if(NULL == fifo)
return 0;
else if(fifo->in == fifo->out)
return 0;
else if(fifo->in > fifo->out)
return (fifo->in - fifo->out);
return (fifo->size - (fifo->out - fifo->in));
}
unsigned int fifo_write_able(fifo_t fifo)
{
return (fifo->size - fifo_read_able(fifo));
}

View File

@@ -0,0 +1,37 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-25 23:54:38
* @LastEditTime : 2019-12-28 01:04:08
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _FIFO_H_
#define _FIFO_H_
#include "config.h"
#define FIFO_READ 0
#define FIFO_WRITE 1
#define FIFO_MAX(a,b) (((a) > (b)) ? (a) : (b))
#define FIFO_MIN(a,b) (((a) < (b)) ? (a) : (b))
struct fifo
{
unsigned int size; /* fifo size */
unsigned int in; /* data input pointer (in % size) */
unsigned int out; /* data output pointer (out % size) */
salof_mutex mutex; /* mutex */
salof_sem sem; /* sem */
void *buff; /* data area */
};
typedef struct fifo * 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);
#endif // !_FIFO_H_

View File

@@ -0,0 +1,288 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-25 23:54:19
* @LastEditTime : 2019-12-28 01:53:41
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "format.h"
static int _get_atoi(const char **str)
{
int n;
for (n = 0; is_digit(**str); (*str)++)
n = n * 10 + **str - '0';
return n;
}
static void _buff_put_char(char *buf, unsigned int *pos, unsigned int max, char c)
{
if (*pos < max)
buf[(*pos)] = c;
(*pos)++;
}
/**
* Formats an integer number
* buf - buffer to print into
* len - current position in buffer
* maxlen - last valid position in buf
* num - number to print
* base - it's base
* width - how many spaces this should have; padding
* flags - above F flags
*/
static void _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;
char altb[8]; // small buf for sign and #
int n = num;
int npad; // number of pads
char pchar = ' '; // padding character
char *digits = "0123456789ABCDEF";
char *ldigits = "0123456789abcdef";
int i, j;
if (base < 2 || base > 16)
return;
if (flags & F_SMALL) digits = ldigits;
if (flags & F_LEFT) flags &= ~F_ZEROPAD;
if ((flags & F_SIGNED) && num < 0) {
n = -num;
sign = '-';
} else if (flags & F_PLUS) {
sign = '+';
} else if (flags & F_SPACE)
sign = ' ';
i = 0;
do {
nbuf[i++] = digits[n % base];
n = n / base;
} while (n > 0);
j = 0;
if (sign) altb[j++] = sign;
if (flags & F_ALTERNATE) {
if (base == 8 || base == 16) {
altb[j++] = '0';
if (base == 16)
altb[j++] = (flags & F_SMALL) ? 'x' : 'X';
}
}
altb[j] = 0;
npad = width > i + j ? width - i - j : 0;
if (width > i + j)
npad = width - i - j;
if (npad > 0 && ((flags & F_LEFT) == 0)) {
if (flags & F_ZEROPAD) {
for (j = 0; altb[j]; j++)
_buff_put_char(buf, len, maxlen, altb[j]);
altb[0] = 0;
}
while (npad-- > 0)
_buff_put_char(buf, len, maxlen, (flags & F_ZEROPAD) ? '0' : ' ');
}
for (j = 0; altb[j]; j++)
_buff_put_char(buf, len, maxlen, altb[j]);
while (i-- > 0)
_buff_put_char(buf, len, maxlen, nbuf[i]);
if (npad > 0 && (flags & F_LEFT))
while(npad-- > 0)
_buff_put_char(buf, len, maxlen, pchar);
}
static void _format_char(char *buf, unsigned int *pos, unsigned int max, char c,
int width, int flags)
{
int npad = 0;
if (width > 0) npad = width - 1;
if (npad < 0) npad = 0;
if (npad && ((flags & F_LEFT) == 0))
while (npad-- > 0)
_buff_put_char(buf, pos, max, ' ');
_buff_put_char(buf, pos, max, c);
if (npad && (flags & F_LEFT))
while (npad-- > 0)
_buff_put_char(buf, pos, max, ' ');
}
/**
* strlen()
*/
static unsigned int _str_len(char *s)
{
unsigned int i;
for (i = 0; *s; i++, s++)
;
return i;
}
static void _format_str(char *buf, unsigned int *pos, unsigned int max, char *s,
int width, int flags)
{
int npad = 0;
if (width > 0) npad = width - _str_len(s);
if (npad < 0) npad = 0;
if (npad && ((flags & F_LEFT) == 0))
while (npad-- > 0)
_buff_put_char(buf, pos, max, ' ');
while (*s)
_buff_put_char(buf, pos, max, *s++);
if (npad && (flags & F_LEFT))
while (npad-- > 0)
_buff_put_char(buf, pos, max, ' ');
}
/***********************************************************************************************************************/
/**
* 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)
{
unsigned int n = 0;
char c, *s;
char state = 0;
signed long long num;
int base;
int flags, width, precision, lflags;
if (!buf) size = 0;
for (;;) {
c = *fmt++;
if (state == S_DEFAULT) {
if (c == '%') {
state = S_FLAGS;
flags = 0;
} else {
_buff_put_char(buf, &n, size, c);
}
} else if (state == S_FLAGS) {
switch (c) {
case '#': flags |= F_ALTERNATE; break;
case '0': flags |= F_ZEROPAD; break;
case '-': flags |= F_LEFT; break;
case ' ': flags |= F_SPACE; break;
case '+': flags |= F_PLUS; break;
case '\'':
case 'I' : break; // not yet used
default: fmt--; width = 0; state = S_WIDTH;
}
} else if (state == S_WIDTH) {
if (c == '*') {
width = va_arg(ap, int);
if (width < 0) {
width = -width;
flags |= F_LEFT;
}
} else if (is_digit(c) && c > '0') {
fmt--;
width = _get_atoi(&fmt);
} else {
fmt--;
precision = -1;
state = S_PRECIS;
}
} else if (state == S_PRECIS) {
// Ignored for now, but skip it
if (c == '.') {
if (is_digit(*fmt))
precision = _get_atoi(&fmt);
else if (*fmt == '*')
precision = va_arg(ap, int);
precision = precision < 0 ? 0 : precision;
} else
fmt--;
lflags = 0;
state = S_LENGTH;
} else if (state == S_LENGTH) {
switch(c) {
case 'h': lflags = lflags == L_CHAR ? L_SHORT : L_CHAR; break;
case 'l': lflags = lflags == L_LONG ? L_LLONG : L_LONG; break;
case 'L': lflags = L_DOUBLE; break;
default: fmt--; state = S_CONV;
}
} else if (state == S_CONV) {
if (c == 'd' || c == 'i' || c == 'o' || c == 'b' || c == 'u'
|| c == 'x' || c == 'X') {
if (lflags == L_LONG)
num = va_arg(ap, int);
else if (lflags & (L_LLONG | L_DOUBLE))
num = va_arg(ap, signed long long);
else if (c == 'd' || c == 'i')
num = va_arg(ap, int);
else
num = (unsigned int) va_arg(ap, int);
base = 10;
if (c == 'd' || c == 'i') {
flags |= F_SIGNED;
} else if (c == 'x' || c == 'X') {
flags |= c == 'x' ? F_SMALL : 0;
base = 16;
} else if (c == 'o') {
base = 8;
} else if (c == 'b') {
base = 2;
}
_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);
} else if (c == 's') {
s = va_arg(ap, char *);
if (!s)
s = "(null)";
_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);
} else if (c == '%') {
_buff_put_char(buf, &n, size, c);
} else {
_buff_put_char(buf, &n, size, '%');
_buff_put_char(buf, &n, size, c);
}
state = S_DEFAULT;
}
if (c == 0)
break;
}
n--;
if (n < size)
buf[n] = 0;
else if (size > 0)
buf[size - 1] = 0;
return n;
}

View File

@@ -0,0 +1,45 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-25 23:54:38
* @LastEditTime : 2019-12-26 20:10:28
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _FORMAT_H_
#define _FORMAT_H_
#include "config.h"
#include <stdarg.h>
#define FORMAT_BUF_LEN 12
/* Format states */
#define S_DEFAULT 0
#define S_FLAGS 1
#define S_WIDTH 2
#define S_PRECIS 3
#define S_LENGTH 4
#define S_CONV 5
/* Lenght flags */
#define L_CHAR 1
#define L_SHORT 2
#define L_LONG 3
#define L_LLONG 4
#define L_DOUBLE 5
#define F_ALTERNATE 0001 // put 0x infront 16, 0 on octals, b on binary
#define F_ZEROPAD 0002 // value should be zero padded
#define F_LEFT 0004 // left justified if set, otherwise right justified
#define F_SPACE 0010 // place a space before positive number
#define F_PLUS 0020 // show +/- on signed numbers, default only for -
#define F_SIGNED 0040 // is an unsigned number?
#define F_SMALL 0100 // use lowercase for hex?
#define is_digit(c) (c >= '0' && c <= '9')
int format_nstr(char *buf, unsigned int size, const char *fmt, va_list ap);
#endif // !_FORMAT_H_

View File

@@ -0,0 +1,108 @@
/*
* @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.
*/
/** synchronous asynchronous log output framework */
#include "salof.h"
#ifndef SALOF_BUFF_SIZE
#define SALOF_BUFF_SIZE (1024U)
#endif
#ifndef SALOF_FIFO_SIZE
#define SALOF_FIFO_SIZE (2048U)
#endif
static int salof_out(char *buf, int len);
#if USE_SALOF
#include <string.h>
static fifo_t _salof_fifo = NULL;
static int _len;
static char _out_buff[SALOF_BUFF_SIZE];
#if !USE_IDLE_HOOK
static salof_tcb _salof_task;
void salof_task(void *parm);
#else
#if !defined(salof_handler)
#error "salof_handler need to be defined as your hook function"
#endif
#endif
#endif
static char _format_buff[SALOF_BUFF_SIZE];
int salof_init(void)
{
#if USE_SALOF
_salof_fifo = fifo_create(SALOF_FIFO_SIZE);
if(_salof_fifo == NULL)
return -1;
#if !USE_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;
#endif
#endif
return 0;
}
void salof(const char *fmt, ...)
{
va_list args;
int len;
va_start(args, fmt);
len = format_nstr(_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);
#else
salof_out(_format_buff, len);
#endif
va_end(args);
}
static int salof_out(char *buf, int len)
{
return send_buff(buf, len);
}
#if USE_SALOF
void salof_handler( void )
{
_len = fifo_read(_salof_fifo, _out_buff, sizeof(_out_buff), 0);
if(_len > 0) {
salof_out((char *)_out_buff, _len);
memset(_out_buff, 0, _len);
}
}
#endif
#if !USE_IDLE_HOOK
void salof_task(void *parm)
{
(void)parm;
while(1)
{
#if USE_SALOF
salof_handler();
#endif
}
}
#endif

View File

@@ -0,0 +1,124 @@
#ifndef _SALOF_H_
#define _SALOF_H_
#include "format.h"
#include "fifo.h"
#include <stdio.h>
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
#if USE_LOG
#if USE_SALOF
#define PRINT_LOG salof
#else
#if ((!USE_SALOF)&&(!PRINT_LOG))
#define 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"
#endif
#endif
#if LOG_TS || LOG_TAR
#endif
#if LOG_COLOR
#define LOG_START(l, c) PRINT_LOG("\033\n["#c"m["#l"] >> ")
#define LOG_END PRINT_LOG("\033[0m")
#else
#define LOG_START(l, c) PRINT_LOG("\n["#l"] >> ")
#define 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())
#else
#define LOG_T
#endif
#define LOG_LINE(l, c, fmt, ...) \
do { \
LOG_START(l, c); \
LOG_T; \
PRINT_LOG(fmt, ##__VA_ARGS__); \
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)
#ifndef LOG_LEVEL
#define LOG_LEVEL WARN_LEVEL
#endif
#if LOG_LEVEL < DEBUG_LEVEL
#define LOG_DEBUG(fmt, ...)
#else
#define LOG_DEBUG(fmt, ...) LOG_LINE(D, 0, fmt, ##__VA_ARGS__)
#endif
#if LOG_LEVEL < INFO_LEVEL
#define LOG_INFO(fmt, ...)
#else
#define LOG_INFO(fmt, ...) LOG_LINE(I, FC_GREEN, fmt, ##__VA_ARGS__)
#endif
#if LOG_LEVEL < WARN_LEVEL
#define LOG_WARN(fmt, ...)
#else
#define LOG_WARN(fmt, ...) LOG_LINE(W, FC_YELLOW, fmt, ##__VA_ARGS__)
#endif
#if LOG_LEVEL < ERR_LEVEL
#define LOG_ERR(fmt, ...)
#else
#define LOG_ERR(fmt, ...) LOG_LINE(E, FC_RED, fmt, ##__VA_ARGS__)
#endif
#if LOG_LEVEL < ASSERT_LEVEL
#define LOG_ASSERT(fmt, ...)
#define ASSERT(x)
#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__)
#endif
#else
#define LOG_DEBUG(fmt, ...)
#define LOG_INFO(fmt, ...)
#define LOG_WARN(fmt, ...)
#define LOG_ERR(fmt, ...)
#define LOG(fmt, ...)
#define ASSERT(x)
#endif
#endif // !_SALOF_H_

View File

@@ -0,0 +1,24 @@
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-26 20:00:29
* @LastEditTime : 2019-12-26 20:56:50
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#include "salof.h"
#include <stdio.h>
#include <unistd.h>
int main()
{
salof_init();
LOG_INFO("asfafasf");
sleep(1);
LOG_ERR("asfafasf");
LOG_WARN("asfafasf");
LOG_DEBUG("asfafasf\n");
sleep(1);
}