diff --git a/application/HuntingCamera/src/MainThread.cpp b/application/HuntingCamera/src/MainThread.cpp index 41fd0c96..628e91ec 100644 --- a/application/HuntingCamera/src/MainThread.cpp +++ b/application/HuntingCamera/src/MainThread.cpp @@ -123,6 +123,5 @@ void MainThread::Runing(void) extern bool CreateProtocolHandleImpl(void); void MainThread::CustomizationInit(void) { - // CreateProtocolHandleImpl(); } \ No newline at end of file diff --git a/middleware/IpcConfig/README.md b/middleware/IpcConfig/README.md index f44257d9..c95f4b27 100644 --- a/middleware/IpcConfig/README.md +++ b/middleware/IpcConfig/README.md @@ -12,4 +12,10 @@ ## 1.3. 数据丢失还原机制 +  针对可能发生的数据丢失/损坏,提供数据还原机制。 + +* 系统配置一份默认的只读配置文件,用于数据丢失/损坏时使用; + ## 1.4. 数据备份还原机制 + +  每次修改配置文件,需要备份一份,用于数据丢失/损坏时使用; diff --git a/test/application/VersionReleaseTool/CMakeLists.txt b/test/application/VersionReleaseTool/CMakeLists.txt index 11dfe15b..5014efea 100644 --- a/test/application/VersionReleaseTool/CMakeLists.txt +++ b/test/application/VersionReleaseTool/CMakeLists.txt @@ -1,7 +1,7 @@ # include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) # include(${APPLICATION_SOURCE_PATH}/VersionRelease/build/hunting_camera.cmake) -set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR_IPCSDK}/tools/version_release) include_directories( ./src diff --git a/test/application/VersionReleaseTool/mainTest.cpp b/test/application/VersionReleaseTool/mainTest.cpp index 71aa4a04..6f2dadb5 100644 --- a/test/application/VersionReleaseTool/mainTest.cpp +++ b/test/application/VersionReleaseTool/mainTest.cpp @@ -24,8 +24,8 @@ int main(int argc, char *argv[]) ILogInit(LOG_INSTANCE_TYPE_END); ArgvAnalysis::GetInstance()->Analyze(argc, argv); testing::InitGoogleTest(&argc, argv); - RUN_ALL_TESTS(); + int result = RUN_ALL_TESTS(); ILogUnInit(); DestroyLogModule(); - return 0; + return result; } \ No newline at end of file diff --git a/test/application/VersionReleaseTool/src/ArgvAnalysis.cpp b/test/application/VersionReleaseTool/src/ArgvAnalysis.cpp index 103f4560..49d968b7 100644 --- a/test/application/VersionReleaseTool/src/ArgvAnalysis.cpp +++ b/test/application/VersionReleaseTool/src/ArgvAnalysis.cpp @@ -14,6 +14,8 @@ */ #include "ArgvAnalysis.h" #include "ILog.h" +const char *V_SOURCE_FILE = "v_source_file"; +const char *V_OUTPUT_FILE = "v_output_file"; std::shared_ptr &ArgvAnalysis::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -55,4 +57,22 @@ void ArgvAnalysis::Analyze(int argc, char *argv[]) for (const auto &pair : mOptions) { LogInfo("Key: %s, Value: %s\n", pair.first.c_str(), pair.second.c_str()); } +} +std::string ArgvAnalysis::GetSourceFile(void) +{ + auto it = mOptions.find(V_SOURCE_FILE); + if (it != mOptions.end()) { + return it->second; + } + LogWarning("Can't find the source file.\n"); + return ""; +} +std::string ArgvAnalysis::GetOutputFile(void) +{ + auto it = mOptions.find(V_OUTPUT_FILE); + if (it != mOptions.end()) { + return it->second; + } + LogWarning("Can't find the source file.\n"); + return ""; } \ No newline at end of file diff --git a/test/application/VersionReleaseTool/src/ArgvAnalysis.h b/test/application/VersionReleaseTool/src/ArgvAnalysis.h index 82db6cc4..c4af3023 100644 --- a/test/application/VersionReleaseTool/src/ArgvAnalysis.h +++ b/test/application/VersionReleaseTool/src/ArgvAnalysis.h @@ -24,6 +24,8 @@ public: virtual ~ArgvAnalysis() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); void Analyze(int argc, char *argv[]); + std::string GetSourceFile(void); + std::string GetOutputFile(void); private: std::map mOptions; diff --git a/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp b/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp index 0539796d..eb68e6f6 100644 --- a/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp +++ b/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp @@ -12,15 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "VersionReleaseTool.h" #include "GtestUsing.h" #include "ILog.h" #include "UpgradeTool.h" -#include "VersionReleaseTool.h" +#include "ArgvAnalysis.h" #include namespace VersionReleaseTool { +/** + * @brief Construct a new TEST object + * ../output_files/test/bin/VersionReleaseTool --v_source_file=./test.bin --v_output_file=./test_output.bin + */ TEST(VersionReleaseTool, Version) { - UpgradeTool::GetInstance()->PackFile("src", "output", "1.0.0", "product", "project", "upgradeType"); + std::string sourceFile = ArgvAnalysis::GetInstance()->GetSourceFile(); + std::string outputFile = ArgvAnalysis::GetInstance()->GetOutputFile(); + UpgradeTool::GetInstance()->PackFile(sourceFile, outputFile, "1.0.0", "product", "project", "upgradeType"); } } // namespace VersionReleaseTool \ No newline at end of file diff --git a/tools/version_release/VersionReleaseTool b/tools/version_release/VersionReleaseTool new file mode 100755 index 00000000..3ce420b0 Binary files /dev/null and b/tools/version_release/VersionReleaseTool differ diff --git a/utils/UpgradeTool/src/UpgradeTool.cpp b/utils/UpgradeTool/src/UpgradeTool.cpp index dcb5545d..7fffe277 100644 --- a/utils/UpgradeTool/src/UpgradeTool.cpp +++ b/utils/UpgradeTool/src/UpgradeTool.cpp @@ -82,6 +82,7 @@ void UpgradeTool::FillInTime(unsigned char packTime[6]) 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) { + struct stat fileStat; UpgradeFileHeader header; memset(&header, 0, sizeof(UpgradeFileHeader)); StringToVersionBytes(version, header.version); @@ -91,6 +92,12 @@ void UpgradeTool::PackFile(const std::string &fileName, const std::string &outpu perror("Error opening input file"); return; } + if (stat(fileName.c_str(), &fileStat) == -1) { + LogError("Error getting file size\n"); + fclose(input_file); + return; + } + LogInfo("File size:%ld\n", fileStat.st_size); FILE *output_file = fopen(outputFile.c_str(), "wb"); if (!output_file) { @@ -98,11 +105,28 @@ void UpgradeTool::PackFile(const std::string &fileName, const std::string &outpu fclose(input_file); return; } + long writeSize = 0; fwrite(&header, sizeof(header), 1, output_file); char buffer[1024]; - size_t bytes_read; + size_t bytes_read = 0; + size_t bytes_write = 0; while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) { - fwrite(buffer, 1, bytes_read, output_file); + bytes_write = fwrite(buffer, 1, bytes_read, output_file); + if (bytes_write != bytes_read) { + LogError("fwrite failed, break;\n"); + break; + } + writeSize += bytes_write; + } + LogInfo("write size:%ld\n", writeSize); + if (writeSize != fileStat.st_size) { + LogError("write file failed, remove output file.\n"); + char cmd[1024]; + snprintf(cmd, sizeof(cmd), "rm -f %s", outputFile.c_str()); + fx_system(cmd); + } + else { + LogInfo("write file success.\n"); } fclose(input_file); fclose(output_file);