Backup.
This commit is contained in:
parent
275c1aa59d
commit
e82f4f43f8
|
@ -8,9 +8,9 @@
|
|||
|
||||
**32字节头定义**
|
||||
|
||||
| 打包时间(6) | 版本号(4) | 型号代码(2) | 项目代码(2) | 升级类型(1) | 预留(17) |
|
||||
|----|----|----|----|----|----|
|
||||
|----|----|----|----|----|----|
|
||||
| 打包时间(6) | 版本号(4) | 型号代码(2) | 项目代码(2) | 升级类型(1) | 预留(15) | 校验码(尾2) |
|
||||
|----|----|----|----|----|----|----|
|
||||
|----|----|----|----|----|----|----|
|
||||
|
||||
**升级类型说明**
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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");
|
||||
}
|
|
@ -13,9 +13,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#ifndef UPGRADE_TOOL_H
|
||||
#define UPGRADE_TOOL_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
#define UPGRADE_TOOL_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class UpgradeTool
|
||||
{
|
||||
public:
|
||||
|
@ -24,12 +24,9 @@ public:
|
|||
static std::shared_ptr<UpgradeTool> &GetInstance(std::shared_ptr<UpgradeTool> *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];
|
||||
private:
|
||||
void FillInTime(unsigned char packTime[6]);
|
||||
bool StringToVersionBytes(const std::string &versionString, unsigned char result[4]);
|
||||
};
|
||||
#endif
|
|
@ -14,15 +14,17 @@
|
|||
*/
|
||||
#include "UpgradeTool.h"
|
||||
#include "ILog.h"
|
||||
#include "UpgradeBase.h"
|
||||
#include "LinuxApi.h"
|
||||
#include "UpgradeBase.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
std::shared_ptr<UpgradeTool> &UpgradeTool::GetInstance(std::shared_ptr<UpgradeTool> *impl)
|
||||
{
|
||||
|
@ -38,7 +40,7 @@ std::shared_ptr<UpgradeTool> &UpgradeTool::GetInstance(std::shared_ptr<UpgradeTo
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
bool stringToVersionBytes(const std::string &versionString, unsigned char result[4])
|
||||
bool UpgradeTool::StringToVersionBytes(const std::string &versionString, unsigned char result[4])
|
||||
{
|
||||
std::stringstream ss(versionString);
|
||||
std::string segment;
|
||||
|
@ -63,12 +65,27 @@ bool stringToVersionBytes(const std::string &versionString, unsigned char result
|
|||
|
||||
return true;
|
||||
}
|
||||
void UpgradeTool::FillInTime(unsigned char packTime[6])
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
packTime[0] = timeinfo->tm_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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user