#ifndef __ATAIR720__
#define __ATAIR720__

#include <stdint.h>
#include "type-spec.h"
#include "queue.h"

#define AT_AIR720_DEBUG_EN 1

#ifdef AT_AIR720_DEBUG_EN


#define AT_AIR720_DEBUG(fmt, x...) \
do \
{ \
    printf(fmt,##x); \
}while(0)

#define AT_AIR720_DEBUG_NB(fmt, x...) \
do \
{ \
    UART4_SendNByte(fmt,##x); \
}while(0)

#define AT_AIR720_DEBUG_String(fmt, x...) \
do \
{ \
    UART4_SendString(fmt,##x); \
}while(0)

#define AT_AIR720_DEBUG_1B(fmt, x...) \
do \
{ \
    UART4_SendByte(fmt,##x); \
}while(0)


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

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

#else
#define AT_AIR720_DEBUG(fmt, x...)
#define AT_AIR720_DEBUG_1B(fmt, x...)
#define AT_AIR720_DEBUG_NB(fmt, x...)
#define AT_AIR720_DEBUG_String(fmt, x...)
#define AT_AIR720_DEBUG_H(fmt, x...)
#define AT_AIR720_DEBUG_F(fmt, x...)
#endif

void	thread_atair720(void* parameter);
void Air720_Init(void);

#define buflen  256
#define loraidbuflen  20

typedef struct USART_BUF{
	
	unsigned char rxbufindex;
	
	//unsigned char txbufindex;
	
  unsigned char rxbuf[buflen];
	
	//unsigned char txbuf[buflen];
	
} USART_BUF_t;


uint16_t UDP_0D_frame_l(uint8_t td);

uint16_t UDP_0D_frame_N(uint8_t td);

uint16_t UDP_0D_frame_NT(uint8_t td);

void AT_aire720_process(DEV_WORK_MODE_T *pmode);



typedef enum
{
    AT_AIRE720_STATE_IDLE=0,
    AT_AIRE720_STATE_INIT,
    AT_AIRE720_STATE_CONNECTING,
		AT_AIRE720_STATE_CONNECT_OK,
		AT_AIRE720_STATE_RE_CONNECT,



} tAT_AIRE720_StateCodes;//AT_aire720_State
typedef struct{
	uint8_t rsv; 
	uint8_t firmWareType;                 //固件，类型，0:APP，1:BootLoader,2:SET配置区
	uint8_t desDeviceType;   							//被升级设备类型(1Byte)
	uint8_t desDeviceID[4];        					  //被升级设备ID(4Byte)
	uint8_t  desDeviceChannel;        			//被升级设备通道号(1Byte)
	uint8_t softWareOldVer[4];        				//前版本(4Byte)
	uint8_t softWareNewVer[4];        				//后版本(4Byte)
	uint8_t  srcUrlLen;        			//固件路径URL的长度(1B)
	uint8_t  ppath[80];										//固件路径URL
}tUpdare_Paras;

int8_t Air720_Update_Down(void);
uint8_t  air_send_IMEI_Cmd(uint16_t waittime);
uint8_t  air_send_ICCID_Cmd(uint16_t waittime);

extern sequeue_t * Air720_Send_Sq;

extern tCounterTimeOut_t time_gw_force_rst;
void set_at_aire720_workState(tAT_AIRE720_StateCodes  mode);

#endif


