booster/comport.c | patch | view | raw | blame | history | |
booster/comport.h | patch | view | raw | blame | history | |
booster/iniparser.c | patch | view | raw | blame | history | |
booster/linux_list.h | patch | view | raw | blame | history | |
booster/logger.c | patch | view | raw | blame | history | |
booster/logger.h | patch | view | raw | blame | history | |
booster/ringbuf.c | ●●●●● patch | view | raw | blame | history | |
booster/ringbuf.h | ●●●●● patch | view | raw | blame | history | |
booster/test/comport.c | patch | view | raw | blame | history | |
booster/test/logger.c | patch | view | raw | blame | history | |
booster/util_proc.c | patch | view | raw | blame | history | |
booster/util_proc.h | patch | view | raw | blame | history | |
booster/util_time.h | patch | view | raw | blame | history |
booster/comport.c
booster/comport.h
booster/iniparser.c
booster/linux_list.h
booster/logger.c
booster/logger.h
booster/ringbuf.c
New file @@ -0,0 +1,106 @@ /******************************************************************************** * Copyright: (C) 2021 LingYun IoT System Studio * All rights reserved. * * Filename: ringbuf.h * Description: This head file * * Version: 1.0.0(2021年04月29日) * Author: Guo Wenxue <guowenxue@gmail.com> * ChangeLog: 1, Release initial version on "2021年04月29日 12时18分32秒" * ********************************************************************************/ #include <string.h> #include <assert.h> #include "ringbuf.h" void rb_init (struct ring_buffer *ring, unsigned char* buff, int size) { memset (ring, 0, sizeof (struct ring_buffer)); ring->rd_pointer = 0; ring->wr_pointer = 0; ring->buffer= buff; ring->size = size; } int rb_write (struct ring_buffer *rb, unsigned char * buf, int len) { int total; int i; /* total = len = min(space, len) */ total = rb_free_size(rb); if(len > total) len = total; else total = len; i = rb->wr_pointer; if(i + len > rb->size) { memcpy(rb->buffer + i, buf, rb->size - i); buf += rb->size - i; len -= rb->size - i; i = 0; } memcpy(rb->buffer + i, buf, len); rb->wr_pointer = i + len; return total; } int rb_free_size (struct ring_buffer *rb) { return (rb->size - 1 - rb_data_size(rb)); } int rb_read (struct ring_buffer *rb, unsigned char * buf, int max) { int total; int i; /* total = len = min(used, len) */ total = rb_data_size(rb); if(max > total) max = total; else total = max; i = rb->rd_pointer; if(i + max > rb->size) { memcpy(buf, rb->buffer + i, rb->size - i); buf += rb->size - i; max -= rb->size - i; i = 0; } memcpy(buf, rb->buffer + i, max); rb->rd_pointer = i + max; return total; } int rb_data_size (struct ring_buffer *rb) { return ((rb->wr_pointer - rb->rd_pointer) & (rb->size-1)); } void rb_clear (struct ring_buffer *rb) { memset(rb->buffer,0,rb->size); rb->rd_pointer=0; rb->wr_pointer=0; } unsigned char rb_peek(struct ring_buffer* rb, int index) { assert(index < rb_data_size(rb)); return rb->buffer[((rb->rd_pointer + index) % rb->size)]; } booster/ringbuf.h
New file @@ -0,0 +1,57 @@ /******************************************************************************** * Copyright: (C) 2021 LingYun IoT System Studio * All rights reserved. * * Filename: ringbuf.h * Description: This head file * * Version: 1.0.0(2021年04月29日) * Author: Guo Wenxue <guowenxue@gmail.com> * ChangeLog: 1, Release initial version on "2021年04月29日 12时18分32秒" * ********************************************************************************/ #ifndef _RINGBUF_H_ #define _RINGBUF_H_ struct ring_buffer { unsigned char *buffer; int wr_pointer; int rd_pointer; int size; }; /* Initial the ring buffer */ void rb_init (struct ring_buffer *ring, unsigned char *buff, int size) ; /* Description: Write $len bytes data in $buf into ring buffer $rb * Return Value: The actual written into ring buffer data size, if ring buffer * left space size small than $len, then only part of the data be written into. */ int rb_write (struct ring_buffer *rb, unsigned char *buf, int len) ; /* Get ring buffer left free size */ int rb_free_size (struct ring_buffer *rb); /* Read $max bytes data from ring buffer $rb to $buf */ int rb_read (struct ring_buffer *rb, unsigned char *buf, int max); /* Read a specify $index byte data in ring buffer $rb */ unsigned char rb_peek(struct ring_buffer *rb, int index); /* Get data size in the ring buffer */ int rb_data_size (struct ring_buffer *rb); /* Clear the ring buffer data */ void rb_clear (struct ring_buffer *rb) ; #endif /* ----- #ifndef _RINGBUF_H_ ----- */ booster/test/comport.c
booster/test/logger.c
booster/util_proc.c
booster/util_proc.h
booster/util_time.h