#include "omw_cmd.h"
#include "t1001_vtimer.h"
#include "omw_svc.h"
//#include "data_xfer.h"

uint16_t  omw_cmd_uart_fifo_sz;
uint16_t  omw_cmd_uart_fifo_rd;
uint8_t * omw_cmd_uart_fifo_buf;

char  ALL_RCV_DATA[256] = "\0";			//zhq  note:
extern char at_command_buffer[64] ;
extern uint8_t g_uart_ir ;			//zhq  note:

static const omw_svc_info_t * hc_p_dx_svc;
extern uint32_t deft_conn ;



//#define CMD_UART_FIFO_BUF_SIZE  128   //need power of 2

uint8_t  cmd_uart_buf[CMD_UART_FIFO_BUF_SIZE];



    uint8_t cur_rd = 0;
	
void rcv_uart_data(void)						//zhq  note: 接收BUFF数据
{
	if (g_uart_ir) 
	{	
		memset(at_command_buffer, 0,sizeof(at_command_buffer)) ;
		delay_us(6000); // delay 6000us to wait clk stable	
		uint8_t wt = omw_cmd_uart_get_rx_fifo_wt();


		if (cur_rd <= wt)
		{
			for (uint8_t i=0; i<wt-cur_rd; i++) 
			{
				at_command_buffer[i] = omw_cmd_uart_fifo_buf[cur_rd+i];
			}
			cur_rd = wt;
			omw_cmd_uart_fifo_rd = cur_rd;
			omw_cmd_uart_set_rx_fifo_rd(cur_rd);
		}
		else 
		{
			//char  ALL_RCV_DATA[256] = "\0";
			strncat(ALL_RCV_DATA , omw_cmd_uart_fifo_buf,128 );
			strncat(ALL_RCV_DATA , omw_cmd_uart_fifo_buf ,128);
			
			for (uint8_t i=0; i<128+wt-cur_rd; i++) 
			{
				at_command_buffer[i] = ALL_RCV_DATA[cur_rd+i];
			}
			cur_rd = wt;
		}
		data_xfer_notify_send(deft_conn, at_command_buffer, strlen(at_command_buffer));			//zhq  note:串口接收到数据，蓝牙数据包发出		
		g_uart_ir = 0;
	}	
	
}

