/****************************************************************************************************
* created by sunpeng 2017 all rights reserved!
****************************************************************************************************/

#if ARCH_MODE == CC254X_Peripheral_Mode
#include "stdio.h"
#include "include.h"
#include "apptocube.h"
#include "uart_api.h"

#else

#ifdef STM32F10X_HD
#include "stdio.h"
#include "include.h"
#include "apptocube.h"
#include "uart_api.h"

#elif STM32F10X_MD
#include "stdio.h"
#include "include.h"
#include "apptocube.h"
#include "uart_api.h"

#elif NRF52
#include "stdio.h"
#include "include.h"
#include "apptocube.h"
#include "uart_api.h"

#elif NRF51
#include "stdio.h"
#include "include.h"
#include "apptocube.h"
#include "uart_api.h"

#else
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "apptocube.h"
#endif

#endif

typedef enum
{
	STATUS_MIN = 0,
	STATUS_HEAD,
	STATUS_CMDLEN,
	STATUS_CONTENT,
	STATUS_TAIL,
	STATUS_CMDOK,
	STATUS_MAX
}STATUS_ENUM;


STATUS_ENUM sta = STATUS_HEAD;  //协议解析阶段

#define iHeadLenMax (6)  	//指令头byte数
#define iHeadTableMax  5    //head数组成员个数
u8 *sHead[iHeadTableMax];  		//指令头
u16 iHeadCnt = 0;

#define iCmdAndLenMax (3-1) //指令码+长度和 byte数
u8 sCmdLen[3]={0x0};     	//存储指令码+长度和
u8 sCmdLenCnt = 0;       	//存储计数

u16 iDataLenCnt = 0;     	//内容长度和计数


#define iTailLenMax (2)  	//指令头byte数
u8 sTail[]="\r\n";  		//指令头
u16 iTailCnt = 0;


int set_all_com_recv_heads(void)
{
	u16 i=0;
	for(i=0;i<iHeadTableMax;i++)
	{
		sHead[i]=(u8 *)RECV_HEAD[i];
	}
	return true;
}

void parse_head(void)
{
	iHeadCnt++;
	if(iHeadCnt >= iHeadLenMax)
	{
		sta = STATUS_CMDLEN;  //ch status
		//printf("STATUS_HEAD OK\n");
		//printf("last chr = %c\n",*chr);
	}

}

int parsebyte(u8 *chr)
{
	u16 i = 0;

	return 0;
}

int parse_while(u8 *str)
{
	
	while(1)
	{
		if('\0' == *str)
		{
			str++;
			if('\0' != *str)
			{
				str--;
				parsebyte(str);
				str++;
				parsebyte(str);
			}
			else
			{
				break;
			}
		}
		else
		{
			parsebyte(str);
			str++;
		}
	}
	return true;
}


int test_parse(void)
{
	char str[30];
	parse_while((u8 *)str);
	//while(1);
	return 0;
}

/*********************************************end of file*********************************************/
