diff --git a/utils/UpgradeBase/README.md b/utils/UpgradeBase/README.md index 1fb17149..ed1806fc 100644 --- a/utils/UpgradeBase/README.md +++ b/utils/UpgradeBase/README.md @@ -8,9 +8,9 @@ **32字节头定义** -| 打包时间(6) | 版本号(4) | 型号代码(2) | 项目代码(2) | 升级类型(1) | 预留(17) | -|----|----|----|----|----|----| -|----|----|----|----|----|----| +| 打包时间(6) | 版本号(4) | 型号代码(2) | 项目代码(2) | 升级类型(1) | 预留(15) | 校验码(尾2) | +|----|----|----|----|----|----|----| +|----|----|----|----|----|----|----| **升级类型说明** diff --git a/utils/UpgradeBase/include/UpgradeBase.h b/utils/UpgradeBase/include/UpgradeBase.h index a16408b6..dab0699a 100644 --- a/utils/UpgradeBase/include/UpgradeBase.h +++ b/utils/UpgradeBase/include/UpgradeBase.h @@ -22,7 +22,8 @@ typedef struct __attribute__((packed)) upgrade_file_header unsigned char product[2]; unsigned char project[2]; unsigned char upgradeType[1]; - unsigned char reserved[17]; + unsigned char reserved[15]; + unsigned char checkCode[2]; } UpgradeFileHeader; enum class UpgradeType { @@ -45,5 +46,6 @@ public: StatusCode MoveUpgradeFile(const char *sourceFile, const char *targetFile); private: + void PrintfHeader(const UpgradeFileHeader &header); }; #endif \ No newline at end of file diff --git a/utils/UpgradeBase/src/UpgradeBase.cpp b/utils/UpgradeBase/src/UpgradeBase.cpp index 288249c0..7f350ee4 100644 --- a/utils/UpgradeBase/src/UpgradeBase.cpp +++ b/utils/UpgradeBase/src/UpgradeBase.cpp @@ -34,6 +34,7 @@ StatusCode UpgradeBase::CheckUpgradeFile(const char *fileName, UpgradeFileHeader fclose(file); return CreateStatusCode(STATUS_CODE_NOT_OK); } + PrintfHeader(header); return CheckFileHeader(header); } StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targetFile) @@ -83,4 +84,29 @@ StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targ LogInfo("File processed successfully.\n"); return CreateStatusCode(STATUS_CODE_OK); +} +void UpgradeBase::PrintfHeader(const UpgradeFileHeader &header) +{ + printf("=====================================\n"); + printf("packTime:"); + for (long unsigned int i = 0; i < sizeof(header.packTime); ++i) { + printf("0x%02x ", header.packTime[i]); + } + printf("\n"); + printf("version:"); + for (long unsigned int i = 0; i < sizeof(header.version); ++i) { + printf("0x%02x ", header.version[i]); + } + printf("\n"); + printf("product:"); + for (long unsigned int i = 0; i < sizeof(header.product); ++i) { + printf("0x%02x ", header.product[i]); + } + printf("\n"); + printf("upgradeType:"); + for (long unsigned int i = 0; i < sizeof(header.upgradeType); ++i) { + printf("0x%02x ", header.upgradeType[i]); + } + printf("\n"); + printf("=====================================\n"); } \ No newline at end of file diff --git a/utils/UpgradeTool/include/UpgradeTool.h b/utils/UpgradeTool/include/UpgradeTool.h index c0ee3a95..5f827dd2 100644 --- a/utils/UpgradeTool/include/UpgradeTool.h +++ b/utils/UpgradeTool/include/UpgradeTool.h @@ -13,9 +13,9 @@ * limitations under the License. */ #ifndef UPGRADE_TOOL_H - #define UPGRADE_TOOL_H - #include "StatusCode.h" - #include +#define UPGRADE_TOOL_H +#include "StatusCode.h" +#include class UpgradeTool { public: @@ -24,12 +24,9 @@ public: static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); void PackFile(const std::string &fileName, const std::string &outputFile, const std::string &version, const std::string &product, const std::string &project, const std::string &upgradeType); -}; -#endif -// unsigned char packTime[6]; -// unsigned char version[4]; -// unsigned char product[2]; -// unsigned char project[2]; -// unsigned char upgradeType[1]; -// unsigned char reserved[17]; \ No newline at end of file +private: + void FillInTime(unsigned char packTime[6]); + bool StringToVersionBytes(const std::string &versionString, unsigned char result[4]); +}; +#endif \ No newline at end of file diff --git a/utils/UpgradeTool/src/UpgradeTool.cpp b/utils/UpgradeTool/src/UpgradeTool.cpp index d4814571..dcb5545d 100644 --- a/utils/UpgradeTool/src/UpgradeTool.cpp +++ b/utils/UpgradeTool/src/UpgradeTool.cpp @@ -14,15 +14,17 @@ */ #include "UpgradeTool.h" #include "ILog.h" -#include "UpgradeBase.h" #include "LinuxApi.h" +#include "UpgradeBase.h" #include #include #include +#include #include #include #include #include +#include #include std::shared_ptr &UpgradeTool::GetInstance(std::shared_ptr *impl) { @@ -38,7 +40,7 @@ std::shared_ptr &UpgradeTool::GetInstance(std::shared_ptrtm_year; + packTime[1] = timeinfo->tm_mon + 1; // 月份(1-12) + packTime[2] = timeinfo->tm_mday; // 日期(1-31) + packTime[3] = timeinfo->tm_hour; // 小时(0-23) + packTime[4] = timeinfo->tm_min; // 分钟(0-59) + packTime[5] = timeinfo->tm_sec; // 秒(0-59) +} void UpgradeTool::PackFile(const std::string &fileName, const std::string &outputFile, const std::string &version, const std::string &product, const std::string &project, const std::string &upgradeType) { UpgradeFileHeader header; memset(&header, 0, sizeof(UpgradeFileHeader)); - stringToVersionBytes(version, header.version); + StringToVersionBytes(version, header.version); + FillInTime(header.packTime); FILE *input_file = fopen(fileName.c_str(), "rb"); if (!input_file) { perror("Error opening input file");