diff --git a/application/HuntingCamera/build/hunting_camera.cmake b/application/HuntingCamera/build/hunting_camera.cmake index c2556aa2..850d24b0 100644 --- a/application/HuntingCamera/build/hunting_camera.cmake +++ b/application/HuntingCamera/build/hunting_camera.cmake @@ -6,8 +6,9 @@ set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_S set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/MediaManager/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/FilesManager/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/StorageManager/include") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include") -set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager FilesManager StorageManager StatusCode Log Hal pthread dl) \ No newline at end of file +set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager FilesManager StorageManager HuntingUpgrade StatusCode Log Hal pthread dl) \ No newline at end of file diff --git a/application/HuntingCamera/src/MainThread.cpp b/application/HuntingCamera/src/MainThread.cpp index 464219af..4cd40010 100644 --- a/application/HuntingCamera/src/MainThread.cpp +++ b/application/HuntingCamera/src/MainThread.cpp @@ -16,6 +16,7 @@ #include "IAppManager.h" #include "IFilesManager.h" #include "IHalCpp.h" +#include "IHuntingUpgrade.h" #include "ILog.h" #include "IMcuManager.h" #include "IMediaManager.h" @@ -90,10 +91,12 @@ StatusCode MainThread::CreateAllModules(void) CreateStateMachine(); CreateAppManagerModule(); CreateMediaManagerModule(); + CreateHuntingUpgradeModule(); return CreateStatusCode(STATUS_CODE_OK); } void MainThread::DestoryAllModules(void) { + DestroyHuntingUpgradeModule(); DestroyMediaManagerModule(); DestroyAppManagerModule(); DestroyStateMachine(); diff --git a/application/MissionManager/CMakeLists.txt b/application/MissionManager/CMakeLists.txt index 71596696..1ab206c8 100644 --- a/application/MissionManager/CMakeLists.txt +++ b/application/MissionManager/CMakeLists.txt @@ -16,6 +16,7 @@ include_directories( ${MIDDLEWARE_SOURCE_PATH}/StorageManager/include ${MIDDLEWARE_SOURCE_PATH}/McuManager/include ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include + ${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include ) #do not rely on any other library #link_directories( @@ -26,7 +27,7 @@ aux_source_directory(./src SRC_FILES) set(TARGET_NAME MissionManager) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager StatusCode Log) +target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager HuntingUpgrade StatusCode Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/application/MissionManager/README.md b/application/MissionManager/README.md new file mode 100644 index 00000000..9e2f23bb --- /dev/null +++ b/application/MissionManager/README.md @@ -0,0 +1,71 @@ + +# 1. 相机任务管理 + +  相机主业务逻辑使用状态机机制进行管理。 + +## 1.1. 任务状态 + +  任务状态是指相机启动需要执行的任务,可能是拍照 / 视频,可能是其它任务。 + +**例如:** +1. 移动物体侦测启动; +2. 定时启动拍照 / 录像; +3. 测试启动; + +## 1.2. 状态机设计 + +```mermaid +stateDiagram-v2 +[*] --> TopState +TopState --> PowerOff +TopState --> MSDCState +TopState --> DeviceAbnormal +TopState --> MissionState +MissionState --> 存储管理 +存储管理 --> EMMC +存储管理 --> SD卡 +SD卡 --> 插卡 +SD卡 --> 拔卡 +SD卡 --> 卡异常 +MissionState --> 网络管理 +网络管理 --> 联网 +联网 --> 上传文件 +网络管理 --> 未联网 +MissionState --> 直播 +MissionState --> 4G管理 +4G管理 --> Sim卡初始化 +4G管理 --> 注网状态 +MissionState --> Upgrade +``` + +## 1.3. 任务状态获取启动 + +  应用程序运行后,首先需要知道主控是由于何种任务被唤醒,然后根据任务来执行相应的功能代码; + +**时序图** + +```mermaid +sequenceDiagram +participant MCU +participant 大核 +MCU ->> MCU:待机 +opt MCU上电 + MCU ->> 大核:上电 + activate 大核 + 大核 ->> 大核:系统初始化 + 大核 ->> 大核:启动脚本拉起APP + 大核 ->> +MCU:读取启动任务 + MCU -->> -大核:return + alt PIR触发 + 大核 ->> 大核:APP初始化 + 大核 ->> 大核:抓拍并保存 + else 定时 + 大核 ->> 大核:APP初始化 + 大核 ->> 大核:抓拍并保存 + else TEST + 大核 ->> 大核:APP初始化 + 大核 ->> 大核:待机 + end + deactivate 大核 +end +``` \ No newline at end of file diff --git a/application/MissionManager/src/DataProcessing.h b/application/MissionManager/src/DataProcessing.h index 9a4a7e1d..2ad8653a 100644 --- a/application/MissionManager/src/DataProcessing.h +++ b/application/MissionManager/src/DataProcessing.h @@ -24,6 +24,7 @@ enum class InternalStateEvent { STORAGE_HANDLE_STATE_INIT = static_cast(MissionEvent::END), SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED, + CHECK_UPGRADE_FILE, MEDIA_REPORT_EVENT, END }; diff --git a/application/MissionManager/src/MissionManagerMakePtr.cpp b/application/MissionManager/src/MissionManagerMakePtr.cpp index 961bf2ed..5d4f839b 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.cpp +++ b/application/MissionManager/src/MissionManagerMakePtr.cpp @@ -19,6 +19,7 @@ #include "StorageHandleState.h" #include "TestMissionState.h" #include "TopState.h" +#include "UpgradeState.h" bool CreateMissionManagerModule(void) { auto instance = std::make_shared(); @@ -75,4 +76,9 @@ std::shared_ptr MissionManagerMakePtr::CreateSdCardHandleState(void) { std::shared_ptr state = std::make_shared(); return state; +} +std::shared_ptr MissionManagerMakePtr::CreateUpgradeState(void) +{ + std::shared_ptr state = std::make_shared(); + return state; } \ No newline at end of file diff --git a/application/MissionManager/src/MissionManagerMakePtr.h b/application/MissionManager/src/MissionManagerMakePtr.h index ff4f8554..cb6b6460 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.h +++ b/application/MissionManager/src/MissionManagerMakePtr.h @@ -30,5 +30,6 @@ public: virtual std::shared_ptr CreateMissionState(const IpcMission &mission); virtual std::shared_ptr CreateStorageHandleState(void); virtual std::shared_ptr CreateSdCardHandleState(void); + virtual std::shared_ptr CreateUpgradeState(void); }; #endif \ No newline at end of file diff --git a/application/MissionManager/src/MissionState.cpp b/application/MissionManager/src/MissionState.cpp index 5a0c37f1..a872ff9e 100644 --- a/application/MissionManager/src/MissionState.cpp +++ b/application/MissionManager/src/MissionState.cpp @@ -21,6 +21,7 @@ MissionState::MissionState(const std::string &name) : State(name) mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&MissionState::MediaReportHandle, this, _1); mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] = std::bind(&MissionState::SdCardEventReportHandle, this, _1); + mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&MissionState::CheckUpgradeFileHandle, this, _1); } void MissionState::GoInState() { @@ -45,4 +46,10 @@ bool MissionState::SdCardEventReportHandle(VStateMachineData *msg) MissionStateMachine::GetInstance()->DelayMessage(msg); MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE); return EXECUTED; +} +bool MissionState::CheckUpgradeFileHandle(VStateMachineData *msg) +{ + MissionStateMachine::GetInstance()->DelayMessage(msg); + MissionStateMachine::GetInstance()->SwitchState(SystemState::UPGRADE_STATE); + return EXECUTED; } \ No newline at end of file diff --git a/application/MissionManager/src/MissionState.h b/application/MissionManager/src/MissionState.h index 21d20374..84d1aa08 100644 --- a/application/MissionManager/src/MissionState.h +++ b/application/MissionManager/src/MissionState.h @@ -28,5 +28,6 @@ public: private: bool MediaReportHandle(VStateMachineData *msg); bool SdCardEventReportHandle(VStateMachineData *msg); + bool CheckUpgradeFileHandle(VStateMachineData *msg); }; #endif \ No newline at end of file diff --git a/application/MissionManager/src/MissionStateMachine.cpp b/application/MissionManager/src/MissionStateMachine.cpp index 27775200..950bb7aa 100644 --- a/application/MissionManager/src/MissionStateMachine.cpp +++ b/application/MissionManager/src/MissionStateMachine.cpp @@ -91,12 +91,15 @@ void MissionStateMachine::RunStateMachine(const IpcMission &mission) mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission); mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState(); mStateTree[SystemState::SD_CARD_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateSdCardHandleState(); + mStateTree[SystemState::UPGRADE_STATE] = MissionManagerMakePtr::GetInstance()->CreateUpgradeState(); mStateMachine->StatePlus(mStateTree[SystemState::TOP_STATE].get(), nullptr); mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get()); mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(), mStateTree[SystemState::MISSION_STATE].get()); mStateMachine->StatePlus(mStateTree[SystemState::SD_CARD_HANDLE_STATE].get(), mStateTree[SystemState::STORAGE_HANDLE_STATE].get()); + mStateMachine->StatePlus(mStateTree[SystemState::UPGRADE_STATE].get(), + mStateTree[SystemState::MISSION_STATE].get()); mStateMachine->SetCurrentState(mStateTree[SystemState::TOP_STATE].get()); mStateMachine->StartStateMachine(); /** diff --git a/application/MissionManager/src/MissionStateMachine.h b/application/MissionManager/src/MissionStateMachine.h index 995133d4..ea2c79ea 100644 --- a/application/MissionManager/src/MissionStateMachine.h +++ b/application/MissionManager/src/MissionStateMachine.h @@ -28,6 +28,7 @@ enum class SystemState MISSION_STATE, STORAGE_HANDLE_STATE, SD_CARD_HANDLE_STATE, + UPGRADE_STATE, END }; class MissionStateMachine diff --git a/application/MissionManager/src/SdCardHandleState.cpp b/application/MissionManager/src/SdCardHandleState.cpp index 39c03851..a465b797 100644 --- a/application/MissionManager/src/SdCardHandleState.cpp +++ b/application/MissionManager/src/SdCardHandleState.cpp @@ -77,5 +77,10 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg) mFileNeedToSave.reset(); } mSdCardStatus = data->mData; + if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) { + std::shared_ptr message = + std::make_shared(static_cast(InternalStateEvent::CHECK_UPGRADE_FILE)); + MissionStateMachine::GetInstance()->SendStateMessage(message); + } return EXECUTED; } \ No newline at end of file diff --git a/application/MissionManager/src/SdCardHandleState.h b/application/MissionManager/src/SdCardHandleState.h index d8a0c987..c8eb7efb 100644 --- a/application/MissionManager/src/SdCardHandleState.h +++ b/application/MissionManager/src/SdCardHandleState.h @@ -15,10 +15,10 @@ #ifndef SD_CARD_HANDLE_STATE_H #define SD_CARD_HANDLE_STATE_H #include "DataProcessing.h" +#include "IFilesManager.h" #include "IMediaManager.h" #include "IStateMachine.h" #include "IStorageManager.h" -#include "IFilesManager.h" class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this { public: @@ -28,7 +28,7 @@ public: void GoOutState() override; bool ExecuteStateMsg(VStateMachineData *msg) override; -private: +protected: bool MediaReportHandle(VStateMachineData *msg); bool SdCardEventHandle(VStateMachineData *msg); diff --git a/application/MissionManager/src/UpgradeState.cpp b/application/MissionManager/src/UpgradeState.cpp new file mode 100644 index 00000000..c2f0846b --- /dev/null +++ b/application/MissionManager/src/UpgradeState.cpp @@ -0,0 +1,40 @@ +/* + * 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 "UpgradeState.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); +} +void UpgradeState::GoInState() +{ + LogInfo(" ========== opState::GoInState.\n"); +} +void UpgradeState::GoOutState() +{ + LogInfo(" ========== opState::GoOutState.\n"); +} +bool UpgradeState::ExecuteStateMsg(VStateMachineData *msg) +{ + return DataProcessing::EventHandle(msg); +} +bool UpgradeState::CheckUpgradeFileHandle(VStateMachineData *msg) +{ + IHuntingUpgrade::GetInstance()->CheckUpgradeFile(); + return EXECUTED; +} \ No newline at end of file diff --git a/application/MissionManager/src/UpgradeState.h b/application/MissionManager/src/UpgradeState.h new file mode 100644 index 00000000..99b23ebd --- /dev/null +++ b/application/MissionManager/src/UpgradeState.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 UPGRADE_STATE_H +#define UPGRADE_STATE_H +#include "DataProcessing.h" +#include "IMediaManager.h" +#include "IStateMachine.h" +class UpgradeState : public State, public DataProcessing, public std::enable_shared_from_this +{ +public: + UpgradeState(); + virtual ~UpgradeState() = default; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(VStateMachineData *msg) override; + +private: + bool CheckUpgradeFileHandle(VStateMachineData *msg); +}; +#endif \ No newline at end of file diff --git a/build/cmake/toolchain/linux.toolchain.cmake b/build/cmake/toolchain/linux.toolchain.cmake index 1206dc1a..5cef9eaf 100755 --- a/build/cmake/toolchain/linux.toolchain.cmake +++ b/build/cmake/toolchain/linux.toolchain.cmake @@ -77,4 +77,12 @@ set(APP_MANAGER_TCP_SERVER_PORT "9876") # ------------ build sd card ------------ # set(SD_CARD_DEV "/dev/test") set(SD_CARD_MOUNT_PATH "./sdcard") -# ------------ build sd card end ------------ # \ No newline at end of file +# ------------ build sd card end ------------ # + +# ------------ build upgrade ------------ # +set(APPLICATION_CHECK_PATH "/application.bin") +set(APPLICATION_VERSION_1 1) +set(APPLICATION_VERSION_2 0) +set(APPLICATION_VERSION_3 0) +set(APPLICATION_VERSION_4 0) +# ------------ build upgrade end ------------ # \ No newline at end of file diff --git a/hal/src/SdCardHal.cpp b/hal/src/SdCardHal.cpp index 40af110a..ce034f5d 100644 --- a/hal/src/SdCardHal.cpp +++ b/hal/src/SdCardHal.cpp @@ -123,7 +123,7 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status) LogInfo("SdCardHalStatus changed: %s.\n", PrintfStatusString(status)); SdCardHalStatus mountedStatus = SdCardHalStatus::END; if (SdCardHalStatus::INSERTED == status) { - LogInfo("mount sd SD_CARD_DEVICE %s.\n", SD_CARD_MOUNT_PATH); + LogInfo("mount sd to %s.\n", SD_CARD_MOUNT_PATH); constexpr int BUF_LENGTH = 128; char cmd[BUF_LENGTH] = {0}; snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH); diff --git a/middleware/HuntingUpgrade/CMakeLists.txt b/middleware/HuntingUpgrade/CMakeLists.txt index 7d2c234e..cbfcd316 100644 --- a/middleware/HuntingUpgrade/CMakeLists.txt +++ b/middleware/HuntingUpgrade/CMakeLists.txt @@ -1,5 +1,6 @@ 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}) @@ -14,12 +15,14 @@ include_directories( #link_directories( #) +add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_PATH}\") + aux_source_directory(./src SRC_FILES) set(TARGET_NAME HuntingUpgrade) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} UpgradeBase Hal StatusCode Log) +target_link_libraries(${TARGET_NAME} UpgradeBase StatusCode Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/middleware/HuntingUpgrade/include/IHuntingUpgrade.h b/middleware/HuntingUpgrade/include/IHuntingUpgrade.h new file mode 100644 index 00000000..81739261 --- /dev/null +++ b/middleware/HuntingUpgrade/include/IHuntingUpgrade.h @@ -0,0 +1,29 @@ +/* + * 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 I_HUNTING_UPGRADE_H +#define I_HUNTING_UPGRADE_H +#include "StatusCode.h" +#include +bool CreateHuntingUpgradeModule(void); +bool DestroyHuntingUpgradeModule(void); +class IHuntingUpgrade +{ +public: + IHuntingUpgrade() = default; + virtual ~IHuntingUpgrade() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual StatusCode CheckUpgradeFile(void); +}; +#endif \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/HuntingUpgrade.cpp b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp similarity index 57% rename from middleware/HuntingUpgrade/src/HuntingUpgrade.cpp rename to middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp index 0c0e1b33..02c0402b 100644 --- a/middleware/HuntingUpgrade/src/HuntingUpgrade.cpp +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp @@ -12,8 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "HuntingUpgrade.h" -StatusCode HuntingUpgrade::CheckFileHeader(const UpgradeFileHeader &head) +#include "HuntingUpgradeImpl.h" +#include "ILog.h" +StatusCode HuntingUpgradeImpl::CheckFileHeader(const UpgradeFileHeader &head) { return CreateStatusCode(STATUS_CODE_OK); +} +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"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + return code; } \ No newline at end of file diff --git a/middleware/HuntingUpgrade/include/HuntingUpgrade.h b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.h similarity index 75% rename from middleware/HuntingUpgrade/include/HuntingUpgrade.h rename to middleware/HuntingUpgrade/src/HuntingUpgradeImpl.h index 79620a1d..5b54b9a3 100644 --- a/middleware/HuntingUpgrade/include/HuntingUpgrade.h +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.h @@ -16,11 +16,14 @@ #define HUNTING_UPGRADE_H #include "StatusCode.h" #include "UpgradeBase.h" -class HuntingUpgrade : public UpgradeBase +#include "IHuntingUpgrade.h" +#include +class HuntingUpgradeImpl : public UpgradeBase, public IHuntingUpgrade { public: - HuntingUpgrade() = default; - virtual ~HuntingUpgrade() = default; + HuntingUpgradeImpl() = default; + virtual ~HuntingUpgradeImpl() = default; StatusCode CheckFileHeader(const UpgradeFileHeader &head) override; + StatusCode CheckUpgradeFile(void) override; }; #endif \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.cpp b/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.cpp new file mode 100644 index 00000000..2f4ad03c --- /dev/null +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.cpp @@ -0,0 +1,55 @@ +/* + * 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 "HuntingUpgradeMakePtr.h" +#include "HuntingUpgradeImpl.h" +#include "ILog.h" +bool CreateHuntingUpgradeModule(void) +{ + auto instance = std::make_shared(); + StatusCode code = HuntingUpgradeMakePtr::GetInstance()->CreateHuntingUpgrade(instance); + if (IsCodeOK(code)) { + LogInfo("CreateHuntingUpgrade is ok.\n"); + IHuntingUpgrade::GetInstance(&instance); + return true; + } + return false; +} +bool DestroyHuntingUpgradeModule(void) +{ + auto instance = std::make_shared(); + IHuntingUpgrade::GetInstance(&instance); + return true; +} +std::shared_ptr &HuntingUpgradeMakePtr::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + 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; +} +const StatusCode HuntingUpgradeMakePtr::CreateHuntingUpgrade(std::shared_ptr &impl) +{ + LogInfo("HuntingUpgradeMakePtr::CreateHuntingUpgrade.\n"); + auto tmp = std::make_shared(); + impl = tmp; + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.h b/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.h new file mode 100644 index 00000000..2030ad9f --- /dev/null +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.h @@ -0,0 +1,28 @@ +/* + * 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_MAKE_PTR_H +#define HUNTING_UPGRADE_MAKE_PTR_H +#include "IHuntingUpgrade.h" +#include "StatusCode.h" +#include +class HuntingUpgradeMakePtr +{ +public: + HuntingUpgradeMakePtr() = default; + virtual ~HuntingUpgradeMakePtr() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual const StatusCode CreateHuntingUpgrade(std::shared_ptr &impl); +}; +#endif \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/IHuntingUpgrade.cpp b/middleware/HuntingUpgrade/src/IHuntingUpgrade.cpp new file mode 100644 index 00000000..a746536d --- /dev/null +++ b/middleware/HuntingUpgrade/src/IHuntingUpgrade.cpp @@ -0,0 +1,34 @@ +/* + * 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 "IHuntingUpgrade.h" +#include "ILog.h" +std::shared_ptr &IHuntingUpgrade::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + 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; +} +StatusCode IHuntingUpgrade::CheckUpgradeFile(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/test/application/HuntingCamera/CMakeLists.txt b/test/application/HuntingCamera/CMakeLists.txt index f30e66a7..07de680e 100644 --- a/test/application/HuntingCamera/CMakeLists.txt +++ b/test/application/HuntingCamera/CMakeLists.txt @@ -38,7 +38,7 @@ endif() set(TARGET_NAME HuntingCameraTest) add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} HunttingMainLib MissionManagerTestTool McuManagerTestTool McuAskBaseTestTool AppManagerTestTool HalTestTool TestManager gtest gmock pthread) +target_link_libraries(${TARGET_NAME} HuntingMainLib MissionManagerTestTool McuManagerTestTool McuAskBaseTestTool AppManagerTestTool HalTestTool TestManager gtest gmock pthread) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() diff --git a/test/application/HuntingCamera/src_mock/MediaManager_Mock_Test.cpp b/test/application/HuntingCamera/src_mock/MediaManager_Mock_Test.cpp index 26b55d98..ea2466f1 100644 --- a/test/application/HuntingCamera/src_mock/MediaManager_Mock_Test.cpp +++ b/test/application/HuntingCamera/src_mock/MediaManager_Mock_Test.cpp @@ -30,6 +30,7 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot) { SetAllCamerasResult(mAllCamerasMock); MockReportCameraEvent("/tmp/test.MP4", CameraType::MAIN_CAMERA); + CreateUpgradeFile(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); // McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest); MainThread::GetInstance()->Init(); @@ -37,6 +38,5 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot) std::this_thread::sleep_for(std::chrono::milliseconds(100)); // MockAppPlayback(); MainThread::GetInstance()->Runing(); - MainThread::GetInstance()->UnInit(); } } // namespace MediaManager_Mock_Test \ No newline at end of file diff --git a/test/application/MissionManager/tool/CMakeLists.txt b/test/application/MissionManager/tool/CMakeLists.txt index 07592368..2bf9e9fc 100644 --- a/test/application/MissionManager/tool/CMakeLists.txt +++ b/test/application/MissionManager/tool/CMakeLists.txt @@ -1,18 +1,23 @@ 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 ${APPLICATION_SOURCE_PATH}/MissionManager/include ${APPLICATION_SOURCE_PATH}/MissionManager/src ${MIDDLEWARE_SOURCE_PATH}/AppManager/include ${MIDDLEWARE_SOURCE_PATH}/MediaManager/include ${MIDDLEWARE_SOURCE_PATH}/StateMachine/include ${MIDDLEWARE_SOURCE_PATH}/McuManager/include + ${MIDDLEWARE_SOURCE_PATH}/StorageManager/include + ${MIDDLEWARE_SOURCE_PATH}/StorageManager/src + ${MIDDLEWARE_SOURCE_PATH}/FilesManager/include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/LinuxApi/include ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/middleware/AppManager/tool/include ${TEST_SOURCE_PATH}/middleware/AppManager/tool/src @@ -25,6 +30,8 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) +add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_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/MissionManager/tool/include/MissionManagerTestTool.h b/test/application/MissionManager/tool/include/MissionManagerTestTool.h index 26c32d95..0cdbc9ac 100644 --- a/test/application/MissionManager/tool/include/MissionManagerTestTool.h +++ b/test/application/MissionManager/tool/include/MissionManagerTestTool.h @@ -25,15 +25,10 @@ public: void Init(void); void UnInit(void); -private: - // void MissionManagerMockInit(std::shared_ptr &vMock); +protected: + void CreateUpgradeFile(void); private: std::shared_ptr mMissionManagerMock; - // std::shared_ptr mAppMonitorMock; - - // public: - // static std::shared_ptr MakeMonitorMock(void); - // void AppMonitorInit(std::shared_ptr &vMock); }; #endif \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp b/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp index d13048e0..047ef9e7 100644 --- a/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp +++ b/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp @@ -13,20 +13,21 @@ * limitations under the License. */ #include "MissionManagerTestTool.h" +#include "LinuxApi.h" #include "MissionManagerMakePtrTest.h" #include "MissionManagerMock.h" void MissionManagerTestTool::Init(void) { - // ServersMock::GetInstance()->Init(); mMissionManagerMock = std::make_shared(); - // MissionManagerMockInit(mMissionManagerMock); std::shared_ptr mock = std::dynamic_pointer_cast(mMissionManagerMock); OverrideMissionManagerMakePtrObject(mock); } void MissionManagerTestTool::UnInit(void) { - // ServersMock::GetInstance()->UnInit(); mMissionManagerMock.reset(); - // mAppMonitorMock.reset(); CancelOverrideMissionManagerMakePtrObject(); +} +void MissionManagerTestTool::CreateUpgradeFile(void) +{ + fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH); } \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/SdCardHandleStateMock.cpp b/test/application/MissionManager/tool/src/SdCardHandleStateMock.cpp new file mode 100644 index 00000000..1ef9deb9 --- /dev/null +++ b/test/application/MissionManager/tool/src/SdCardHandleStateMock.cpp @@ -0,0 +1,34 @@ +/* + * 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 "SdCardHandleStateMock.h" +#include "ILog.h" +#include "StatusCode.h" +SdCardHandleStateTest::SdCardHandleStateTest() +{ +} +bool SdCardHandleStateTest::SdCardEventHandle(VStateMachineData *msg) +{ + std::shared_ptr message = std::dynamic_pointer_cast(msg->GetMessageObj()); + std::shared_ptr> data = + std::dynamic_pointer_cast>(message->mMissionData); + if (StorageEvent::SD_CARD_INSERT == data->mData) { + const std::string realSavePah = SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH; + bool directoryExist = StorageBase::CheckDirectory(realSavePah.c_str()); + if (false == directoryExist) { + LogWarning("Directory not exist.\n"); + } + } + return SdCardHandleState::SdCardEventHandle(msg); +} \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/SdCardHandleStateMock.h b/test/application/MissionManager/tool/src/SdCardHandleStateMock.h new file mode 100644 index 00000000..5f06a26a --- /dev/null +++ b/test/application/MissionManager/tool/src/SdCardHandleStateMock.h @@ -0,0 +1,36 @@ +/* + * 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 SD_CARD_HANDLE_STATE_MOCK_H +#define SD_CARD_HANDLE_STATE_MOCK_H +#include "MediaMonitorMock.h" +#include "MissionManagerTestTool.h" +#include "SdCardHandleState.h" +#include "StorageBase.h" +class SdCardHandleStateTest : public SdCardHandleState, virtual public MediaMonitorTrace, public StorageBase +{ +public: + SdCardHandleStateTest(); + virtual ~SdCardHandleStateTest() = default; + +private: + bool SdCardEventHandle(VStateMachineData *msg); +}; +class SdCardHandleStateMock : public MediaMonitorMock, public SdCardHandleStateTest +{ +public: + SdCardHandleStateMock() = default; + virtual ~SdCardHandleStateMock() = default; +}; +#endif \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/TopStateMock.h b/test/application/MissionManager/tool/src/TopStateMock.h index 8dfb5bc6..a54480f6 100644 --- a/test/application/MissionManager/tool/src/TopStateMock.h +++ b/test/application/MissionManager/tool/src/TopStateMock.h @@ -22,22 +22,6 @@ class TopStateTest : public TopState, virtual public MediaMonitorTrace public: TopStateTest() = default; virtual ~TopStateTest() = default; - // StatusCode GetProductInfo(AppGetProductInfo ¶m) override; - // StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override; - // StatusCode GetMediaInfo(AppGetMeidaInfo ¶m) override; - // StatusCode GetSdCardInfo(AppGetSdCardInfo ¶m) override; - // StatusCode GetBatteryInfo(AppGetBatteryInfo ¶m) override; - // StatusCode GetParamValue(AppParamValue ¶m) override; - // StatusCode GetCapability(AppGetCapability ¶m) override; - // StatusCode GetLockVideoStatus(LockVideoStatus ¶m) override; - // StatusCode GetStorageInfo(std::vector ¶m) override; - // StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector ¶m) override; - // StatusCode SetDateTime(const AppSetDateTime ¶m) override; - // StatusCode SetTimeZone(const unsigned int &zone) override; - // StatusCode SetParamValue(const AppSetParamValue ¶m) override; - // StatusCode EnterRecorder(void) override; - // StatusCode AppPlayback(const PlayBackEvent &event) override; - // StatusCode UploadFile(AppUploadFile ¶m) override; protected: }; diff --git a/utils/UpgradeBase/include/UpgradeBase.h b/utils/UpgradeBase/include/UpgradeBase.h index d0ccfcec..a16408b6 100644 --- a/utils/UpgradeBase/include/UpgradeBase.h +++ b/utils/UpgradeBase/include/UpgradeBase.h @@ -24,19 +24,24 @@ typedef struct __attribute__((packed)) upgrade_file_header unsigned char upgradeType[1]; unsigned char reserved[17]; } UpgradeFileHeader; +enum class UpgradeType +{ + APPLICATION_ONLY = 0, + END +}; class UpgradeBase { public: UpgradeBase() = default; virtual ~UpgradeBase() = default; - virtual StatusCode CheckFileHeader(const UpgradeFileHeader &head) = 0; + virtual StatusCode CheckFileHeader(const UpgradeFileHeader &header) = 0; /** * @brief Verify if the file belongs to the upgrade file. * * @param fileName The file name being verified. Enter the parameter using an absolute path. * @return StatusCode */ - StatusCode CheckUpgradeFile(const char *fileName); + StatusCode CheckUpgradeFile(const char *fileName, UpgradeFileHeader &header); StatusCode MoveUpgradeFile(const char *sourceFile, const char *targetFile); private: diff --git a/utils/UpgradeBase/src/UpgradeBase.cpp b/utils/UpgradeBase/src/UpgradeBase.cpp index 964f8c8d..288249c0 100644 --- a/utils/UpgradeBase/src/UpgradeBase.cpp +++ b/utils/UpgradeBase/src/UpgradeBase.cpp @@ -18,24 +18,23 @@ #include #include #include -StatusCode UpgradeBase::CheckUpgradeFile(const char *fileName) +StatusCode UpgradeBase::CheckUpgradeFile(const char *fileName, UpgradeFileHeader &header) { FILE *file = nullptr; - UpgradeFileHeader fileHead; file = fopen(fileName, "rb"); if (file == NULL) { - perror("Error opening file"); + LogError("Error opening file:%s\n", fileName); return CreateStatusCode(STATUS_CODE_NOT_OK); } - size_t bytesRead = fread(&fileHead, sizeof(UpgradeFileHeader), 1, file); + size_t bytesRead = fread(&header, sizeof(UpgradeFileHeader), 1, file); if (bytesRead != 1) { - perror("Error reading file header"); + LogError("Error reading file header\n"); fclose(file); return CreateStatusCode(STATUS_CODE_NOT_OK); } - return CheckFileHeader(fileHead); + return CheckFileHeader(header); } StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targetFile) { @@ -49,20 +48,20 @@ StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targ inputFile = fopen(sourceFile, "rb"); if (inputFile == NULL) { - perror("Error opening input file"); + LogError("Error opening input file\n"); return CreateStatusCode(STATUS_CODE_NOT_OK); } outputFile = fopen(targetFile, "wb"); if (outputFile == NULL) { - perror("Error opening output file"); + LogError("Error opening output file\n"); fclose(inputFile); return CreateStatusCode(STATUS_CODE_NOT_OK); } bytesRead = fread(&fileHeader, 1, headerSize, inputFile); if (bytesRead != headerSize) { - perror("Error reading file header"); + LogError("Error reading file header\n"); fclose(inputFile); fclose(outputFile); return CreateStatusCode(STATUS_CODE_NOT_OK); @@ -71,7 +70,7 @@ StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targ while ((bytesRead = fread(buffer, 1, sizeof(buffer), inputFile)) > 0) { fwrite(buffer, 1, bytesRead, outputFile); if (ferror(inputFile) || ferror(outputFile)) { - perror("Error reading or writing file"); + LogError("Error reading or writing file\n"); fclose(inputFile); fclose(outputFile); return CreateStatusCode(STATUS_CODE_NOT_OK);