diff --git a/doc/sdk_build_guide.md b/doc/sdk_build_guide.md new file mode 100644 index 0000000..9b1f4de --- /dev/null +++ b/doc/sdk_build_guide.md @@ -0,0 +1,5 @@ +# 1. SDK构建设计文档 + +## 1.1. 概述 + +  SDK使用cmake构建,把分层解耦合的独立模块编译成静态库,应用程序根据依赖关系进行自动关联链接。 \ No newline at end of file diff --git a/middleware/HuntingUpgrade/CMakeLists.txt b/middleware/HuntingUpgrade/CMakeLists.txt index f860217..c86ea27 100644 --- a/middleware/HuntingUpgrade/CMakeLists.txt +++ b/middleware/HuntingUpgrade/CMakeLists.txt @@ -16,9 +16,6 @@ include_directories( #link_directories( #) -add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_PATH}\") -add_definitions(-DAPPLICATION_UPGRADE_PATH=\"${APPLICATION_UPGRADE_PATH}\") - aux_source_directory(./src SRC_FILES) set(TARGET_NAME HuntingUpgrade) diff --git a/middleware/HuntingUpgrade/build/hunting_upgrade.cmake b/middleware/HuntingUpgrade/build/hunting_upgrade.cmake index 4be9712..10b4ef5 100644 --- a/middleware/HuntingUpgrade/build/hunting_upgrade.cmake +++ b/middleware/HuntingUpgrade/build/hunting_upgrade.cmake @@ -1,2 +1,4 @@ -add_definitions(-DHUNTING_CAMERA_VERSION="1.0.0.0") \ No newline at end of file +add_definitions(-DHUNTING_CAMERA_VERSION="1.0.0.0") +add_definitions(-DAPPLICATION_CHECK_PATH="${APPLICATION_CHECK_PATH}") +add_definitions(-DAPPLICATION_UPGRADE_PATH="${APPLICATION_UPGRADE_PATH}") \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp index 2ad2e0f..78a0e8b 100644 --- a/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp @@ -14,9 +14,26 @@ */ #include "HuntingUpgradeImpl.h" #include "ILog.h" +#include +#include +#include StatusCode HuntingUpgradeImpl::CheckFileHeader(const UpgradeFileHeader &head) { - const char *version = HUNTING_CAMERA_VERSION; + constexpr int VERSION_BUFF_LENGTH = 36; + char versionStr[VERSION_BUFF_LENGTH] = {0}; + memcpy(versionStr, HUNTING_CAMERA_VERSION, strlen(HUNTING_CAMERA_VERSION)); + unsigned char versionChar[VERSION_LENGTH] = {0}; + char *token; + int i = 0; + token = strtok(versionStr, "."); + while (token != NULL && i < VERSION_LENGTH) { + versionChar[i] = atoi(token); + token = strtok(NULL, "."); + i++; + } + // for (int j = 0; j < VERSION_LENGTH; j++) { + // printf("0x%X\n", versionChar[j]); + // } return CreateStatusCode(STATUS_CODE_OK); } StatusCode HuntingUpgradeImpl::CheckUpgradeFile(void) diff --git a/test/application/MissionManager/tool/CMakeLists.txt b/test/application/MissionManager/tool/CMakeLists.txt index 2cae5dc..c881325 100644 --- a/test/application/MissionManager/tool/CMakeLists.txt +++ b/test/application/MissionManager/tool/CMakeLists.txt @@ -1,4 +1,5 @@ include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/build/hunting_upgrade.cmake) include(${HAL_SOURCE_PATH}/build/hal.cmake) set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) @@ -31,9 +32,6 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) -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}) diff --git a/test/application/VersionReleaseTool/src/VersionBase.cpp b/test/application/VersionReleaseTool/src/VersionBase.cpp new file mode 100644 index 0000000..0f5cc58 --- /dev/null +++ b/test/application/VersionReleaseTool/src/VersionBase.cpp @@ -0,0 +1,51 @@ +/* + * 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 "VersionBase.h" +#include +#include +#include +#include +#include +void VersionBase::GetVersion(const std::string &fileName, const std::regex &pattern, std::string &version) +{ + std::ifstream file(fileName); + if (!file.is_open()) { + std::cerr << "无法打开文件: " << fileName << std::endl; + return; + } + + std::string line; + std::string versionGet; + // std::regex pattern(R"(add_definitions\(-DHUNTING_CAMERA_VERSION=\"([^"]+)\"\))"); + + while (std::getline(file, line)) { + std::smatch match; + if (std::regex_search(line, match, pattern)) { + // 如果找到匹配项,match[1]将包含捕获的版本号 + versionGet = match[1].str(); + break; // 找到后退出循环 + } + } + + file.close(); + + if (versionGet.empty()) { + std::cerr << "在文件中未找到指定的行或版本号!" << std::endl; + return; + } + + std::cout << "提取的版本号: " << versionGet << std::endl; + return; +} \ No newline at end of file diff --git a/test/application/VersionReleaseTool/src/VersionBase.h b/test/application/VersionReleaseTool/src/VersionBase.h new file mode 100644 index 0000000..e610013 --- /dev/null +++ b/test/application/VersionReleaseTool/src/VersionBase.h @@ -0,0 +1,26 @@ +/* + * 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 VERSION_BASE_H +#define VERSION_BASE_H +#include +#include +class VersionBase +{ +public: + VersionBase() = default; + virtual ~VersionBase() = default; + void GetVersion(const std::string &fileName, const std::regex &pattern, std::string &version); +}; +#endif \ No newline at end of file diff --git a/test/middleware/CMakeLists.txt b/test/middleware/CMakeLists.txt index e9ab9d4..5afda67 100644 --- a/test/middleware/CMakeLists.txt +++ b/test/middleware/CMakeLists.txt @@ -5,4 +5,5 @@ add_subdirectory(McuManager) add_subdirectory(McuAskBase) add_subdirectory(DeviceManager) add_subdirectory(AppManager) -add_subdirectory(MediaManager) \ No newline at end of file +add_subdirectory(MediaManager) +add_subdirectory(HuntingUpgrade) \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/CMakeLists.txt b/test/middleware/HuntingUpgrade/CMakeLists.txt new file mode 100644 index 0000000..bcdf839 --- /dev/null +++ b/test/middleware/HuntingUpgrade/CMakeLists.txt @@ -0,0 +1,82 @@ +# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/build/hunting_upgrade.cmake) +set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) + +include_directories( + ./src + ./include + ./tool/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/StatusCode/include + # ${UTILS_SOURCE_PATH}/LinuxApi/include + # ${HAL_SOURCE_PATH}/include + ${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include + ${TEST_SOURCE_PATH} + # ${TEST_SOURCE_PATH}/hal/tool/include + # ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include +) + +link_directories( + ${LIBS_OUTPUT_PATH} + ${EXTERNAL_LIBS_OUTPUT_PATH} +) + +aux_source_directory(. SRC_FILES_MAIN) +aux_source_directory(./src SRC_FILES) +if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) + aux_source_directory(./src_mock SRC_FILES) +endif() + +set(TARGET_NAME HuntingUpgradeTest) +add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} HuntingUpgradeTestTool gtest gmock pthread) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() + +if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + HuntingUpgradeTest_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + # --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]' + --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]' + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/HuntingUpgrade +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make HuntingUpgradeTest_code_check + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) + +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + HuntingUpgradeTest_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${SRC_FILES_MAIN} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/HuntingUpgrade +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make HuntingUpgradeTest_code_check + COMMAND make HuntingUpgradeTest_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) + +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tool/CMakeLists.txt") + add_subdirectory(tool) +endif() \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/mainTest.cpp b/test/middleware/HuntingUpgrade/mainTest.cpp new file mode 100644 index 0000000..475ceee --- /dev/null +++ b/test/middleware/HuntingUpgrade/mainTest.cpp @@ -0,0 +1,23 @@ +/* + * 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 +#include +#include +#include +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/src/HuntingUpgrade_Test.cpp b/test/middleware/HuntingUpgrade/src/HuntingUpgrade_Test.cpp new file mode 100644 index 0000000..92cbd45 --- /dev/null +++ b/test/middleware/HuntingUpgrade/src/HuntingUpgrade_Test.cpp @@ -0,0 +1,68 @@ +/* + * 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 "HuntingUpgradeTestTool.h" +#include "IHuntingUpgrade.h" +#include "ILog.h" +#include +#include +#include +namespace HuntingUpgradeTest +{ +class HuntingUpgradeTest : public testing::Test, public HuntingUpgradeTestTool +{ +public: + HuntingUpgradeTest() + { + } + virtual ~HuntingUpgradeTest() + { + } + static void SetUpTestCase() + { + CreateLogModule(); + ILogInit(LOG_INSTANCE_TYPE_END); + } + static void TearDownTestCase() + { + ILogUnInit(); + DestroyLogModule(); + } + virtual void SetUp() + { + // HalTestTool::Init(); + HuntingUpgradeTestTool::Init(); + // CreateHalCppModule(); + // CreateHuntingUpgradeModule(); + CreateHuntingUpgradeModule(); + } + virtual void TearDown() + { + HuntingUpgradeTestTool::UnInit(); + // HalTestTool::UnInit(); + // DestroyHuntingUpgradeModule(); + // DestroyHalCppModule(); + DestroyHuntingUpgradeModule(); + } +}; +/** + * @brief + * ../output_files/test/bin/HuntingUpgradeTest --gtest_filter=HuntingUpgradeTest.HS_RH_UNIT_HuntingUpgrade_EXAMPLE_Demo0 + */ +TEST_F(HuntingUpgradeTest, HS_RH_UNIT_HuntingUpgrade_EXAMPLE_Demo0) +{ + HuntingUpgradeTestTool::CreateUpgradeFile(); + IHuntingUpgrade::GetInstance()->CheckUpgradeFile(); +} +} // namespace HuntingUpgradeTest \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/tool/CMakeLists.txt b/test/middleware/HuntingUpgrade/tool/CMakeLists.txt new file mode 100644 index 0000000..cd7aafc --- /dev/null +++ b/test/middleware/HuntingUpgrade/tool/CMakeLists.txt @@ -0,0 +1,56 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +include(${HAL_SOURCE_PATH}/build/hal.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}/LinuxApi/include + ${UTILS_SOURCE_PATH}/UpgradeTool/include + ${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/src + ${TEST_SOURCE_PATH} + ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +aux_source_directory(./src TEST_TOOL_SRC_FILES) +set(TEST_TOOL_TARGET HuntingUpgradeTestTool) +add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) +target_link_libraries(${TEST_TOOL_TARGET} UpgradeTool LinuxApi HuntingUpgrade Log) + +if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + HuntingUpgradeTestTool_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${TEST_TOOL_SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/HuntingUpgrade/tool +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + HuntingUpgradeTestTool_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${TEST_TOOL_SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/HuntingUpgrade/tool +) +add_custom_command( + TARGET ${TEST_TOOL_TARGET} + PRE_BUILD + COMMAND make HuntingUpgradeTestTool_code_check + COMMAND make HuntingUpgradeTestTool_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TEST_TOOL_TARGET}) \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/tool/include/HuntingUpgradeTestTool.h b/test/middleware/HuntingUpgrade/tool/include/HuntingUpgradeTestTool.h new file mode 100644 index 0000000..141622e --- /dev/null +++ b/test/middleware/HuntingUpgrade/tool/include/HuntingUpgradeTestTool.h @@ -0,0 +1,32 @@ +/* + * 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 HUNTING_UPGRADE_TEST_TOOL_H +#define HUNTING_UPGRADE_TEST_TOOL_H +#include "GtestUsing.h" +class HuntingUpgradeTestTool +{ +public: + HuntingUpgradeTestTool() = default; + virtual ~HuntingUpgradeTestTool() = default; + +protected: + void Init(void); + void UnInit(void); + void CreateUpgradeFile(void); + +private: + bool CheckDirectory(const char *filepath); +}; +#endif \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp b/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp new file mode 100644 index 0000000..7af6822 --- /dev/null +++ b/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp @@ -0,0 +1,82 @@ +/* + * 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 "HuntingUpgradeTestTool.h" +#include "ILog.h" +#include "LinuxApi.h" +#include "UpgradeTool.h" +#include +#include +#include +#include +#include +void HuntingUpgradeTestTool::Init(void) +{ +} +void HuntingUpgradeTestTool::UnInit(void) +{ + if (access(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test", F_OK) == 0) { + fx_system("rm -rf " SD_CARD_MOUNT_PATH); + } +} +void HuntingUpgradeTestTool::CreateUpgradeFile(void) +{ + CheckDirectory(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); + 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"); +} +bool HuntingUpgradeTestTool::CheckDirectory(const char *filepath) +{ + LogInfo("CheckDirectory:%s\n", filepath); + char *path = nullptr; + char *sep = nullptr; + struct stat st = {0}; + + path = strdup(filepath); + if (!path) { + LogError("strdup\n"); + return false; + } + + for (sep = strchr(path, '/'); sep != NULL; sep = strchr(sep + 1, '/')) { + *sep = '\0'; + if (strlen(path) == 0) { + *sep = '/'; + continue; + } + if (stat(path, &st) == -1) { + if (errno == ENOENT) { + if (mkdir(path, 0755) == -1) { + LogError("mkdir path failed:%s\n", path); + free(path); + return false; + } + } + else { + LogError("stat\n"); + free(path); + return false; + } + } + + *sep = '/'; + } + free(path); + return true; +} \ No newline at end of file diff --git a/tools/version_release/VersionReleaseTool b/tools/version_release/VersionReleaseTool index 853f654..c08691d 100755 Binary files a/tools/version_release/VersionReleaseTool and b/tools/version_release/VersionReleaseTool differ diff --git a/utils/UpgradeBase/include/UpgradeBase.h b/utils/UpgradeBase/include/UpgradeBase.h index dab0699..31296fa 100644 --- a/utils/UpgradeBase/include/UpgradeBase.h +++ b/utils/UpgradeBase/include/UpgradeBase.h @@ -15,10 +15,11 @@ #ifndef UPGRADE_BASE_H #define UPGRADE_BASE_H #include "StatusCode.h" +constexpr int VERSION_LENGTH = 4; typedef struct __attribute__((packed)) upgrade_file_header { unsigned char packTime[6]; - unsigned char version[4]; + unsigned char version[VERSION_LENGTH]; unsigned char product[2]; unsigned char project[2]; unsigned char upgradeType[1];