#include "string.h"
#include "CommandsDefine.h"
#include "stmflash.h"
#include "usart.h"
#include "iap.h"
#include "ProjectConfig.h"
/* 获取当前程序是的版本等信息*/
/*
请求格式 包起始标识+CMD0x02_Request_ReadMcuVersion+[0x00+0x00]+包尾标识
返回格式:
  包起始标识
	+CMD0x03_Request_ReadMcuBootVersion
	+[2字节的数据长度，=129]
	+1字节的主版本号+1字节的次版本号+1字节的修订版本
	+Version_DateLength=14字节的日期时间标识，是YYYYMMDDHHMMSS格式的ascii码
	+Version_ModifierNameMaxLength=16字节的最后修改人姓名。其余的填0
	+Version_ModelNameMaxLength=32字节的型号标识
	+Version_Comment_MaxLength=64字节的备注信息
	+包尾标识
*/
void CMD0x03_Request_ReadMcuBootVersion_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
{
	u8 backdataLength=3
			+Version_DateLength
			+Version_ModifierNameMaxLength
			+Version_ModelNameMaxLength
			+Version_Comment_MaxLength;
	
	memset(USART_WR_BUF,0,backdataLength);
	int len;
#ifdef RUNNING_WHERE_AT_BOOT	
	VersionInfo* versionInfo=GetVersion();	
#else
	struct BootWriteFlashInfoStruct bootWriteFlashInfo;
	iap_ReadBootWriteInfo(&bootWriteFlashInfo);	
	VersionInfo* versionInfo=(VersionInfo*)&bootWriteFlashInfo;
#endif

	USART_WR_BUF[0]=versionInfo->Version_MainNo;
	USART_WR_BUF[1]=versionInfo->Version_SubNo;
	USART_WR_BUF[2]=versionInfo->Version_ModifyNo;
	
	
	for(int i=0;i<Version_DateLength;i++)
		USART_WR_BUF[3+i]=versionInfo->Version_Date[i];
	len=strlen(versionInfo->Version_ModifierName);
	len=len>Version_ModifierNameMaxLength ? Version_ModifierNameMaxLength:len;
	for(int i=0;i<len;i++)
		USART_WR_BUF[3+Version_DateLength+i]=versionInfo->Version_ModifierName[i];

	len=strlen(versionInfo->Version_ModelName);
	len=len>Version_ModelNameMaxLength ? Version_ModelNameMaxLength:len;
	for(int i=0;i<len;i++)
		USART_WR_BUF[3+Version_DateLength+Version_ModifierNameMaxLength+i]=versionInfo->Version_ModelName[i];
	len=strlen(versionInfo->Version_Comment);
	len=len>Version_Comment_MaxLength ? Version_Comment_MaxLength:len;
	for(int i=0;i<len;i++)
		USART_WR_BUF[3+Version_DateLength+Version_ModifierNameMaxLength+Version_ModelNameMaxLength+i]=versionInfo->Version_Comment[i];
	
	int sendSize=Command_FormatCmdBuffer(CMD0x03_Request_ReadMcuBootVersion,USART_WR_BUF,backdataLength,USART_WR_BUF_LAST);
	USART6_Send(CMD0x03_Request_ReadMcuBootVersion,backdataLength,bIsContentBitInverted_SendBack);
}

