LingYun IoT Studio NB-IoT research project
guowenxue
2018-11-19 ec8c799d8bb2ee69b5e6f56201231e8c905edeb1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
    Based on ringbuffer.h by Patrick Prasse (patrick.prasse@gmx.net). Code
    has been modified by Telenor and Gemalto.
 
 */
 
#ifndef __CP_RINGBUF_H_
#define __CP_RINGBUF_H_
 
#include <sys/types.h>
 
struct ring_buffer {
    u_char *buffer;
    int wr_pointer;
    int rd_pointer;
    int size;
};
 
/* Initial the ring buffer */
void rb_init (struct ring_buffer *ring, u_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, u_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, u_char * buf, int max);
 
/* Read a specify $index byte data in ring buffer $rb  */
u_char rb_peek(struct ring_buffer* rb, int index);
 
/* Get data size in the ring buffer  */
int rb_data_size (struct ring_buffer *);
 
/* Clear the ring buffer data  */
void rb_clear (struct ring_buffer *rb) ;
 
#endif /* __CP_RINGBUF_H_ */