#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "string.h"
#include "Helper.h"
#include "iap.h"
/* 获取当前程序是App还是Boot  */
/*
请求格式 包起始标识+CMD0x01_Request_RunningAtWhere+[0x00+0x00]+包尾标识
返回格式 包起始标识+CMD0x01_Request_RunningAtWhere+[0x00+0x01]+1Byte的RunningAtWhere+包尾标识.  RunningAtWhere 约定：RUNNING_AT_APP 0x77，RUNNING_AT_BOOT 0x11
*/
void CMD0x15_Request_WriteUpdateTimeStamp_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
{
	u8 bDataOK=1;
	u8 validDataLength=dataLen;
	if (bIsContentBitInverted_Recv)
	{
		validDataLength=dataLen/2;
		if (!Helper_CheckInvertBytesIsRegist(pData,dataLen))
			bDataOK=0;
	}
	if (validDataLength<Version_DateLength)
		bDataOK=0;
	if (bDataOK)
	{
		struct BootWriteFlashInfoStruct bootWriteFlashInfo;
		iap_ReadBootWriteInfo(&bootWriteFlashInfo);
		memcpy(bootWriteFlashInfo.UpdateTimeStamp,pData,Version_DateLength);
		iap_UpdateBootWriteInfo(&bootWriteFlashInfo);
	}
	else
		Command_SendbackErrorMessage(Error0x02_CannotRunAtBoot,1);		
}
