#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "Probe_MSO7000X_2d5g.h"
#include "AnalogChannelCtrl_2d5g_base.h"
#include "ProbeEEPROM.h"
#include "Helper.h"
#include "string.h"
//////////////////////////////////////////////////////////////////////////////
// 			2203/5/X GHz_ljw 合并版 厂家专用烧写EEPROM
//////////////////////////////////////////////////////////////////////////////

void CMD0x50_Request_WriteProbeFactoryInfo_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
{
#ifdef RUNNING_WHERE_AT_BOOT	
	Command_SendbackErrorMessage(Error0x02_CannotRunAtBoot);
#else
	u8 bDataOK=1;
	u8 validDataLength=dataLen;
	if (bIsContentBitInverted_Recv)
	{
		validDataLength=dataLen/2;
		bDataOK=Helper_CheckInvertBytesIsRegist(pData,dataLen);
	}
	if (validDataLength<7)
		bDataOK=0;
	
	if(!bDataOK)	
	{
			Command_SendbackErrorMessage(Error0x05_CMD_ParaLentghError,1);
			return;
	}
	if(IsChannelSetting!=0)
	{
		return;
	}
	IsChannelSetting = 1;
	u8 writeData[EEPROM_DATA_LEN+1];//careful!!!,EEPROM_DATA_LEN can't too big,check leap/stack size
	if(dataLen < EEPROM_DATA_LEN+1)	
	{
		for(int i = 0;i<EEPROM_DATA_LEN-dataLen+1;i++)
		{
			writeData[dataLen+i] = 0xFF;
		}
	}
	memcpy(writeData,pData,dataLen);

	u8 result = ProbeEEPROM_Write(writeData,writeData+1);
	if(result==1)
	{
		Command_SendbackOKMessage();
	}
	else
		{
		Command_SendbackErrorMessage(Error0xFF_General,1);
	}
	IsChannelSetting = 0;	
#endif		
}
