Backup:Upgrade State.

This commit is contained in:
Fancy code 2024-05-07 15:53:27 +08:00
parent 75bd13b7a6
commit bc5290047b
34 changed files with 460 additions and 55 deletions

View File

@ -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)
set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager FilesManager StorageManager HuntingUpgrade StatusCode Log Hal pthread dl)

View File

@ -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();

View File

@ -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(

View File

@ -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
```

View File

@ -24,6 +24,7 @@ enum class InternalStateEvent
{
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
CHECK_UPGRADE_FILE,
MEDIA_REPORT_EVENT,
END
};

View File

@ -19,6 +19,7 @@
#include "StorageHandleState.h"
#include "TestMissionState.h"
#include "TopState.h"
#include "UpgradeState.h"
bool CreateMissionManagerModule(void)
{
auto instance = std::make_shared<IMissionManager>();
@ -75,4 +76,9 @@ std::shared_ptr<State> MissionManagerMakePtr::CreateSdCardHandleState(void)
{
std::shared_ptr<State> state = std::make_shared<SdCardHandleState>();
return state;
}
std::shared_ptr<State> MissionManagerMakePtr::CreateUpgradeState(void)
{
std::shared_ptr<State> state = std::make_shared<UpgradeState>();
return state;
}

View File

@ -30,5 +30,6 @@ public:
virtual std::shared_ptr<State> CreateMissionState(const IpcMission &mission);
virtual std::shared_ptr<State> CreateStorageHandleState(void);
virtual std::shared_ptr<State> CreateSdCardHandleState(void);
virtual std::shared_ptr<State> CreateUpgradeState(void);
};
#endif

View File

@ -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;
}

View File

@ -28,5 +28,6 @@ public:
private:
bool MediaReportHandle(VStateMachineData *msg);
bool SdCardEventReportHandle(VStateMachineData *msg);
bool CheckUpgradeFileHandle(VStateMachineData *msg);
};
#endif

View File

@ -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();
/**

View File

@ -28,6 +28,7 @@ enum class SystemState
MISSION_STATE,
STORAGE_HANDLE_STATE,
SD_CARD_HANDLE_STATE,
UPGRADE_STATE,
END
};
class MissionStateMachine

View File

@ -77,5 +77,10 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
mFileNeedToSave.reset();
}
mSdCardStatus = data->mData;
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
std::shared_ptr<VMissionData> message =
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
MissionStateMachine::GetInstance()->SendStateMessage(message);
}
return EXECUTED;
}

View File

@ -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<SdCardHandleState>
{
public:
@ -28,7 +28,7 @@ public:
void GoOutState() override;
bool ExecuteStateMsg(VStateMachineData *msg) override;
private:
protected:
bool MediaReportHandle(VStateMachineData *msg);
bool SdCardEventHandle(VStateMachineData *msg);

View File

@ -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;
}

View File

@ -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<UpgradeState>
{
public:
UpgradeState();
virtual ~UpgradeState() = default;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(VStateMachineData *msg) override;
private:
bool CheckUpgradeFileHandle(VStateMachineData *msg);
};
#endif

View File

@ -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 ------------ #
# ------------ 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 ------------ #

View File

@ -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);

View File

@ -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(

View File

@ -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 <memory>
bool CreateHuntingUpgradeModule(void);
bool DestroyHuntingUpgradeModule(void);
class IHuntingUpgrade
{
public:
IHuntingUpgrade() = default;
virtual ~IHuntingUpgrade() = default;
static std::shared_ptr<IHuntingUpgrade> &GetInstance(std::shared_ptr<IHuntingUpgrade> *impl = nullptr);
virtual StatusCode CheckUpgradeFile(void);
};
#endif

View File

@ -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;
}

View File

@ -16,11 +16,14 @@
#define HUNTING_UPGRADE_H
#include "StatusCode.h"
#include "UpgradeBase.h"
class HuntingUpgrade : public UpgradeBase
#include "IHuntingUpgrade.h"
#include <memory>
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

View File

@ -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<IHuntingUpgrade>();
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>();
IHuntingUpgrade::GetInstance(&instance);
return true;
}
std::shared_ptr<HuntingUpgradeMakePtr> &HuntingUpgradeMakePtr::GetInstance(std::shared_ptr<HuntingUpgradeMakePtr> *impl)
{
static auto instance = std::make_shared<HuntingUpgradeMakePtr>();
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<IHuntingUpgrade> &impl)
{
LogInfo("HuntingUpgradeMakePtr::CreateHuntingUpgrade.\n");
auto tmp = std::make_shared<HuntingUpgradeImpl>();
impl = tmp;
return CreateStatusCode(STATUS_CODE_OK);
}

View File

@ -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 <memory>
class HuntingUpgradeMakePtr
{
public:
HuntingUpgradeMakePtr() = default;
virtual ~HuntingUpgradeMakePtr() = default;
static std::shared_ptr<HuntingUpgradeMakePtr> &GetInstance(std::shared_ptr<HuntingUpgradeMakePtr> *impl = nullptr);
virtual const StatusCode CreateHuntingUpgrade(std::shared_ptr<IHuntingUpgrade> &impl);
};
#endif

View File

@ -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> &IHuntingUpgrade::GetInstance(std::shared_ptr<IHuntingUpgrade> *impl)
{
static auto instance = std::make_shared<IHuntingUpgrade>();
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);
}

View File

@ -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()

View File

@ -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

View File

@ -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})

View File

@ -25,15 +25,10 @@ public:
void Init(void);
void UnInit(void);
private:
// void MissionManagerMockInit(std::shared_ptr<IMissionManager> &vMock);
protected:
void CreateUpgradeFile(void);
private:
std::shared_ptr<IMissionManager> mMissionManagerMock;
// std::shared_ptr<VAppMonitor> mAppMonitorMock;
// public:
// static std::shared_ptr<VAppMonitor> MakeMonitorMock(void);
// void AppMonitorInit(std::shared_ptr<VAppMonitor> &vMock);
};
#endif

View File

@ -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<MissionManagerMock>();
// MissionManagerMockInit(mMissionManagerMock);
std::shared_ptr<MissionManagerMock> mock = std::dynamic_pointer_cast<MissionManagerMock>(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);
}

View File

@ -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<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(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);
}

View File

@ -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

View File

@ -22,22 +22,6 @@ class TopStateTest : public TopState, virtual public MediaMonitorTrace
public:
TopStateTest() = default;
virtual ~TopStateTest() = default;
// StatusCode GetProductInfo(AppGetProductInfo &param) override;
// StatusCode GetDeviceAttr(AppGetDeviceAttr &param) override;
// StatusCode GetMediaInfo(AppGetMeidaInfo &param) override;
// StatusCode GetSdCardInfo(AppGetSdCardInfo &param) override;
// StatusCode GetBatteryInfo(AppGetBatteryInfo &param) override;
// StatusCode GetParamValue(AppParamValue &param) override;
// StatusCode GetCapability(AppGetCapability &param) override;
// StatusCode GetLockVideoStatus(LockVideoStatus &param) override;
// StatusCode GetStorageInfo(std::vector<AppGetStorageInfo> &param) override;
// StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> &param) override;
// StatusCode SetDateTime(const AppSetDateTime &param) override;
// StatusCode SetTimeZone(const unsigned int &zone) override;
// StatusCode SetParamValue(const AppSetParamValue &param) override;
// StatusCode EnterRecorder(void) override;
// StatusCode AppPlayback(const PlayBackEvent &event) override;
// StatusCode UploadFile(AppUploadFile &param) override;
protected:
};

View File

@ -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:

View File

@ -18,24 +18,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);