MeterLogger
Functions | Variables
queue.c File Reference
#include "queue.h"
#include "proto.h"
#include <esp8266.h>
Include dependency graph for queue.c:

Go to the source code of this file.

Functions

void ICACHE_FLASH_ATTR QUEUE_Init (QUEUE *queue, int bufferSize)
 
int32_t ICACHE_FLASH_ATTR QUEUE_Puts (QUEUE *queue, uint8_t *buffer, uint16_t len)
 
int32_t ICACHE_FLASH_ATTR QUEUE_Gets (QUEUE *queue, uint8_t *buffer, uint16_t *len, uint16_t maxLen)
 
BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty (QUEUE *queue)
 

Variables

uint8_t * last_rb_p_r
 
uint8_t * last_rb_p_w
 
uint32_t last_fill_cnt
 

Function Documentation

◆ QUEUE_Gets()

int32_t ICACHE_FLASH_ATTR QUEUE_Gets ( QUEUE queue,
uint8_t *  buffer,
uint16_t *  len,
uint16_t  maxLen 
)

Definition at line 61 of file queue.c.

References PROTO_ParseRb(), and QUEUE::rb.

Referenced by MQTT_Ping(), MQTT_Publish(), MQTT_Subscribe(), MQTT_Task(), and MQTT_UnSubscribe().

62 {
63  return PROTO_ParseRb(&queue->rb, buffer, len, maxLen);
64 }
RINGBUF rb
Definition: queue.h:37
I16 ICACHE_FLASH_ATTR PROTO_ParseRb(RINGBUF *rb, U8 *bufOut, U16 *len, U16 maxBufLen)
Definition: proto.c:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QUEUE_Init()

void ICACHE_FLASH_ATTR QUEUE_Init ( QUEUE queue,
int  bufferSize 
)

Definition at line 39 of file queue.c.

References QUEUE::buf, os_zalloc, QUEUE::rb, and RINGBUF_Init().

Referenced by MQTT_InitClient().

40 {
41  queue->buf = (uint8_t*)os_zalloc(bufferSize);
42  RINGBUF_Init(&queue->rb, queue->buf, bufferSize);
43 }
#define os_zalloc(s)
Definition: mem.h:44
I16 ICACHE_FLASH_ATTR RINGBUF_Init(RINGBUF *r, U8 *buf, I32 size)
init a RINGBUF object
Definition: ringbuf.c:16
uint8_t * buf
Definition: queue.h:36
RINGBUF rb
Definition: queue.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QUEUE_IsEmpty()

BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty ( QUEUE queue)

Definition at line 66 of file queue.c.

References FALSE, RINGBUF::fill_cnt, QUEUE::rb, and TRUE.

Referenced by MQTT_Task().

67 {
68  if(queue->rb.fill_cnt<=0)
69  return TRUE;
70  return FALSE;
71 }
#define FALSE
Definition: c_types.h:111
#define TRUE
Definition: c_types.h:110
RINGBUF rb
Definition: queue.h:37
volatile I32 fill_cnt
Definition: ringbuf.h:11
Here is the caller graph for this function:

◆ QUEUE_Puts()

int32_t ICACHE_FLASH_ATTR QUEUE_Puts ( QUEUE queue,
uint8_t *  buffer,
uint16_t  len 
)

Definition at line 44 of file queue.c.

References RINGBUF::fill_cnt, last_fill_cnt, last_rb_p_r, last_rb_p_w, RINGBUF::p_r, RINGBUF::p_w, PROTO_AddRb(), and QUEUE::rb.

Referenced by MQTT_Ping(), MQTT_Publish(), MQTT_Subscribe(), mqtt_tcpclient_recv(), and MQTT_UnSubscribe().

45 {
46  uint32_t ret;
47 
48  last_rb_p_r = queue->rb.p_r;
49  last_rb_p_w = queue->rb.p_w;
50  last_fill_cnt = queue->rb.fill_cnt;
51 
52  ret = PROTO_AddRb(&queue->rb, buffer, len);
53  if (ret == -1) {
54  // rolling ring buffer back
55  queue->rb.p_r = last_rb_p_r;
56  queue->rb.p_w = last_rb_p_w;
57  queue->rb.fill_cnt = last_fill_cnt;
58  }
59  return ret;
60 }
uint8_t * last_rb_p_w
Definition: queue.c:36
I16 ICACHE_FLASH_ATTR PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len)
Definition: proto.c:106
uint32_t last_fill_cnt
Definition: queue.c:37
RINGBUF rb
Definition: queue.h:37
uint8_t * last_rb_p_r
Definition: queue.c:35
U8 *volatile p_w
Definition: ringbuf.h:10
volatile I32 fill_cnt
Definition: ringbuf.h:11
U8 *volatile p_r
Definition: ringbuf.h:9
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ last_fill_cnt

uint32_t last_fill_cnt

Definition at line 37 of file queue.c.

Referenced by QUEUE_Puts().

◆ last_rb_p_r

uint8_t* last_rb_p_r

Definition at line 35 of file queue.c.

Referenced by QUEUE_Puts().

◆ last_rb_p_w

uint8_t* last_rb_p_w

Definition at line 36 of file queue.c.

Referenced by QUEUE_Puts().