buffer.h
2.4 KB
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
/**@file
* @brief Declaration for the internal buffer and memory management
* @author Maria Jorba Brosa
* @date 08/06/2014
*
* The functions declared in this file manage the I2C functionality of the device to use with the sensors
*/
#ifndef BUFFER_H
#define BUFFER_H
#include "libwismart.h"
#include "json.h"
//!Soft limit definition
/*! This variable defines at which point the soft limit for used memory is reached. The specified value is used memory bytes. */
#define SOFT_LIMIT 8192 /* en bytes -> 8k * 1024 */
//!Hard limit definition
/*! This variable defines at which point the hard limit for used memory is reached. The specified value is used memory bytes.*/
#define HARD_LIMIT 10240
//! Memory OK status definition
#define MEMORY_OK 0
//! Soft limit status definition
#define SOFT_REACHED 1
//! Hard limit status definition
#define HARD_REACHED 2
//! Debug printing definition
/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */
#define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
//#define DBG_BUFFER(fmt,...) printf("")
//! Value write into buffer function
/*! This function stores data into a memory buffer. It frees the memory of the old one, which is passed by argument, and returns a new one with the value stored. */
char** put_message(char* info /*! Data to be stored */, char** buf /*! Old buffer */ ,uint32_t *index /*! Buffer index to store the data */, uint32_t *buf_len /*! Old buffer length */);
//! Memory check function
/*! This function checks the current used memory and returns the memory status definitions according to the amount of memory used. */
int check_memory(void);
//! Buffer data send function
/*! This function sends the data in a specified buffer to the server. If successful, it frees the memory used by it. */
int send(char** buf /*! Buffer to send */, uint32_t *index /*! Current buffer index */, uint32_t *size_buf /*! Buffer size */, char *provider_ID /*! Current module ID */, char *sensor_ID /*! Sensor ID for the data stored in that buffer */);
//! Buffer join function
/*! This function returns a copy of the buffer passed by argument with one more slot to store another piece of data from the sensors */
char** join_buf(char** buf /*! Old buffer */, uint32_t *buf_len /*! Old buffer length*/);
#endif