
#ifndef __SX1276_API_H__
#define __SX1276_API_H__

#include <stdint.h>
#include <stdbool.h>

#include "queue.h"




#define SX1276_API_DEBUG_EN 1

#ifdef SX1276_API_DEBUG_EN
#include <stdio.h> 
#define SX1276_API_DEBUG(fmt, x...) \
do \
{ \
    printf(fmt,##x); \
}while(0)

#define SX1276_API_DEBUG_H(fmt, x...) \
do \
{ \
    USART_printfHex(fmt,##x); \
}while(0)

#define SX1276_API_DEBUG_F(fmt, x...) \
do \
{ \
    printf("%s %s(Line %d): "fmt,__FILE__,__FUNCTION__,__LINE__, ##x); \
}while(0)

#else
#define SX1276_API_DEBUG(fmt, x...)
#define SX1276_API_DEBUG1(fmt, x...)
#define SX1276_API_DEBUG_F(fmt, x...)
#endif


#define LoRa_SendTimeOut 60*1000
extern uint32_t LoRa_SendTimeCouter;


uint8_t SX1276_Send_Data(uint8_t * buffer,uint16_t bufferLen );
int16_t SX1276_Read_Data( void *Buffer ,uint32_t Timeout, int8_t *snr,double *rssi );
uint8_t SX1276_Send_Data_Listen_Ch(uint8_t * buffer,uint16_t bufferLen,uint32_t ldelay_ms,uint8_t num);
bool SX1276IsLoraChannelFree( int16_t rssiThresh );

double SX1276_Ambience_Rssi(void);
void SX1276_Sleep(void);
uint8_t SX1276_Cad_Listen(void);

uint16_t  SX1276_CAD_Task( void *Buffer ,uint32_t Timeout,int8_t *snr,int16_t *rssi );
void SX1276_Read_Data_Sp(uint32_t Timeout );
void SX1276_CAD_Start( void );
void SX1276_Send_Data_Sp(uint8_t * buffer,uint16_t bufferLen );



extern sequeue_t				 *lora_tx_sq;
extern sequeue_t				 *lora_rx_sq;

#endif // __RADIO_H__
