# 1 "../buffer.c"
# 1 "D:\\Projects\\FOCE\\SensorNode\\SensorNode\\sensorNodeMain\\SensorNodeMainStandalone//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "../buffer.c"







# 1 "../buffer.h" 1
# 11 "../buffer.h"
typedef struct
{
    unsigned char* data;
    int head;
    int tail;
    int ptr_mask;
} ByteBuffer;


int bufPut(unsigned char b, ByteBuffer* buff);
int bufGet(unsigned char* b, ByteBuffer* buff);

void bufClear(ByteBuffer* buff);
int bufIsFull(ByteBuffer* buff);
int bufIsEmpty(ByteBuffer* buff);
int bufAvailable(ByteBuffer* buff);
# 9 "../buffer.c" 2
# 18 "../buffer.c"
int bufPut(unsigned char b, ByteBuffer* buff)
{
    if ( bufIsFull(buff) )
    {
        return 0;
    }
    else
    {
        buff->data[buff->head] = b;
        buff->head = (buff->head + 1) & buff->ptr_mask;
        return 1;
    }
}

int bufGet(unsigned char* b, ByteBuffer* buff)
{
    if ( bufIsEmpty(buff) )
    {
        *b = 0;
        return 0;
    }
    else
    {
        *b = buff->data[buff->tail];
        buff->tail = (buff->tail + 1) & buff->ptr_mask;
        return 1;
    }
}

void bufClear(ByteBuffer* buff)
{
    buff->tail = 0;
    buff->head = 0;
}

int bufIsFull(ByteBuffer* buff)
{
    if ( ((buff->head + 1) & buff->ptr_mask) == buff->tail )
        return 1;
    else
        return 0;
}

int bufIsEmpty(ByteBuffer* buff)
{
    if (buff->tail == buff->head)
        return 1;
    else
        return 0;
}

int bufAvailable(ByteBuffer* buff)
{
    return (buff->head - buff->tail) & buff->ptr_mask;
}
