#ifndef _LORA_H_
#define _LORA_H_


//CAD parameters
#define CAD_SYMBOL_NUM          LORA_CAD_02_SYMBOL
#define CAD_DET_PEAK            22
#define CAD_DET_MIN             10
#define CAD_TIMEOUT_MS          2000
#define NB_TRY                  10

extern timeout_t g_loraRcvTime;

typedef struct _lora_param_{
    uint32_t freq; //发射频率
    uint8_t power; // 发射功率
    uint8_t bandwidth; //带宽
    uint8_t spreadingFactor; //扩频因子
    uint8_t codingrate; // 纠错编码率
    uint16_t preambleLen; // 前导码长度
}loraParam;
extern loraParam g_loraPa[4];
typedef enum LORA_STATE_ENUM {
    lora_state_idle,
    lora_state_rcv,
    lora_state_send,
        lora_state_sendRept,
    lora_state_max
} LORA_STATE_ENUM;

typedef struct _system_lora {
  uint8_t memory[8][256];		//必须4字节对齐
    OS_Q  lora_q;
    OS_SEM sem;
    OS_MEM lora_m;
    OS_TMR lora_tmr;
} system_lora_t;

extern void * lora_queue_mem_calloc_must(void);
extern int lora_queue_mem_free(void * p_msg);
extern void lora_queue_insert(char *p_msg, uint32_t msg_len);

extern void lora_init(char *device_id);
extern void lora_task(void);

static void SX126xOnTxDone( void );
static void SX126xOnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
static void SX126xOnTxTimeout( void );
static void SX126xOnRxTimeout( void );
static void SX126xOnRxError( void );
extern void lora_queue_proc_testTx(void);

#endif
