Backup:Upgrade.
This commit is contained in:
parent
bc5290047b
commit
275c1aa59d
|
@ -13,10 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "UpgradeState.h"
|
||||
#include "IHuntingUpgrade.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include "IHuntingUpgrade.h"
|
||||
UpgradeState::UpgradeState() : State("UpgradeState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&UpgradeState::CheckUpgradeFileHandle, this, _1);
|
||||
|
|
|
@ -81,6 +81,7 @@ set(SD_CARD_MOUNT_PATH "./sdcard")
|
|||
|
||||
# ------------ build upgrade ------------ #
|
||||
set(APPLICATION_CHECK_PATH "/application.bin")
|
||||
set(APPLICATION_UPGRADE_PATH "./fastboot_server")
|
||||
set(APPLICATION_VERSION_1 1)
|
||||
set(APPLICATION_VERSION_2 0)
|
||||
set(APPLICATION_VERSION_3 0)
|
||||
|
|
|
@ -16,6 +16,7 @@ include_directories(
|
|||
#)
|
||||
|
||||
add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_PATH}\")
|
||||
add_definitions(-DAPPLICATION_UPGRADE_PATH=\"${APPLICATION_UPGRADE_PATH}\")
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ StatusCode HuntingUpgradeImpl::CheckUpgradeFile(void)
|
|||
UpgradeFileHeader header;
|
||||
StatusCode code = UpgradeBase::CheckUpgradeFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH, header);
|
||||
if (!IsCodeOK(code)) {
|
||||
LogInfo("Check upgrade file:not found.\n");
|
||||
LogWarning("Check upgrade file:not found.\n");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
UpgradeBase::MoveUpgradeFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH, APPLICATION_UPGRADE_PATH);
|
||||
return code;
|
||||
}
|
|
@ -34,9 +34,10 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 6);
|
||||
TestManager::ResetTimeOut(1000 * 4);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// MockAppPlayback();
|
||||
MainThread::GetInstance()->Runing();
|
||||
RemoveUpgradeFile();
|
||||
}
|
||||
} // namespace MediaManager_Mock_Test
|
|
@ -18,6 +18,7 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/LinuxApi/include
|
||||
${UTILS_SOURCE_PATH}/UpgradeTool/include
|
||||
${TEST_SOURCE_PATH}
|
||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/include
|
||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/src
|
||||
|
@ -31,11 +32,12 @@ include_directories(
|
|||
# )
|
||||
|
||||
add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_PATH}\")
|
||||
add_definitions(-DAPPLICATION_UPGRADE_PATH=\"${APPLICATION_UPGRADE_PATH}\")
|
||||
|
||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||
set(TEST_TOOL_TARGET MissionManagerTestTool)
|
||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||
target_link_libraries(${TEST_TOOL_TARGET} MissionManager AppManagerTestTool MediaManagerTestTool Log)
|
||||
target_link_libraries(${TEST_TOOL_TARGET} MissionManager AppManagerTestTool MediaManagerTestTool UpgradeTool StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
|
||||
protected:
|
||||
void CreateUpgradeFile(void);
|
||||
void RemoveUpgradeFile(void);
|
||||
|
||||
private:
|
||||
std::shared_ptr<IMissionManager> mMissionManagerMock;
|
||||
|
|
|
@ -13,9 +13,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "MissionManagerTestTool.h"
|
||||
#include "ILog.h"
|
||||
#include "LinuxApi.h"
|
||||
#include "MissionManagerMakePtrTest.h"
|
||||
#include "MissionManagerMock.h"
|
||||
#include "UpgradeTool.h"
|
||||
void MissionManagerTestTool::Init(void)
|
||||
{
|
||||
mMissionManagerMock = std::make_shared<MissionManagerMock>();
|
||||
|
@ -29,5 +31,15 @@ void MissionManagerTestTool::UnInit(void)
|
|||
}
|
||||
void MissionManagerTestTool::CreateUpgradeFile(void)
|
||||
{
|
||||
fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH);
|
||||
fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test");
|
||||
UpgradeTool::GetInstance()->PackFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test",
|
||||
SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH,
|
||||
"1.0.0.0",
|
||||
"hunting",
|
||||
"dgiot",
|
||||
"app");
|
||||
}
|
||||
void MissionManagerTestTool::RemoveUpgradeFile(void)
|
||||
{
|
||||
fx_system("rm " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH);
|
||||
}
|
|
@ -17,3 +17,4 @@ add_subdirectory(FxHttpServer)
|
|||
add_subdirectory(Servers)
|
||||
add_subdirectory(TcpModule)
|
||||
add_subdirectory(UpgradeBase)
|
||||
add_subdirectory(UpgradeTool)
|
55
utils/UpgradeTool/CMakeLists.txt
Normal file
55
utils/UpgradeTool/CMakeLists.txt
Normal file
|
@ -0,0 +1,55 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/UpgradeBase/include
|
||||
${UTILS_SOURCE_PATH}/LinuxApi/include
|
||||
)
|
||||
# link_directories(
|
||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME UpgradeTool)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} LinuxApi StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
UpgradeTool_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/UpgradeTool
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
UpgradeTool_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/UpgradeTool
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make UpgradeTool_code_check
|
||||
COMMAND make UpgradeTool_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
5
utils/UpgradeTool/README.md
Normal file
5
utils/UpgradeTool/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# 升级打包工具库
|
||||
|
||||
## 概述
|
||||
|
||||
  升级打包工具库,用于把升级文件添加校验字节头进行打包。
|
35
utils/UpgradeTool/include/UpgradeTool.h
Normal file
35
utils/UpgradeTool/include/UpgradeTool.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef UPGRADE_TOOL_H
|
||||
#define UPGRADE_TOOL_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class UpgradeTool
|
||||
{
|
||||
public:
|
||||
UpgradeTool() = default;
|
||||
virtual ~UpgradeTool() = default;
|
||||
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];
|
93
utils/UpgradeTool/src/UpgradeTool.cpp
Normal file
93
utils/UpgradeTool/src/UpgradeTool.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "UpgradeTool.h"
|
||||
#include "ILog.h"
|
||||
#include "UpgradeBase.h"
|
||||
#include "LinuxApi.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
std::shared_ptr<UpgradeTool> &UpgradeTool::GetInstance(std::shared_ptr<UpgradeTool> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<UpgradeTool>();
|
||||
if (impl) {
|
||||
if (instance.use_count() == 1) {
|
||||
LogInfo("Instance changed succeed.\n");
|
||||
instance = *impl;
|
||||
}
|
||||
else {
|
||||
LogError("Can't changing the instance becase of using by some one.\n");
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
bool stringToVersionBytes(const std::string &versionString, unsigned char result[4])
|
||||
{
|
||||
std::stringstream ss(versionString);
|
||||
std::string segment;
|
||||
int index = 0;
|
||||
|
||||
while (std::getline(ss, segment, '.') && index < 4) {
|
||||
unsigned int value = 0;
|
||||
std::stringstream segmentStream(segment);
|
||||
segmentStream >> std::dec >> value;
|
||||
|
||||
if (value > 255) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result[index++] = static_cast<unsigned char>(value);
|
||||
printf("================ version[%d]: %02x\n", index, result[index - 1]);
|
||||
}
|
||||
|
||||
if (index != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
FILE *input_file = fopen(fileName.c_str(), "rb");
|
||||
if (!input_file) {
|
||||
perror("Error opening input file");
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *output_file = fopen(outputFile.c_str(), "wb");
|
||||
if (!output_file) {
|
||||
perror("Error opening output file");
|
||||
fclose(input_file);
|
||||
return;
|
||||
}
|
||||
fwrite(&header, sizeof(header), 1, output_file);
|
||||
char buffer[1024];
|
||||
size_t bytes_read;
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
|
||||
fwrite(buffer, 1, bytes_read, output_file);
|
||||
}
|
||||
fclose(input_file);
|
||||
fclose(output_file);
|
||||
fx_system("sync");
|
||||
}
|
Loading…
Reference in New Issue
Block a user