#ifndef _TXBUFFER_H
#define _TXBUFFER_H

#include <stdint.h>
#include "ble_gattc.h"
#include "ble_srv_common.h"

#ifdef __cplusplus
extern "C" {
#endif


#define WRITE_MESSAGE_LENGTH   32    /**< Length of the write message in the buffer */

typedef enum
{
    READ_REQ,  /**< Type identifying that this tx_message is a read request. */
    WRITE_REQ  /**< Type identifying that this tx_message is a write request. */
} tx_request_t;

/**@brief Structure for writing a message to the peer, i.e. CCCD.
 */
typedef struct
{
    uint8_t                  gattc_value[WRITE_MESSAGE_LENGTH];  /**< The message to write. */
    ble_gattc_write_params_t gattc_params;                       /**< GATTC parameters for this message. */
} write_params_t;

/**@brief Structure for holding data to be transmitted to the connected central.
 */
typedef struct
{
    uint16_t     conn_handle;  /**< Connection handle to be used when transmitting this message. */
    tx_request_t type;         /**< Type of this message, i.e. read or write message. */
    union
    {
        uint16_t       read_handle;  /**< Read request message. */
        write_params_t write_req;    /**< Write request message. */
    } req;
} tx_message_t;


typedef struct
{
    tx_message_t*  pStorage;
    uint32_t        iCapacity;
    uint32_t        iPushCount;
    uint32_t        iPullCount;
} STxBuffer;



void TxBufferInit(STxBuffer* pThis, tx_message_t* pStorage, uint32_t iCapacity);

void TxBufferReset(STxBuffer* pThis);

/**@brief Function for passing any pending request from the buffer to the stack.
 */
void TxBufferProcess(STxBuffer* pThis);

tx_message_t* TxBufferPush(STxBuffer* pThis);





#ifdef __cplusplus
}
#endif
#endif  // _TXBUFFER_H
