Backup:Upgrade State.
This commit is contained in:
parent
75bd13b7a6
commit
bc5290047b
|
@ -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}/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}/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}/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}/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};${UTILS_SOURCE_PATH}/Log/include")
|
||||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/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)
|
|
@ -16,6 +16,7 @@
|
||||||
#include "IAppManager.h"
|
#include "IAppManager.h"
|
||||||
#include "IFilesManager.h"
|
#include "IFilesManager.h"
|
||||||
#include "IHalCpp.h"
|
#include "IHalCpp.h"
|
||||||
|
#include "IHuntingUpgrade.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IMcuManager.h"
|
#include "IMcuManager.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
|
@ -90,10 +91,12 @@ StatusCode MainThread::CreateAllModules(void)
|
||||||
CreateStateMachine();
|
CreateStateMachine();
|
||||||
CreateAppManagerModule();
|
CreateAppManagerModule();
|
||||||
CreateMediaManagerModule();
|
CreateMediaManagerModule();
|
||||||
|
CreateHuntingUpgradeModule();
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
void MainThread::DestoryAllModules(void)
|
void MainThread::DestoryAllModules(void)
|
||||||
{
|
{
|
||||||
|
DestroyHuntingUpgradeModule();
|
||||||
DestroyMediaManagerModule();
|
DestroyMediaManagerModule();
|
||||||
DestroyAppManagerModule();
|
DestroyAppManagerModule();
|
||||||
DestroyStateMachine();
|
DestroyStateMachine();
|
||||||
|
|
|
@ -16,6 +16,7 @@ include_directories(
|
||||||
${MIDDLEWARE_SOURCE_PATH}/StorageManager/include
|
${MIDDLEWARE_SOURCE_PATH}/StorageManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include
|
||||||
)
|
)
|
||||||
#do not rely on any other library
|
#do not rely on any other library
|
||||||
#link_directories(
|
#link_directories(
|
||||||
|
@ -26,7 +27,7 @@ aux_source_directory(./src SRC_FILES)
|
||||||
set(TARGET_NAME MissionManager)
|
set(TARGET_NAME MissionManager)
|
||||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
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")
|
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
71
application/MissionManager/README.md
Normal file
71
application/MissionManager/README.md
Normal 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
|
||||||
|
```
|
|
@ -24,6 +24,7 @@ enum class InternalStateEvent
|
||||||
{
|
{
|
||||||
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
||||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
||||||
|
CHECK_UPGRADE_FILE,
|
||||||
MEDIA_REPORT_EVENT,
|
MEDIA_REPORT_EVENT,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "StorageHandleState.h"
|
#include "StorageHandleState.h"
|
||||||
#include "TestMissionState.h"
|
#include "TestMissionState.h"
|
||||||
#include "TopState.h"
|
#include "TopState.h"
|
||||||
|
#include "UpgradeState.h"
|
||||||
bool CreateMissionManagerModule(void)
|
bool CreateMissionManagerModule(void)
|
||||||
{
|
{
|
||||||
auto instance = std::make_shared<IMissionManager>();
|
auto instance = std::make_shared<IMissionManager>();
|
||||||
|
@ -76,3 +77,8 @@ std::shared_ptr<State> MissionManagerMakePtr::CreateSdCardHandleState(void)
|
||||||
std::shared_ptr<State> state = std::make_shared<SdCardHandleState>();
|
std::shared_ptr<State> state = std::make_shared<SdCardHandleState>();
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
std::shared_ptr<State> MissionManagerMakePtr::CreateUpgradeState(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<State> state = std::make_shared<UpgradeState>();
|
||||||
|
return state;
|
||||||
|
}
|
|
@ -30,5 +30,6 @@ public:
|
||||||
virtual std::shared_ptr<State> CreateMissionState(const IpcMission &mission);
|
virtual std::shared_ptr<State> CreateMissionState(const IpcMission &mission);
|
||||||
virtual std::shared_ptr<State> CreateStorageHandleState(void);
|
virtual std::shared_ptr<State> CreateStorageHandleState(void);
|
||||||
virtual std::shared_ptr<State> CreateSdCardHandleState(void);
|
virtual std::shared_ptr<State> CreateSdCardHandleState(void);
|
||||||
|
virtual std::shared_ptr<State> CreateUpgradeState(void);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -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::MEDIA_REPORT_EVENT] = std::bind(&MissionState::MediaReportHandle, this, _1);
|
||||||
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||||
std::bind(&MissionState::SdCardEventReportHandle, this, _1);
|
std::bind(&MissionState::SdCardEventReportHandle, this, _1);
|
||||||
|
mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&MissionState::CheckUpgradeFileHandle, this, _1);
|
||||||
}
|
}
|
||||||
void MissionState::GoInState()
|
void MissionState::GoInState()
|
||||||
{
|
{
|
||||||
|
@ -46,3 +47,9 @@ bool MissionState::SdCardEventReportHandle(VStateMachineData *msg)
|
||||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
|
bool MissionState::CheckUpgradeFileHandle(VStateMachineData *msg)
|
||||||
|
{
|
||||||
|
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||||
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::UPGRADE_STATE);
|
||||||
|
return EXECUTED;
|
||||||
|
}
|
|
@ -28,5 +28,6 @@ public:
|
||||||
private:
|
private:
|
||||||
bool MediaReportHandle(VStateMachineData *msg);
|
bool MediaReportHandle(VStateMachineData *msg);
|
||||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||||
|
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -91,12 +91,15 @@ void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||||
mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission);
|
mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission);
|
||||||
mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState();
|
mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState();
|
||||||
mStateTree[SystemState::SD_CARD_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateSdCardHandleState();
|
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::TOP_STATE].get(), nullptr);
|
||||||
mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get());
|
mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get());
|
||||||
mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(),
|
mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(),
|
||||||
mStateTree[SystemState::MISSION_STATE].get());
|
mStateTree[SystemState::MISSION_STATE].get());
|
||||||
mStateMachine->StatePlus(mStateTree[SystemState::SD_CARD_HANDLE_STATE].get(),
|
mStateMachine->StatePlus(mStateTree[SystemState::SD_CARD_HANDLE_STATE].get(),
|
||||||
mStateTree[SystemState::STORAGE_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->SetCurrentState(mStateTree[SystemState::TOP_STATE].get());
|
||||||
mStateMachine->StartStateMachine();
|
mStateMachine->StartStateMachine();
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,6 +28,7 @@ enum class SystemState
|
||||||
MISSION_STATE,
|
MISSION_STATE,
|
||||||
STORAGE_HANDLE_STATE,
|
STORAGE_HANDLE_STATE,
|
||||||
SD_CARD_HANDLE_STATE,
|
SD_CARD_HANDLE_STATE,
|
||||||
|
UPGRADE_STATE,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
class MissionStateMachine
|
class MissionStateMachine
|
||||||
|
|
|
@ -77,5 +77,10 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
|
||||||
mFileNeedToSave.reset();
|
mFileNeedToSave.reset();
|
||||||
}
|
}
|
||||||
mSdCardStatus = data->mData;
|
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;
|
return EXECUTED;
|
||||||
}
|
}
|
|
@ -15,10 +15,10 @@
|
||||||
#ifndef SD_CARD_HANDLE_STATE_H
|
#ifndef SD_CARD_HANDLE_STATE_H
|
||||||
#define SD_CARD_HANDLE_STATE_H
|
#define SD_CARD_HANDLE_STATE_H
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IFilesManager.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
#include "IStorageManager.h"
|
#include "IStorageManager.h"
|
||||||
#include "IFilesManager.h"
|
|
||||||
class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this<SdCardHandleState>
|
class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this<SdCardHandleState>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -28,7 +28,7 @@ public:
|
||||||
void GoOutState() override;
|
void GoOutState() override;
|
||||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool MediaReportHandle(VStateMachineData *msg);
|
bool MediaReportHandle(VStateMachineData *msg);
|
||||||
bool SdCardEventHandle(VStateMachineData *msg);
|
bool SdCardEventHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
|
|
40
application/MissionManager/src/UpgradeState.cpp
Normal file
40
application/MissionManager/src/UpgradeState.cpp
Normal 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;
|
||||||
|
}
|
32
application/MissionManager/src/UpgradeState.h
Normal file
32
application/MissionManager/src/UpgradeState.h
Normal 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
|
|
@ -78,3 +78,11 @@ set(APP_MANAGER_TCP_SERVER_PORT "9876")
|
||||||
set(SD_CARD_DEV "/dev/test")
|
set(SD_CARD_DEV "/dev/test")
|
||||||
set(SD_CARD_MOUNT_PATH "./sdcard")
|
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 ------------ #
|
|
@ -123,7 +123,7 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
||||||
LogInfo("SdCardHalStatus changed: %s.\n", PrintfStatusString(status));
|
LogInfo("SdCardHalStatus changed: %s.\n", PrintfStatusString(status));
|
||||||
SdCardHalStatus mountedStatus = SdCardHalStatus::END;
|
SdCardHalStatus mountedStatus = SdCardHalStatus::END;
|
||||||
if (SdCardHalStatus::INSERTED == status) {
|
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;
|
constexpr int BUF_LENGTH = 128;
|
||||||
char cmd[BUF_LENGTH] = {0};
|
char cmd[BUF_LENGTH] = {0};
|
||||||
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||||
|
include(${HAL_SOURCE_PATH}/build/hal.cmake)
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||||
|
|
||||||
|
@ -14,12 +15,14 @@ include_directories(
|
||||||
#link_directories(
|
#link_directories(
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
add_definitions(-DAPPLICATION_CHECK_PATH=\"${APPLICATION_CHECK_PATH}\")
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME HuntingUpgrade)
|
set(TARGET_NAME HuntingUpgrade)
|
||||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
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")
|
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
29
middleware/HuntingUpgrade/include/IHuntingUpgrade.h
Normal file
29
middleware/HuntingUpgrade/include/IHuntingUpgrade.h
Normal 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
|
|
@ -12,8 +12,19 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "HuntingUpgrade.h"
|
#include "HuntingUpgradeImpl.h"
|
||||||
StatusCode HuntingUpgrade::CheckFileHeader(const UpgradeFileHeader &head)
|
#include "ILog.h"
|
||||||
|
StatusCode HuntingUpgradeImpl::CheckFileHeader(const UpgradeFileHeader &head)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
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;
|
||||||
|
}
|
|
@ -16,11 +16,14 @@
|
||||||
#define HUNTING_UPGRADE_H
|
#define HUNTING_UPGRADE_H
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include "UpgradeBase.h"
|
#include "UpgradeBase.h"
|
||||||
class HuntingUpgrade : public UpgradeBase
|
#include "IHuntingUpgrade.h"
|
||||||
|
#include <memory>
|
||||||
|
class HuntingUpgradeImpl : public UpgradeBase, public IHuntingUpgrade
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HuntingUpgrade() = default;
|
HuntingUpgradeImpl() = default;
|
||||||
virtual ~HuntingUpgrade() = default;
|
virtual ~HuntingUpgradeImpl() = default;
|
||||||
StatusCode CheckFileHeader(const UpgradeFileHeader &head) override;
|
StatusCode CheckFileHeader(const UpgradeFileHeader &head) override;
|
||||||
|
StatusCode CheckUpgradeFile(void) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
55
middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.cpp
Normal file
55
middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.cpp
Normal 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);
|
||||||
|
}
|
28
middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.h
Normal file
28
middleware/HuntingUpgrade/src/HuntingUpgradeMakePtr.h
Normal 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
|
34
middleware/HuntingUpgrade/src/IHuntingUpgrade.cpp
Normal file
34
middleware/HuntingUpgrade/src/IHuntingUpgrade.cpp
Normal 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);
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ endif()
|
||||||
|
|
||||||
set(TARGET_NAME HuntingCameraTest)
|
set(TARGET_NAME HuntingCameraTest)
|
||||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
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")
|
if(${TEST_COVERAGE} MATCHES "true")
|
||||||
target_link_libraries(${TARGET_NAME} gcov)
|
target_link_libraries(${TARGET_NAME} gcov)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -30,6 +30,7 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
||||||
{
|
{
|
||||||
SetAllCamerasResult(mAllCamerasMock);
|
SetAllCamerasResult(mAllCamerasMock);
|
||||||
MockReportCameraEvent("/tmp/test.MP4", CameraType::MAIN_CAMERA);
|
MockReportCameraEvent("/tmp/test.MP4", CameraType::MAIN_CAMERA);
|
||||||
|
CreateUpgradeFile();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
// McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
// McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||||
MainThread::GetInstance()->Init();
|
MainThread::GetInstance()->Init();
|
||||||
|
@ -37,6 +38,5 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
// MockAppPlayback();
|
// MockAppPlayback();
|
||||||
MainThread::GetInstance()->Runing();
|
MainThread::GetInstance()->Runing();
|
||||||
MainThread::GetInstance()->UnInit();
|
|
||||||
}
|
}
|
||||||
} // namespace MediaManager_Mock_Test
|
} // namespace MediaManager_Mock_Test
|
|
@ -1,18 +1,23 @@
|
||||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||||
|
include(${HAL_SOURCE_PATH}/build/hal.cmake)
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
./src
|
./src
|
||||||
./include
|
./include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
|
||||||
${APPLICATION_SOURCE_PATH}/MissionManager/include
|
${APPLICATION_SOURCE_PATH}/MissionManager/include
|
||||||
${APPLICATION_SOURCE_PATH}/MissionManager/src
|
${APPLICATION_SOURCE_PATH}/MissionManager/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/MediaManager/include
|
${MIDDLEWARE_SOURCE_PATH}/MediaManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/StateMachine/include
|
${MIDDLEWARE_SOURCE_PATH}/StateMachine/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/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}
|
||||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/include
|
${TEST_SOURCE_PATH}/middleware/AppManager/tool/include
|
||||||
${TEST_SOURCE_PATH}/middleware/AppManager/tool/src
|
${TEST_SOURCE_PATH}/middleware/AppManager/tool/src
|
||||||
|
@ -25,6 +30,8 @@ include_directories(
|
||||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
# ${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)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET MissionManagerTestTool)
|
set(TEST_TOOL_TARGET MissionManagerTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
|
|
|
@ -25,15 +25,10 @@ public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
// void MissionManagerMockInit(std::shared_ptr<IMissionManager> &vMock);
|
void CreateUpgradeFile(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<IMissionManager> mMissionManagerMock;
|
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
|
#endif
|
|
@ -13,20 +13,21 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "MissionManagerTestTool.h"
|
#include "MissionManagerTestTool.h"
|
||||||
|
#include "LinuxApi.h"
|
||||||
#include "MissionManagerMakePtrTest.h"
|
#include "MissionManagerMakePtrTest.h"
|
||||||
#include "MissionManagerMock.h"
|
#include "MissionManagerMock.h"
|
||||||
void MissionManagerTestTool::Init(void)
|
void MissionManagerTestTool::Init(void)
|
||||||
{
|
{
|
||||||
// ServersMock::GetInstance()->Init();
|
|
||||||
mMissionManagerMock = std::make_shared<MissionManagerMock>();
|
mMissionManagerMock = std::make_shared<MissionManagerMock>();
|
||||||
// MissionManagerMockInit(mMissionManagerMock);
|
|
||||||
std::shared_ptr<MissionManagerMock> mock = std::dynamic_pointer_cast<MissionManagerMock>(mMissionManagerMock);
|
std::shared_ptr<MissionManagerMock> mock = std::dynamic_pointer_cast<MissionManagerMock>(mMissionManagerMock);
|
||||||
OverrideMissionManagerMakePtrObject(mock);
|
OverrideMissionManagerMakePtrObject(mock);
|
||||||
}
|
}
|
||||||
void MissionManagerTestTool::UnInit(void)
|
void MissionManagerTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
// ServersMock::GetInstance()->UnInit();
|
|
||||||
mMissionManagerMock.reset();
|
mMissionManagerMock.reset();
|
||||||
// mAppMonitorMock.reset();
|
|
||||||
CancelOverrideMissionManagerMakePtrObject();
|
CancelOverrideMissionManagerMakePtrObject();
|
||||||
}
|
}
|
||||||
|
void MissionManagerTestTool::CreateUpgradeFile(void)
|
||||||
|
{
|
||||||
|
fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -22,22 +22,6 @@ class TopStateTest : public TopState, virtual public MediaMonitorTrace
|
||||||
public:
|
public:
|
||||||
TopStateTest() = default;
|
TopStateTest() = default;
|
||||||
virtual ~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<AppGetStorageInfo> ¶m) override;
|
|
||||||
// StatusCode GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶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:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,19 +24,24 @@ typedef struct __attribute__((packed)) upgrade_file_header
|
||||||
unsigned char upgradeType[1];
|
unsigned char upgradeType[1];
|
||||||
unsigned char reserved[17];
|
unsigned char reserved[17];
|
||||||
} UpgradeFileHeader;
|
} UpgradeFileHeader;
|
||||||
|
enum class UpgradeType
|
||||||
|
{
|
||||||
|
APPLICATION_ONLY = 0,
|
||||||
|
END
|
||||||
|
};
|
||||||
class UpgradeBase
|
class UpgradeBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UpgradeBase() = default;
|
UpgradeBase() = default;
|
||||||
virtual ~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.
|
* @brief Verify if the file belongs to the upgrade file.
|
||||||
*
|
*
|
||||||
* @param fileName The file name being verified. Enter the parameter using an absolute path.
|
* @param fileName The file name being verified. Enter the parameter using an absolute path.
|
||||||
* @return StatusCode
|
* @return StatusCode
|
||||||
*/
|
*/
|
||||||
StatusCode CheckUpgradeFile(const char *fileName);
|
StatusCode CheckUpgradeFile(const char *fileName, UpgradeFileHeader &header);
|
||||||
StatusCode MoveUpgradeFile(const char *sourceFile, const char *targetFile);
|
StatusCode MoveUpgradeFile(const char *sourceFile, const char *targetFile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,24 +18,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
StatusCode UpgradeBase::CheckUpgradeFile(const char *fileName)
|
StatusCode UpgradeBase::CheckUpgradeFile(const char *fileName, UpgradeFileHeader &header)
|
||||||
{
|
{
|
||||||
FILE *file = nullptr;
|
FILE *file = nullptr;
|
||||||
UpgradeFileHeader fileHead;
|
|
||||||
|
|
||||||
file = fopen(fileName, "rb");
|
file = fopen(fileName, "rb");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Error opening file");
|
LogError("Error opening file:%s\n", fileName);
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
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) {
|
if (bytesRead != 1) {
|
||||||
perror("Error reading file header");
|
LogError("Error reading file header\n");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
return CheckFileHeader(fileHead);
|
return CheckFileHeader(header);
|
||||||
}
|
}
|
||||||
StatusCode UpgradeBase::MoveUpgradeFile(const char *sourceFile, const char *targetFile)
|
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");
|
inputFile = fopen(sourceFile, "rb");
|
||||||
if (inputFile == NULL) {
|
if (inputFile == NULL) {
|
||||||
perror("Error opening input file");
|
LogError("Error opening input file\n");
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFile = fopen(targetFile, "wb");
|
outputFile = fopen(targetFile, "wb");
|
||||||
if (outputFile == NULL) {
|
if (outputFile == NULL) {
|
||||||
perror("Error opening output file");
|
LogError("Error opening output file\n");
|
||||||
fclose(inputFile);
|
fclose(inputFile);
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesRead = fread(&fileHeader, 1, headerSize, inputFile);
|
bytesRead = fread(&fileHeader, 1, headerSize, inputFile);
|
||||||
if (bytesRead != headerSize) {
|
if (bytesRead != headerSize) {
|
||||||
perror("Error reading file header");
|
LogError("Error reading file header\n");
|
||||||
fclose(inputFile);
|
fclose(inputFile);
|
||||||
fclose(outputFile);
|
fclose(outputFile);
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
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) {
|
while ((bytesRead = fread(buffer, 1, sizeof(buffer), inputFile)) > 0) {
|
||||||
fwrite(buffer, 1, bytesRead, outputFile);
|
fwrite(buffer, 1, bytesRead, outputFile);
|
||||||
if (ferror(inputFile) || ferror(outputFile)) {
|
if (ferror(inputFile) || ferror(outputFile)) {
|
||||||
perror("Error reading or writing file");
|
LogError("Error reading or writing file\n");
|
||||||
fclose(inputFile);
|
fclose(inputFile);
|
||||||
fclose(outputFile);
|
fclose(outputFile);
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user