CMD0x03_Request_ReadMcuBootVersion.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "string.h"
  2. #include "CommandsDefine.h"
  3. #include "stmflash.h"
  4. #include "usart.h"
  5. #include "iap.h"
  6. #include "ProjectConfig.h"
  7. /* 获取当前程序是的版本等信息*/
  8. /*
  9. 请求格式 包起始标识+CMD0x02_Request_ReadMcuVersion+[0x00+0x00]+包尾标识
  10. 返回格式:
  11. 包起始标识
  12. +CMD0x03_Request_ReadMcuBootVersion
  13. +[2字节的数据长度,=129]
  14. +1字节的主版本号+1字节的次版本号+1字节的修订版本
  15. +Version_DateLength=14字节的日期时间标识,是YYYYMMDDHHMMSS格式的ascii码
  16. +Version_ModifierNameMaxLength=16字节的最后修改人姓名。其余的填0
  17. +Version_ModelNameMaxLength=32字节的型号标识
  18. +Version_Comment_MaxLength=64字节的备注信息
  19. +包尾标识
  20. */
  21. void CMD0x03_Request_ReadMcuBootVersion_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
  22. {
  23. u8 backdataLength=3
  24. +Version_DateLength
  25. +Version_ModifierNameMaxLength
  26. +Version_ModelNameMaxLength
  27. +Version_Comment_MaxLength;
  28. memset(USART_WR_BUF,0,backdataLength);
  29. int len;
  30. #ifdef RUNNING_WHERE_AT_BOOT
  31. VersionInfo* versionInfo=GetVersion();
  32. #else
  33. struct BootWriteFlashInfoStruct bootWriteFlashInfo;
  34. iap_ReadBootWriteInfo(&bootWriteFlashInfo);
  35. VersionInfo* versionInfo=(VersionInfo*)&bootWriteFlashInfo;
  36. #endif
  37. USART_WR_BUF[0]=versionInfo->Version_MainNo;
  38. USART_WR_BUF[1]=versionInfo->Version_SubNo;
  39. USART_WR_BUF[2]=versionInfo->Version_ModifyNo;
  40. for(int i=0;i<Version_DateLength;i++)
  41. USART_WR_BUF[3+i]=versionInfo->Version_Date[i];
  42. len=strlen(versionInfo->Version_ModifierName);
  43. len=len>Version_ModifierNameMaxLength ? Version_ModifierNameMaxLength:len;
  44. for(int i=0;i<len;i++)
  45. USART_WR_BUF[3+Version_DateLength+i]=versionInfo->Version_ModifierName[i];
  46. len=strlen(versionInfo->Version_ModelName);
  47. len=len>Version_ModelNameMaxLength ? Version_ModelNameMaxLength:len;
  48. for(int i=0;i<len;i++)
  49. USART_WR_BUF[3+Version_DateLength+Version_ModifierNameMaxLength+i]=versionInfo->Version_ModelName[i];
  50. len=strlen(versionInfo->Version_Comment);
  51. len=len>Version_Comment_MaxLength ? Version_Comment_MaxLength:len;
  52. for(int i=0;i<len;i++)
  53. USART_WR_BUF[3+Version_DateLength+Version_ModifierNameMaxLength+Version_ModelNameMaxLength+i]=versionInfo->Version_Comment[i];
  54. int sendSize=Command_FormatCmdBuffer(CMD0x03_Request_ReadMcuBootVersion,USART_WR_BUF,backdataLength,USART_WR_BUF_LAST);
  55. USART6_Send(CMD0x03_Request_ReadMcuBootVersion,backdataLength,bIsContentBitInverted_SendBack);
  56. }