#include <string.h>
#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "DebugDataDefine.h"
#include "AnalogChannelCtrl_2d5g_base.h"
#include "Helper.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////
// 			2203/4/X GHz_ljw 合并版
//////////////////////////////////////////////////////////////////////////////
void CMD0xE3_Request_GetDebugData_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
{
#ifdef RUNNING_WHERE_AT_BOOT	
	Command_SendbackErrorMessage(Error0x02_CannotRunAtBoot,1);
#else
	u8 bDataOK=1;
	u8 validDataLength=dataLen;
	if (bIsContentBitInverted_Recv)
	{
		validDataLength=dataLen/2;
		if (!Helper_CheckInvertBytesIsRegist(pData,dataLen))
			bDataOK=0;
	}
	if (validDataLength<2)
		bDataOK=0;
	if (!bDataOK)
	{
		Command_SendbackErrorMessage(Error0x05_CMD_ParaLentghError,1);			
		return;
	}
	u8 dataBytes=2;
	switch(pData[0])
	{
		case DebugDataType_AnalogChannelSetData:
			dataBytes=41;
			break;
		case DebugDataType_CommunicateTimesInfo:
			dataBytes=sizeof(u32)*2;
			break;
		case DebugDataType_Analog4094Word:
			dataBytes=sizeof(u32)*2;
			break;			
		default:
			break;
	}
	
	memset(USART_WR_BUF,0xff,PACKAGE_MIN_BYTES+dataBytes);
	switch(pData[0])
	{
		case DebugDataType_AnalogChannelSetData:
				memcpy(USART_WR_BUF,G_DebugData_AnalogChannel_LastRecvData,PACKAGE_CHANNELSET_MAX_BYTES);
				break;
		case DebugDataType_CommunicateTimesInfo:
			  memcpy(USART_WR_BUF,&RecvedPackageCount,sizeof(u32));
				memcpy(&USART_WR_BUF[sizeof(u32)],&SendBackPackageCount,sizeof(u32));
				break;
		case DebugDataType_Analog4094Word:
			  memcpy(USART_WR_BUF,&G_High8HC595,sizeof(u32));			
			  memcpy(&USART_WR_BUF[4],&G_Low32HC595,sizeof(u32));				
				break;
		default:
				break;
	}		

	USART6_Send(CMD0xE3_Request_GetDebugData,dataBytes,bIsContentBitInverted_SendBack);	 
#endif	
}
