mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Compile ok.
This commit is contained in:
commit
543641f11b
|
@ -12,6 +12,12 @@ set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTOR
|
|||
message("platform = ${TARGET_PLATFORM}")
|
||||
message("platform PATH = ${PLATFORM_PATH}")
|
||||
|
||||
add_custom_target(
|
||||
sdk_clean
|
||||
COMMAND echo "sdk clean finished."
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
|
||||
# Gdb debug
|
||||
include(build/sdk_config.cmake)
|
||||
|
||||
|
@ -166,22 +172,6 @@ set(TEST_LINUX_MOCK "" CACHE STRING INTERNAL)
|
|||
# if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
set(TEST_LINK_LIB "testUtils" CACHE STRING INTERNAL FORCE)
|
||||
# endif()
|
||||
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||
# set(TEST_LINUX_MOCK "-Wl,--wrap=fopen,--wrap=fprintf_gpio,--wrap=fprintf_dir" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=tcgetattr" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=tcsetattr" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=gethostbyname" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=connect" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=socket" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=select" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_open" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_read" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_write" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_close" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_fclose" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_fread" CACHE STRING INTERNAL FORCE)
|
||||
# set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=linux_fcntl" CACHE STRING INTERNAL FORCE)
|
||||
endif()
|
||||
|
||||
# 添加编译目录
|
||||
add_subdirectory(external)
|
||||
|
|
36
README.md
36
README.md
|
@ -1,16 +1,8 @@
|
|||
<<<<<<< HEAD
|
||||
# 1. 一个嵌入式软件架构的示例
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
  从嵌入式软件角度来描述软件架构开发方法。
|
||||
=======
|
||||
# 1. 一个嵌入式软件架构的示例。
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
   从嵌入式软件角度来描述软件架构开发方法。
|
||||
>>>>>>> embedded-framework/master
|
||||
|
||||
欢迎在仓库里面提issue交流学习。
|
||||
|
||||
|
@ -30,7 +22,6 @@ title 嵌入式软件开发
|
|||
"工具使用" : 5
|
||||
```
|
||||
|
||||
<<<<<<< HEAD
|
||||
  本仓库从上述全方面来部署一个嵌入式软件开发项目。各部分环环相扣不分彼此,组成一个完整的健康的敏捷的可持续的嵌入式开发体系。
|
||||
|
||||
### 1.2.1. 源码构建
|
||||
|
@ -44,21 +35,6 @@ title 嵌入式软件开发
|
|||
  通俗来讲,CMakeList.txt脚本就是告诉编译器,从哪里搜索头文件 / 把哪些源代码编译 / 从哪里找到哪些链接库 /输出什么文件到哪个目录。
|
||||
|
||||
```code
|
||||
=======
|
||||
   本仓库从上述全方面来部署一个嵌入式软件开发项目。各部分环环相扣不分彼此,组成一个完整的健康的敏捷的可持续的嵌入式开发体系。
|
||||
|
||||
### 1.2.1. 源码构建
|
||||
|
||||
   源码构建是一个嵌入式软件项目的开始,属于嵌入式软件开发的最基础要素,他决定了开发者使用何种方式何种工具来部署 / 编译项目源码。源码构建方案设计会直接影响到开发效率。
|
||||
|
||||
   源码构建的工具很多,嵌入式开发中常见的有Makefile / CMake / Scons / GN等,例如:国内比较热门的开源项目鸿蒙系统,使用GN作为构建工具。由于历史原因,Makefile是相对古老的源码构建工具,大部分开源项目使用的都是Makefile,随着发展,部分开源项目开始增加使用CMake构建脚本,此时开源项目同时支持Makefile和CMake两种构建方案。构建工具的选择没有好坏之分,大部分后开发的工具都会针对性解决前者的一些缺陷,往往后来者会有更多的优点。本仓库自研部分使用的是CMake工具进行源码构建。
|
||||
|
||||
**一个CMakeList.txt脚本示例**
|
||||
|
||||
   通俗来讲,CMakeList.txt脚本就是告诉编译器,从哪里搜索头文件 / 把哪些源代码编译 / 从哪里找到哪些链接库 /输出什么文件到哪个目录。
|
||||
|
||||
```
|
||||
>>>>>>> embedded-framework/master
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) // 一个配置文件
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) // 设置可执行文件的输出目录
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) // 设置库的输出目录
|
||||
|
@ -111,12 +87,8 @@ endif()
|
|||
|
||||
  在编译的时候,使用clang-tidy工具针对性选择对自研部分的代码进行静态检测。
|
||||
示例:
|
||||
<<<<<<< HEAD
|
||||
|
||||
```code
|
||||
=======
|
||||
```
|
||||
>>>>>>> embedded-framework/master
|
||||
add_custom_target(
|
||||
SharedData_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
|
@ -134,12 +106,8 @@ add_custom_target(
|
|||
|
||||
  在编译的时候,使用clang-format工具针对性选择对自研部分的代码进行自动格式化,实现编码格式的客观绝对统一。
|
||||
示例:
|
||||
<<<<<<< HEAD
|
||||
|
||||
```code
|
||||
=======
|
||||
```
|
||||
>>>>>>> embedded-framework/master
|
||||
add_custom_target(
|
||||
SharedData_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
|
@ -151,8 +119,4 @@ add_custom_target(
|
|||
|
||||
### 1.2.2. 架构设计
|
||||
|
||||
<<<<<<< HEAD
|
||||
  抛开产品业务不进行描述,代码部署主要使用分层模块化的代码结构,结合面向对象的多态设计模式进行代码开发,使得业务代码在部署时具备灵活多变的特性,进一步提高代码的复用性,最终实现产品业务软件层面的敏捷迭代。
|
||||
=======
|
||||
   抛开产品业务不进行描述,代码部署主要使用分层模块化的代码结构,结合面向对象的多态设计模式进行代码开发,使得业务代码在部署时具备灵活多变的特性,进一步提高代码的复用性,最终实现产品业务软件层面的敏捷迭代。
|
||||
>>>>>>> embedded-framework/master
|
||||
|
|
3
application/CMakeLists.txt
Normal file
3
application/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
add_subdirectory(main)
|
||||
add_subdirectory(HuntingCamera)
|
||||
add_subdirectory(MissionManager)
|
73
application/HuntingCamera/CMakeLists.txt
Normal file
73
application/HuntingCamera/CMakeLists.txt
Normal file
|
@ -0,0 +1,73 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
include(${APPLICATION_SOURCE_PATH}/HuntingCamera/build/hunting_camera.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
${HUNTTING_MAIN_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
aux_source_directory(. SRC_FILES)
|
||||
aux_source_directory(./src MAIN_SRC_FILE_THIS)
|
||||
|
||||
# Mark src files for test.
|
||||
# file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c)
|
||||
# set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
set(TARGET_LIB HuntingMainLib)
|
||||
add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS})
|
||||
set(TARGET_NAME HuntingCamera_x86)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_LIB} ${HUNTTING_LINK_LIB})
|
||||
target_link_libraries(${TARGET_NAME} ${TARGET_LIB})
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
HuntingCamera_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${MAIN_SRC_FILE_THIS}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HuntingCamera
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make HuntingCamera_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
HuntingCamera_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${MAIN_SRC_FILE_THIS} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/HuntingCamera
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make HuntingCamera_code_check
|
||||
COMMAND make HuntingCamera_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_LIB})
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES *.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
16
application/HuntingCamera/build/hunting_camera.cmake
Normal file
16
application/HuntingCamera/build/hunting_camera.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
set(HUNTTING_MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/HuntingCamera/src")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${APPLICATION_SOURCE_PATH}/MissionManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/StateMachine/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/McuManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/AppManager/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}/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};${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include")
|
||||
set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/IpcConfig/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 HuntingUpgrade IpcConfig DeviceManager StatusCode Log Hal pthread dl)
|
24
application/HuntingCamera/main.cpp
Normal file
24
application/HuntingCamera/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 "ILog.h"
|
||||
#include "MainThread.h"
|
||||
#include <thread>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
return 0;
|
||||
}
|
132
application/HuntingCamera/src/MainThread.cpp
Normal file
132
application/HuntingCamera/src/MainThread.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include "IAppManager.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "IHalCpp.h"
|
||||
#include "IHuntingUpgrade.h"
|
||||
#include "IIpcConfig.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include <signal.h>
|
||||
#include <thread>
|
||||
static void sigHandler(int signo)
|
||||
{
|
||||
LogInfo("Stop main application.\n");
|
||||
MainThread::GetInstance()->Exit();
|
||||
}
|
||||
void InitSignalHandle(void)
|
||||
{
|
||||
signal(SIGINT, sigHandler);
|
||||
signal(SIGTERM, sigHandler);
|
||||
signal(SIGKILL, sigHandler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
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 MainThread::Init(void)
|
||||
{
|
||||
InitSignalHandle();
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_EASYLOGGING);
|
||||
CustomizationInit();
|
||||
mMainThreadRuning = true;
|
||||
CreateAllModules();
|
||||
IHalCpp::GetInstance()->Init();
|
||||
IDeviceManager::GetInstance()->Init();
|
||||
IMcuManager::GetInstance()->Init();
|
||||
IStorageManager::GetInstance()->Init();
|
||||
IIpcConfig::GetInstance()->Init();
|
||||
IMediaManager::GetInstance()->Init();
|
||||
IMissionManager::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::UnInit(void)
|
||||
{
|
||||
IMissionManager::GetInstance()->UnInit();
|
||||
IMediaManager::GetInstance()->UnInit();
|
||||
IIpcConfig::GetInstance()->UnInit();
|
||||
IStorageManager::GetInstance()->UnInit();
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
IHalCpp::GetInstance()->UnInit();
|
||||
DestoryAllModules();
|
||||
ILogUnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::CreateAllModules(void)
|
||||
{
|
||||
CreateHalCppModule();
|
||||
CreateMcuManager();
|
||||
CreateStorageManagerModule();
|
||||
CreateFilesManagerModule();
|
||||
CreateMissionManagerModule();
|
||||
CreateStateMachine();
|
||||
CreateAppManagerModule();
|
||||
CreateMediaManagerModule();
|
||||
CreateHuntingUpgradeModule();
|
||||
CreateIpcConfigModule();
|
||||
CreateDeviceManagerModule();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
DestroyHuntingUpgradeModule();
|
||||
DestroyMediaManagerModule();
|
||||
DestroyAppManagerModule();
|
||||
DestroyStateMachine();
|
||||
DestroyMissionManagerModule();
|
||||
DestroyFilesManagerModule();
|
||||
DestroyStorageManagerModule();
|
||||
DestroyMcuManager();
|
||||
DestroyHalCppModule();
|
||||
DestroyIpcConfigModule();
|
||||
DestroyDeviceManagerModule();
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
extern bool CreateProtocolHandleImpl(void);
|
||||
void MainThread::CustomizationInit(void)
|
||||
{
|
||||
CreateProtocolHandleImpl();
|
||||
}
|
42
application/HuntingCamera/src/MainThread.h
Normal file
42
application/HuntingCamera/src/MainThread.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 MAIN_THREAD_H
|
||||
#define MAIN_THREAD_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MainThread
|
||||
{
|
||||
public:
|
||||
MainThread();
|
||||
virtual ~MainThread() = default;
|
||||
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *impl = nullptr);
|
||||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void);
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
void DestoryAllModules(void);
|
||||
void ResetAllPtrMaker(void);
|
||||
|
||||
private:
|
||||
bool mMainThreadRuning;
|
||||
};
|
||||
#endif // !MAIN_THREAD_H
|
73
application/MissionManager/CMakeLists.txt
Normal file
73
application/MissionManager/CMakeLists.txt
Normal file
|
@ -0,0 +1,73 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
# include(${UTILS_SOURCE_PATH}/WebServer/build/webserver.cmake)
|
||||
include(${MIDDLEWARE_SOURCE_PATH}/AppManager/build/app_manager.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||
${UTILS_SOURCE_PATH}/LedControl/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/StateMachine/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/AppManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/MediaManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/FilesManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/StorageManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/HuntingUpgrade/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||
)
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
#)
|
||||
|
||||
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 DeviceManager HuntingUpgrade KeyControl LedControl StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
MissionManager_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/MissionManager
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make MissionManager_code_check
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
MissionManager_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/MissionManager
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make MissionManager_code_check
|
||||
COMMAND make MissionManager_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
82
application/MissionManager/README.md
Normal file
82
application/MissionManager/README.md
Normal file
|
@ -0,0 +1,82 @@
|
|||
|
||||
# 1. 相机任务管理
|
||||
|
||||
  相机主业务逻辑使用状态机机制进行管理。
|
||||
|
||||
## 1.1. 任务状态
|
||||
|
||||
  任务状态是指相机启动需要执行的任务,可能是拍照 / 视频,可能是其它任务。
|
||||
|
||||
**例如:**
|
||||
1. 移动物体侦测启动;
|
||||
2. 定时启动拍照 / 录像;
|
||||
3. 测试启动;
|
||||
|
||||
## 1.2. 状态机设计
|
||||
|
||||
### 1.2.1. 状态树设计图
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> TopState
|
||||
TopState --> PowerOff
|
||||
TopState --> MSDCState
|
||||
TopState --> DeviceAbnormal
|
||||
TopState --> MissionState
|
||||
MissionState --> 空闲
|
||||
MissionState --> 存储管理
|
||||
存储管理 --> EMMC
|
||||
存储管理 --> SD卡
|
||||
MissionState --> 媒体管理
|
||||
SD卡 --> 插卡
|
||||
SD卡 --> 拔卡
|
||||
SD卡 --> 卡异常
|
||||
MissionState --> 网络管理
|
||||
网络管理 --> 联网
|
||||
联网 --> 上传文件
|
||||
网络管理 --> 未联网
|
||||
MissionState --> 直播
|
||||
MissionState --> 4G管理
|
||||
4G管理 --> Sim卡初始化
|
||||
4G管理 --> 注网状态
|
||||
MissionState --> Upgrade
|
||||
```
|
||||
|
||||
1. 任意状态处理命令时,不能阻塞,否则整个应用将会瘫痪无法响应任意的命令;
|
||||
2. MissionState: 任务状态,在此状态下,由任务状态处理各种逻辑命令,根据逻辑命令定义,切换到相应的状态再处理数据,处理完数据会停留在当前状态,等待新的命令;
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## 1.4. MCU监视器
|
||||
|
||||
  MCU监视器必须由其中一个状态继承,只有状态机运行之后才能处理串口命令。
|
63
application/MissionManager/include/IMissionManager.h
Normal file
63
application/MissionManager/include/IMissionManager.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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_MISSION_MANAGER
|
||||
#define I_MISSION_MANAGER
|
||||
#include "StatusCode.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
bool CreateMissionManagerModule(void);
|
||||
bool DestroyMissionManagerModule(void);
|
||||
enum class MissionEvent
|
||||
{
|
||||
TEST = 0,
|
||||
END
|
||||
};
|
||||
class VMissionData
|
||||
{
|
||||
public:
|
||||
VMissionData(const MissionEvent &event) : mEvent(event)
|
||||
{
|
||||
mRetryTimes = 0;
|
||||
mDelayTimeMs = 0;
|
||||
}
|
||||
virtual ~VMissionData() = default;
|
||||
const MissionEvent mEvent;
|
||||
int mRetryTimes;
|
||||
unsigned int mDelayTimeMs;
|
||||
std::function<void(bool, std::shared_ptr<VMissionData>)> mMissionFinshed;
|
||||
};
|
||||
template <typename T>
|
||||
class VMissionDataV2 : public VMissionData
|
||||
{
|
||||
|
||||
public:
|
||||
VMissionDataV2(const MissionEvent &event, T value) : VMissionData(event), mData(value)
|
||||
{
|
||||
}
|
||||
virtual ~VMissionDataV2() = default;
|
||||
|
||||
public:
|
||||
T mData;
|
||||
};
|
||||
class IMissionManager
|
||||
{
|
||||
public:
|
||||
IMissionManager() = default;
|
||||
virtual ~IMissionManager() = default;
|
||||
static std::shared_ptr<IMissionManager> &GetInstance(std::shared_ptr<IMissionManager> *impl = nullptr);
|
||||
virtual const StatusCode Init(void);
|
||||
virtual const StatusCode UnInit(void);
|
||||
};
|
||||
#endif
|
159
application/MissionManager/src/AppMonitor.cpp
Normal file
159
application/MissionManager/src/AppMonitor.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* 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 "AppMonitor.h"
|
||||
#include "ILog.h"
|
||||
#include <vector>
|
||||
StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetProductInfo.\n");
|
||||
param.mModel = "test";
|
||||
param.mCompany = "test";
|
||||
param.mSoc = "test";
|
||||
param.mSp = "test";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetDeviceAttr.\n");
|
||||
param.mUUID = "test";
|
||||
param.mSoftVersion = "test";
|
||||
param.mOtaVersion = "test";
|
||||
param.mHardwareVersion = "test";
|
||||
param.mSSID = "test";
|
||||
param.mBSSID = "test";
|
||||
param.mCameraNumber = "test";
|
||||
param.mCurrentCameraID = "test";
|
||||
param.mWifiReboot = "test";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetMediaInfo(AppGetMediaInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetMediaInfo.\n");
|
||||
param.mRtspUrl = "rtsp://192.168.169.1/live/0";
|
||||
param.mTransport = "tcp";
|
||||
param.mPort = APP_MANAGER_TCP_SERVER_PORT;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetSdCardInfo.\n");
|
||||
SdCardInfo info;
|
||||
IStorageManager::GetInstance()->GetSdCardInfo(info);
|
||||
param.mStatus = SdCardStatusConvert(info.mEvent);
|
||||
param.mFree = info.mFreeSizeMB;
|
||||
param.mTotal = info.mTotalSizeMB;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetBatteryInfo.\n");
|
||||
param.mCapacity = 0;
|
||||
param.mChargeStatus = ChargeStatus::CHARGING;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
param.mMicStatus = SwitchStatus::ON;
|
||||
param.mRec = SwitchStatus::OFF;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetCapability(AppGetCapability ¶m)
|
||||
{
|
||||
param.mPlaybackType = PlaybackType::DOWNLOAD_PLAYBACK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
||||
{
|
||||
param = LockVideoStatus::LOCK;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
||||
{
|
||||
AppGetStorageInfo info;
|
||||
SdCardInfo sdInfo;
|
||||
IStorageManager::GetInstance()->GetSdCardInfo(sdInfo);
|
||||
info.mIndex = 0;
|
||||
info.mName = "TF card 1";
|
||||
info.mType = StorageType::SD_CARD_1;
|
||||
info.mFree = sdInfo.mFreeSizeMB;
|
||||
info.mTotal = sdInfo.mTotalSizeMB;
|
||||
param.push_back(info);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
||||
{
|
||||
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
||||
AppGetFileList file;
|
||||
file.mCreateTime_s = 123456789;
|
||||
file.mDuration = 182;
|
||||
file.mName = "/DCIM/2024/01/15/20240115140207-20240115140509.mp4";
|
||||
file.mSize = 1024 * 182;
|
||||
file.mType = StorageFileType::VIDEO;
|
||||
param.push_back(file);
|
||||
AppGetFileList file2;
|
||||
file2.mCreateTime_s = 123456789;
|
||||
file2.mDuration = 0;
|
||||
file2.mName = "/34a396526922a33e97906920dbfef2a5.jpg";
|
||||
file2.mSize = 1024;
|
||||
file2.mType = StorageFileType::PICTURE;
|
||||
param.push_back(file2);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::EnterRecorder(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::AppPlayback(const PlayBackEvent &event)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
{
|
||||
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageEvent::SD_CARD_INSERT:
|
||||
return SdCardStatus::NORMAL;
|
||||
case StorageEvent::SD_CARD_REMOVE:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
case StorageEvent::SD_ABNORMAL:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
default:
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
45
application/MissionManager/src/AppMonitor.h
Normal file
45
application/MissionManager/src/AppMonitor.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 APP_MONITOR_H
|
||||
#define APP_MONITOR_H
|
||||
#include "IAppManager.h"
|
||||
#include "IStorageManager.h"
|
||||
class AppMonitor : public VAppMonitor
|
||||
{
|
||||
public:
|
||||
AppMonitor() = default;
|
||||
virtual ~AppMonitor() = default;
|
||||
StatusCode GetProductInfo(AppGetProductInfo ¶m) override;
|
||||
StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override;
|
||||
StatusCode GetMediaInfo(AppGetMediaInfo ¶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;
|
||||
StatusCode GetThumbnail(AppGetThumbnail ¶m) override;
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
};
|
||||
#endif
|
75
application/MissionManager/src/DataProcessing.cpp
Normal file
75
application/MissionManager/src/DataProcessing.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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 "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
key_event_data::key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime)
|
||||
: mKeyName(keyName), mKeyEvent(keyEvent), mHoldTime(holdTime)
|
||||
{
|
||||
}
|
||||
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||
{
|
||||
}
|
||||
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
||||
{
|
||||
}
|
||||
DataProcessing::DataProcessing()
|
||||
{
|
||||
mEventHandle[InternalStateEvent::KEY_EVENT_HANDLE] = std::bind(&DataProcessing::KeyEventHandle, this, _1);
|
||||
}
|
||||
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (nullptr == msg) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
std::map<InternalStateEvent, DataProcessingFunc>::iterator iter;
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
||||
iter = mEventHandle.find(event);
|
||||
if (iter != mEventHandle.end()) {
|
||||
return mEventHandle[event](msg);
|
||||
}
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
bool DataProcessing::KeyEventHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (nullptr == msg) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
std::map<std::string, KeyHandleFunc>::iterator iter;
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<KeyEventData>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<KeyEventData>>(message->mMissionData);
|
||||
if (!data) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
iter = mKeyClickHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyClickHandle.end() && KeyEvent::SHORT_CLICK == data->mData.mKeyEvent) {
|
||||
return mKeyClickHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
iter = mKeyHoldDownHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyHoldDownHandle.end() && KeyEvent::HOLD_DOWN == data->mData.mKeyEvent) {
|
||||
return mKeyHoldDownHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
iter = mKeyHoldUpHandle.find(data->mData.mKeyName);
|
||||
if (iter != mKeyHoldUpHandle.end() && KeyEvent::HOLD_UP == data->mData.mKeyEvent) {
|
||||
return mKeyHoldUpHandle[data->mData.mKeyName](data->mData);
|
||||
}
|
||||
return NOT_EXECUTED;
|
||||
}
|
78
application/MissionManager/src/DataProcessing.h
Normal file
78
application/MissionManager/src/DataProcessing.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 DATA_PROCESSING_H
|
||||
#define DATA_PROCESSING_H
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "KeyControl.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
using std::placeholders::_1;
|
||||
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
||||
enum class InternalStateEvent
|
||||
{
|
||||
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
||||
ANY_STATE_SD_STATUS_PERORIED,
|
||||
CHECK_UPGRADE_FILE,
|
||||
MEDIA_REPORT_EVENT,
|
||||
KEY_EVENT_HANDLE,
|
||||
RESET_KEY_MEDIA_TASK,
|
||||
MEDIA_HANDLE_STATE_TASK_TIME_OUT,
|
||||
END
|
||||
};
|
||||
typedef struct key_event_data
|
||||
{
|
||||
key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime);
|
||||
const std::string mKeyName;
|
||||
const KeyEvent mKeyEvent;
|
||||
const unsigned int mHoldTime;
|
||||
} KeyEventData;
|
||||
using KeyHandleFunc = std::function<bool(const KeyEventData &)>;
|
||||
class MissionData : public VStateMachineData
|
||||
{
|
||||
public:
|
||||
MissionData(const std::shared_ptr<VMissionData> &data);
|
||||
virtual ~MissionData() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData;
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* MissionMessage abstracts user data into state machine data, enabling the transfer of arbitrary data within the state
|
||||
* machine.
|
||||
*/
|
||||
class MissionMessage : public VStateMessage
|
||||
{
|
||||
public:
|
||||
MissionMessage(const std::shared_ptr<VMissionData> &message);
|
||||
virtual ~MissionMessage() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData; // The message from users of state manager module.
|
||||
};
|
||||
class DataProcessing
|
||||
{
|
||||
public:
|
||||
DataProcessing();
|
||||
virtual ~DataProcessing() = default;
|
||||
bool EventHandle(VStateMachineData *msg);
|
||||
virtual bool KeyEventHandle(VStateMachineData *msg);
|
||||
|
||||
protected:
|
||||
std::map<InternalStateEvent, DataProcessingFunc> mEventHandle;
|
||||
std::map<std::string, DataProcessingFunc> mKeyEventHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyClickHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyHoldDownHandle;
|
||||
std::map<std::string, KeyHandleFunc> mKeyHoldUpHandle;
|
||||
};
|
||||
#endif
|
38
application/MissionManager/src/IMissionManager.cpp
Normal file
38
application/MissionManager/src/IMissionManager.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 "IMissionManager.h"
|
||||
#include "ILog.h"
|
||||
std::shared_ptr<IMissionManager> &IMissionManager::GetInstance(std::shared_ptr<IMissionManager> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<IMissionManager>();
|
||||
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 IMissionManager::Init(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IMissionManager::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
37
application/MissionManager/src/IdleState.cpp
Normal file
37
application/MissionManager/src/IdleState.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 "IdleState.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
IdleState::IdleState() : State("IdleState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1);
|
||||
// mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
// std::bind(&IdleState::SdCardEventHandle, this, _1);
|
||||
}
|
||||
void IdleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== IdleState::GoInState.\n");
|
||||
}
|
||||
void IdleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== IdleState::GoOutState.\n");
|
||||
}
|
||||
bool IdleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
30
application/MissionManager/src/IdleState.h
Normal file
30
application/MissionManager/src/IdleState.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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 IDLE_STATE_H
|
||||
#define IDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
class IdleState : public State, public DataProcessing, public std::enable_shared_from_this<IdleState>
|
||||
{
|
||||
public:
|
||||
IdleState();
|
||||
virtual ~IdleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
};
|
||||
#endif
|
37
application/MissionManager/src/LedsHandle.cpp
Normal file
37
application/MissionManager/src/LedsHandle.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 "LedsHandle.h"
|
||||
#include "ILog.h"
|
||||
void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime,
|
||||
const unsigned int &blinkPeriod)
|
||||
{
|
||||
switch (status) {
|
||||
case DeviceStatus::NORMAL:
|
||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogWarning("unknow device status.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void inline LedsHandle::DeleteDeviceStatusLed(void)
|
||||
{
|
||||
mDeviceStatus->DeleteState();
|
||||
}
|
||||
void LedsHandle::DeleteAllLeds(void)
|
||||
{
|
||||
DeleteDeviceStatusLed();
|
||||
}
|
46
application/MissionManager/src/LedsHandle.h
Normal file
46
application/MissionManager/src/LedsHandle.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 LEDS_HANDLE_H
|
||||
#define LEDS_HANDLE_H
|
||||
#include "SetLedState.h"
|
||||
enum class DeviceStatus
|
||||
{
|
||||
NORMAL = 0,
|
||||
TAKING_PICTURE_OR_VIDEO,
|
||||
END
|
||||
};
|
||||
class LedsHandle
|
||||
{
|
||||
public:
|
||||
LedsHandle() = default;
|
||||
virtual ~LedsHandle() = default;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief This function is designed as a virtual function so that when the board uses different LED circuits, this
|
||||
* function can be overloaded to achieve polymorphic control of the light.
|
||||
* @param status
|
||||
* @param keepAliveTime
|
||||
* @param blinkPeriod
|
||||
*/
|
||||
virtual void ControlDeviceStatusLed(const DeviceStatus &status, const long int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
void DeleteDeviceStatusLed(void);
|
||||
void DeleteAllLeds(void);
|
||||
|
||||
private:
|
||||
std::shared_ptr<SetLedState> mDeviceStatus;
|
||||
};
|
||||
#endif
|
69
application/MissionManager/src/McuMonitor.cpp
Normal file
69
application/MissionManager/src/McuMonitor.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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 "McuMonitor.h"
|
||||
#include "ILog.h"
|
||||
#include "IMcuManager.h"
|
||||
void McuMonitor::Init(std::shared_ptr<VMcuMonitor> &monitor)
|
||||
{
|
||||
IMcuManager::GetInstance()->SetMcuMonitor(monitor);
|
||||
}
|
||||
void McuMonitor::UnInit(void)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
}
|
||||
void McuMonitor::RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetIntervalStartEvent\n");
|
||||
std::shared_ptr<McuRecv<McuGetIntervalStart>> recvData =
|
||||
std::dynamic_pointer_cast<McuRecv<McuGetIntervalStart>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mHour = 10;
|
||||
recvData->mDataRecvReply.mMin = 10;
|
||||
recvData->mDataRecvReply.mSecond = 10;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
||||
void McuMonitor::RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetDateTime\n");
|
||||
std::shared_ptr<McuRecv<McuReplyDateTime>> recvData = std::dynamic_pointer_cast<McuRecv<McuReplyDateTime>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mYear = 2024;
|
||||
recvData->mDataRecvReply.mMon = 10;
|
||||
recvData->mDataRecvReply.mDay = 10;
|
||||
recvData->mDataRecvReply.mHour = 10;
|
||||
recvData->mDataRecvReply.mMin = 10;
|
||||
recvData->mDataRecvReply.mSecond = 10;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
||||
void McuMonitor::RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv)
|
||||
{
|
||||
LogInfo("RecvGetPirSensitivity\n");
|
||||
std::shared_ptr<McuRecv<McuGetPirSensitivity>> recvData =
|
||||
std::dynamic_pointer_cast<McuRecv<McuGetPirSensitivity>>(recv);
|
||||
if (recvData) {
|
||||
recvData->mDataRecvReply.mSensitivity = 9;
|
||||
recv->ReplyFinished(true);
|
||||
}
|
||||
recv->ReplyFinished(false);
|
||||
}
|
31
application/MissionManager/src/McuMonitor.h
Normal file
31
application/MissionManager/src/McuMonitor.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 MCU_MONITOR_H
|
||||
#define MCU_MONITOR_H
|
||||
#include "IMcuManager.h"
|
||||
class McuMonitor : public VMcuMonitor
|
||||
{
|
||||
public:
|
||||
McuMonitor() = default;
|
||||
virtual ~McuMonitor() = default;
|
||||
void Init(std::shared_ptr<VMcuMonitor> &monitor);
|
||||
void UnInit(void);
|
||||
void RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission) override;
|
||||
void RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
void RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv) override;
|
||||
};
|
||||
#endif
|
47
application/MissionManager/src/MediaHandleState.cpp
Normal file
47
application/MissionManager/src/MediaHandleState.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 "MediaHandleState.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
MediaHandleState::MediaHandleState() : State("MediaHandleState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] =
|
||||
std::bind(&MediaHandleState::ResetKeyMediaTaskHandle, this, _1);
|
||||
}
|
||||
void MediaHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== MediaHandleState::GoInState.\n");
|
||||
if (!mMediaHandle) {
|
||||
MediaTaskHandle::Init();
|
||||
}
|
||||
}
|
||||
void MediaHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== MediaHandleState::GoOutState.\n");
|
||||
}
|
||||
bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
void MediaHandleState::TaskResponse(const std::vector<MediaTaskResponse> &response)
|
||||
{
|
||||
}
|
||||
bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||
{
|
||||
MakeSingleTask(InternalStateEvent::RESET_KEY_MEDIA_TASK, shared_from_this());
|
||||
return EXECUTED;
|
||||
}
|
37
application/MissionManager/src/MediaHandleState.h
Normal file
37
application/MissionManager/src/MediaHandleState.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 MEDIA_HANDLE_STATE_H
|
||||
#define MEDIA_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "MediaTaskHandle.h"
|
||||
class MediaHandleState : public State,
|
||||
public DataProcessing,
|
||||
public MediaTaskHandle,
|
||||
public VMediaTaskIniator,
|
||||
public std::enable_shared_from_this<MediaHandleState>
|
||||
{
|
||||
public:
|
||||
MediaHandleState();
|
||||
virtual ~MediaHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
void TaskResponse(const std::vector<MediaTaskResponse> &response) override;
|
||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
25
application/MissionManager/src/MediaTask.cpp
Normal file
25
application/MissionManager/src/MediaTask.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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 "MediaTask.h"
|
||||
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||
const std::weak_ptr<VMediaTaskIniator> &iniator)
|
||||
: mType(type), mBindEvent(bindEvent), mIniator(iniator)
|
||||
{
|
||||
mResponseData.reset();
|
||||
}
|
||||
unsigned int MediaTask::GetTaskTimeOutMs(void)
|
||||
{
|
||||
return MEDIA_TASK_TIMEOUT_MS;
|
||||
}
|
42
application/MissionManager/src/MediaTask.h
Normal file
42
application/MissionManager/src/MediaTask.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 MEDIA_TASK_H
|
||||
#define MEDIA_TASK_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
constexpr unsigned int MEDIA_TASK_TIMEOUT_MS = 1000 * 60;
|
||||
class VMediaTaskIniator
|
||||
{
|
||||
public:
|
||||
VMediaTaskIniator() = default;
|
||||
virtual ~VMediaTaskIniator() = default;
|
||||
virtual void TaskResponse(const std::vector<MediaTaskResponse> &response) = 0;
|
||||
};
|
||||
class MediaTask : public VMediaTask
|
||||
{
|
||||
public:
|
||||
MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||
const std::weak_ptr<VMediaTaskIniator> &iniator);
|
||||
virtual ~MediaTask() = default;
|
||||
virtual unsigned int GetTaskTimeOutMs(void);
|
||||
|
||||
private:
|
||||
const MediaTaskType mType;
|
||||
const InternalStateEvent mBindEvent;
|
||||
const std::weak_ptr<VMediaTaskIniator> mIniator;
|
||||
bool mFinished = false;
|
||||
std::shared_ptr<MediaTaskResponse> mResponseData;
|
||||
};
|
||||
#endif
|
51
application/MissionManager/src/MediaTaskHandle.cpp
Normal file
51
application/MissionManager/src/MediaTaskHandle.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "MediaTaskHandle.h"
|
||||
#include "ILog.h"
|
||||
#include "MissionStateMachine.h"
|
||||
MediaTaskHandle::MediaTaskHandle()
|
||||
{
|
||||
mMediaHandle.reset();
|
||||
// mMediaHandle = std::make_shared<VMediaHandle>();
|
||||
}
|
||||
void MediaTaskHandle::Init(void)
|
||||
{
|
||||
IMediaManager::GetInstance()->GetMediaChannel(MediaChannel::MEDIA_1, mMediaHandle);
|
||||
}
|
||||
void MediaTaskHandle::UnInit(void)
|
||||
{
|
||||
mMediaHandle->ClearTask();
|
||||
mMediaHandle.reset();
|
||||
}
|
||||
void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
||||
const std::shared_ptr<VMediaTaskIniator> &iniator)
|
||||
{
|
||||
std::shared_ptr<VMediaTask> task = std::make_shared<MediaTask>(MediaTaskType::END, bindEvent, iniator);
|
||||
if (!mMediaHandle) {
|
||||
LogError("MediaHandle is null");
|
||||
return;
|
||||
}
|
||||
auto code = mMediaHandle->ExecuteTask(task);
|
||||
if (IsCodeOK(code)) {
|
||||
mRuningTask = task;
|
||||
long long timeOut = std::dynamic_pointer_cast<MediaTask>(task)->GetTaskTimeOutMs();
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionData>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_HANDLE_STATE_TASK_TIME_OUT));
|
||||
MissionStateMachine::GetInstance()->MessageExecutedLater(message, timeOut);
|
||||
}
|
||||
// else if () {
|
||||
// mMediaHandle->StopTask();
|
||||
// }
|
||||
}
|
35
application/MissionManager/src/MediaTaskHandle.h
Normal file
35
application/MissionManager/src/MediaTaskHandle.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 MEDIA_TASK_HANDLE_H
|
||||
#define MEDIA_TASK_HANDLE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MediaTask.h"
|
||||
class MediaTaskHandle
|
||||
{
|
||||
public:
|
||||
MediaTaskHandle();
|
||||
virtual ~MediaTaskHandle() = default;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
void MakeSingleTask(const InternalStateEvent &bindEvent, const std::shared_ptr<VMediaTaskIniator> &iniator);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<VMediaHandle> mMediaHandle;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VMediaTask> mRuningTask;
|
||||
};
|
||||
#endif
|
28
application/MissionManager/src/MissionManager.cpp
Normal file
28
application/MissionManager/src/MissionManager.cpp
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.
|
||||
*/
|
||||
#include "MissionManager.h"
|
||||
#include "IAppManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
const StatusCode MissionManager::Init(void)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode MissionManager::UnInit(void)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->UnInit();
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
26
application/MissionManager/src/MissionManager.h
Normal file
26
application/MissionManager/src/MissionManager.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MISSION_MANAGER_H
|
||||
#define MISSION_MANAGER_H
|
||||
#include "IMissionManager.h"
|
||||
class MissionManager : public IMissionManager
|
||||
{
|
||||
public:
|
||||
MissionManager() = default;
|
||||
virtual ~MissionManager() = default;
|
||||
const StatusCode Init(void) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
};
|
||||
#endif
|
118
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
118
application/MissionManager/src/MissionManagerMakePtr.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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 "MissionManagerMakePtr.h"
|
||||
#include "ILog.h"
|
||||
#include "IdleState.h"
|
||||
#include "MediaHandleState.h"
|
||||
#include "MissionManager.h"
|
||||
#include "OnMissionState.h"
|
||||
#include "PirTriggeredMissionState.h"
|
||||
#include "SdCardHandleState.h"
|
||||
#include "StorageHandleState.h"
|
||||
#include "TestMissionState.h"
|
||||
#include "TopState.h"
|
||||
#include "UpgradeState.h"
|
||||
bool CreateMissionManagerModule(void)
|
||||
{
|
||||
auto instance = std::make_shared<IMissionManager>();
|
||||
StatusCode code = MissionManagerMakePtr::GetInstance()->CreateMissionManagerInstance(instance);
|
||||
if (IsCodeOK(code)) {
|
||||
LogInfo("CreateMcuManager is ok.\n");
|
||||
IMissionManager::GetInstance(&instance);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool DestroyMissionManagerModule(void)
|
||||
{
|
||||
auto instance = std::make_shared<IMissionManager>();
|
||||
IMissionManager::GetInstance(&instance);
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<MissionManagerMakePtr> &MissionManagerMakePtr::GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MissionManagerMakePtr>();
|
||||
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 MissionManagerMakePtr::CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance)
|
||||
{
|
||||
instance = std::make_shared<MissionManager>();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateTopState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<TopState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateMissionState(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("MissionManagerMakePtr::CreateMissionState\n");
|
||||
std::shared_ptr<State> state;
|
||||
switch (mission) {
|
||||
case IpcMission::PIR_TRIGGERED:
|
||||
LogInfo("Create PirTriggeredMissionState.\n");
|
||||
state = std::make_shared<PirTriggeredMissionState>();
|
||||
break;
|
||||
case IpcMission::TEST:
|
||||
LogInfo("Create TestMissionState.\n");
|
||||
state = std::make_shared<TestMissionState>();
|
||||
break;
|
||||
case IpcMission::ON:
|
||||
LogInfo("Create OnMissionState.\n");
|
||||
state = std::make_shared<OnMissionState>();
|
||||
break;
|
||||
|
||||
default:
|
||||
LogWarning("Unknown mission.\n");
|
||||
state = std::make_shared<TestMissionState>();
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateStorageHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<StorageHandleState>();
|
||||
// std::dynamic_pointer_cast<StorageHandleState>(state)->Init();
|
||||
return state;
|
||||
}
|
||||
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;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateMediaHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<MediaHandleState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateIdleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<IdleState>();
|
||||
return state;
|
||||
}
|
37
application/MissionManager/src/MissionManagerMakePtr.h
Normal file
37
application/MissionManager/src/MissionManagerMakePtr.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 MISSION_MANAGER_MAKE_PTR_H
|
||||
#define MISSION_MANAGER_MAKE_PTR_H
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MissionManagerMakePtr
|
||||
{
|
||||
public:
|
||||
MissionManagerMakePtr() = default;
|
||||
virtual ~MissionManagerMakePtr() = default;
|
||||
static std::shared_ptr<MissionManagerMakePtr> &GetInstance(std::shared_ptr<MissionManagerMakePtr> *impl = nullptr);
|
||||
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
|
||||
virtual std::shared_ptr<State> CreateTopState(void);
|
||||
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);
|
||||
virtual std::shared_ptr<State> CreateMediaHandleState(void);
|
||||
virtual std::shared_ptr<State> CreateIdleState(void);
|
||||
};
|
||||
#endif
|
56
application/MissionManager/src/MissionState.cpp
Normal file
56
application/MissionManager/src/MissionState.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 "MissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "MissionStateMachine.h"
|
||||
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()
|
||||
{
|
||||
LogInfo(" ========== MissionState::GoInState.\n");
|
||||
}
|
||||
void MissionState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== MissionState::GoOutState.\n");
|
||||
LedsHandle::DeleteAllLeds();
|
||||
}
|
||||
bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool MissionState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
||||
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;
|
||||
}
|
39
application/MissionManager/src/MissionState.h
Normal file
39
application/MissionManager/src/MissionState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 MISSION_STATE_H
|
||||
#define MISSION_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "LedsHandle.h"
|
||||
class MissionState : public State,
|
||||
public DataProcessing,
|
||||
public LedsHandle,
|
||||
public std::enable_shared_from_this<MissionState>
|
||||
{
|
||||
public:
|
||||
MissionState(const std::string &name);
|
||||
virtual ~MissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
protected:
|
||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
124
application/MissionManager/src/MissionStateMachine.cpp
Normal file
124
application/MissionManager/src/MissionStateMachine.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* 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 "MissionStateMachine.h"
|
||||
#include "DataProcessing.h"
|
||||
#include "ILog.h"
|
||||
#include "McuAskBase.h"
|
||||
#include "MissionManagerMakePtr.h"
|
||||
// #include "TopState.h"
|
||||
std::shared_ptr<MissionStateMachine> &MissionStateMachine::GetInstance(std::shared_ptr<MissionStateMachine> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MissionStateMachine>();
|
||||
if (impl) {
|
||||
instance = *impl;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
MissionStateMachine::MissionStateMachine()
|
||||
{
|
||||
mStartMission = IpcMission::END;
|
||||
}
|
||||
void MissionStateMachine::Init(void)
|
||||
{
|
||||
mStateMachine = std::make_shared<VStateMachineHandle>();
|
||||
auto code = IStateMachine::GetInstance()->CreateStateMachine(mStateMachine);
|
||||
if (!IsCodeOK(code)) {
|
||||
LogError("Create state machine failed[%s].\n", code.mPrintStringCode(code));
|
||||
return;
|
||||
}
|
||||
if (!mStateMachine->InitialStateMachine()) {
|
||||
LogError("State machine init failed.\n");
|
||||
return;
|
||||
}
|
||||
mStartMission = GetStartMission();
|
||||
if (mStartMission == IpcMission::END) {
|
||||
LogError("ipcmission error, will start test mode.\n");
|
||||
mStartMission = IpcMission::TEST;
|
||||
}
|
||||
RunStateMachine(mStartMission);
|
||||
}
|
||||
void MissionStateMachine::UnInit(void)
|
||||
{
|
||||
mStateMachine->StopHandlerThread();
|
||||
mStateTree.clear();
|
||||
}
|
||||
StatusCode MissionStateMachine::SendStateMessage(const std::shared_ptr<VMissionData> &message)
|
||||
{
|
||||
std::shared_ptr<VStateMessage> msg = std::make_shared<MissionMessage>(message);
|
||||
mStateMachine->SendMessage(static_cast<int>(message->mEvent), msg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MissionStateMachine::MessageExecutedLater(const std::shared_ptr<VMissionData> &message,
|
||||
long long &delayTimeMs)
|
||||
{
|
||||
std::shared_ptr<VStateMessage> msg = std::make_shared<MissionMessage>(message);
|
||||
mStateMachine->MessageExecutedLater(static_cast<int>(message->mEvent), msg, delayTimeMs);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MissionStateMachine::DelayMessage(VStateMachineData *msg)
|
||||
{
|
||||
mStateMachine->DelayMessage(msg);
|
||||
}
|
||||
void MissionStateMachine::SwitchState(const SystemState &state)
|
||||
{
|
||||
mStateMachine->SwitchState(mStateTree[state].get());
|
||||
}
|
||||
IpcMission MissionStateMachine::GetStartMission(void)
|
||||
{
|
||||
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY)
|
||||
{
|
||||
mDataReply = IpcMission::END;
|
||||
}
|
||||
virtual ~McuAskIpcMission() = default;
|
||||
};
|
||||
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();
|
||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||
return std::dynamic_pointer_cast<McuAskIpcMission>(ask)->mDataReply;
|
||||
}
|
||||
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("Make all states and start the state machine, ipc mission = %s.\n",
|
||||
IMcuManager::GetInstance()->PrintIpcMissionString(mission));
|
||||
mStateTree[SystemState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
||||
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();
|
||||
mStateTree[SystemState::MEDIA_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateMediaHandleState();
|
||||
mStateTree[SystemState::IDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateIdleState();
|
||||
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->StatePlus(mStateTree[SystemState::MEDIA_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::IDLE_STATE].get(), mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->SetCurrentState(mStateTree[SystemState::TOP_STATE].get());
|
||||
mStateMachine->StartStateMachine();
|
||||
/**
|
||||
* @brief The business can only be processed after the state machine is started.
|
||||
*
|
||||
*/
|
||||
std::shared_ptr<VMissionData> message =
|
||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::STORAGE_HANDLE_STATE_INIT));
|
||||
SendStateMessage(message);
|
||||
}
|
58
application/MissionManager/src/MissionStateMachine.h
Normal file
58
application/MissionManager/src/MissionStateMachine.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 MISSION_STATE_MACHINE_H
|
||||
#define MISSION_STATE_MACHINE_H
|
||||
// #include "IDeviceManager.h"
|
||||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <map>
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
enum class SystemState
|
||||
{
|
||||
TOP_STATE = 0,
|
||||
MISSION_STATE,
|
||||
STORAGE_HANDLE_STATE,
|
||||
SD_CARD_HANDLE_STATE,
|
||||
UPGRADE_STATE,
|
||||
MEDIA_HANDLE_STATE,
|
||||
IDLE_STATE,
|
||||
END
|
||||
};
|
||||
class MissionStateMachine
|
||||
{
|
||||
public:
|
||||
MissionStateMachine();
|
||||
virtual ~MissionStateMachine() = default;
|
||||
static std::shared_ptr<MissionStateMachine> &GetInstance(std::shared_ptr<MissionStateMachine> *impl = nullptr);
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
StatusCode SendStateMessage(const std::shared_ptr<VMissionData> &message);
|
||||
StatusCode MessageExecutedLater(const std::shared_ptr<VMissionData> &message, long long &delayTimeMs);
|
||||
void DelayMessage(VStateMachineData *msg);
|
||||
void SwitchState(const SystemState &state);
|
||||
|
||||
private:
|
||||
IpcMission GetStartMission(void);
|
||||
void RunStateMachine(const IpcMission &mission);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||
std::map<SystemState, std::shared_ptr<State>> mStateTree;
|
||||
IpcMission mStartMission;
|
||||
};
|
||||
#endif
|
37
application/MissionManager/src/OnMissionState.cpp
Normal file
37
application/MissionManager/src/OnMissionState.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 "OnMissionState.h"
|
||||
#include "ILog.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
OnMissionState::OnMissionState() : MissionState("OnMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&OnMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void OnMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== OnMissionState::GoInState.\n");
|
||||
}
|
||||
void OnMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== OnMissionState::GoOutState.\n");
|
||||
}
|
||||
bool OnMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
return EXECUTED;
|
||||
}
|
31
application/MissionManager/src/OnMissionState.h
Normal file
31
application/MissionManager/src/OnMissionState.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 ON_MISSION_STATE_H
|
||||
#define ON_MISSION_STATE_H
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class OnMissionState : public MissionState
|
||||
{
|
||||
public:
|
||||
OnMissionState();
|
||||
virtual ~OnMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
37
application/MissionManager/src/PirTrggeredMissionState.cpp
Normal file
37
application/MissionManager/src/PirTrggeredMissionState.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 "PirTriggeredMissionState.h"
|
||||
#include "ILog.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
PirTriggeredMissionState::PirTriggeredMissionState() : MissionState("PirTriggeredMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&PirTriggeredMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void PirTriggeredMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== PirTriggeredMissionState::GoInState.\n");
|
||||
}
|
||||
void PirTriggeredMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== PirTriggeredMissionState::GoOutState.\n");
|
||||
}
|
||||
bool PirTriggeredMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
return EXECUTED;
|
||||
}
|
31
application/MissionManager/src/PirTriggeredMissionState.h
Normal file
31
application/MissionManager/src/PirTriggeredMissionState.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 PIR_TRIGGERED_MISSION_STATE_H
|
||||
#define PIR_TRIGGERED_MISSION_STATE_H
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class PirTriggeredMissionState : public MissionState
|
||||
{
|
||||
public:
|
||||
PirTriggeredMissionState();
|
||||
virtual ~PirTriggeredMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
86
application/MissionManager/src/SdCardHandleState.cpp
Normal file
86
application/MissionManager/src/SdCardHandleState.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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 "SdCardHandleState.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
SdCardHandleState::SdCardHandleState() : State("SdCardHandleState"), mSdCardStatus(StorageEvent::END)
|
||||
{
|
||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&SdCardHandleState::MediaReportHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
std::bind(&SdCardHandleState::SdCardEventHandle, this, _1);
|
||||
}
|
||||
void SdCardHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== SdCardHandleState::GoInState.\n");
|
||||
}
|
||||
void SdCardHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== SdCardHandleState::GoOutState.\n");
|
||||
}
|
||||
bool SdCardHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
LogInfo(" MediaReportHandle.\n");
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<MediaReportEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<MediaReportEvent>>(message->mMissionData);
|
||||
if (!data) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
if (StorageEvent::SD_CARD_INSERT != mSdCardStatus) {
|
||||
/**
|
||||
* @brief The SD card has not been mounted yet, cache the data for the quick start first.
|
||||
*
|
||||
*/
|
||||
LogWarning("Sd card is not inserted, cache data.\n");
|
||||
mFileNeedToSave = std::make_shared<SaveFileInfo>(data->mData.mFileName);
|
||||
return EXECUTED;
|
||||
}
|
||||
LogInfo("file = %s.\n", data->mData.mFileName.c_str());
|
||||
SaveFileInfo saveFileInfo(data->mData.mFileName);
|
||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(saveFileInfo);
|
||||
if (IsCodeOK(code) == false) {
|
||||
LogError("SaveFile failed.\n");
|
||||
}
|
||||
return EXECUTED;
|
||||
}
|
||||
bool SdCardHandleState::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);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
if (mFileNeedToSave && StorageEvent::SD_CARD_INSERT == data->mData) {
|
||||
LogInfo("Sd card is inserted for the first time.\n");
|
||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(*(mFileNeedToSave.get()));
|
||||
if (IsCodeOK(code) == false) {
|
||||
LogError("SaveFile failed.\n");
|
||||
}
|
||||
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;
|
||||
}
|
39
application/MissionManager/src/SdCardHandleState.h
Normal file
39
application/MissionManager/src/SdCardHandleState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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_H
|
||||
#define SD_CARD_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this<SdCardHandleState>
|
||||
{
|
||||
public:
|
||||
SdCardHandleState();
|
||||
virtual ~SdCardHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
protected:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
bool SdCardEventHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
StorageEvent mSdCardStatus;
|
||||
std::shared_ptr<SaveFileInfo> mFileNeedToSave;
|
||||
};
|
||||
#endif
|
44
application/MissionManager/src/SetLedState.cpp
Normal file
44
application/MissionManager/src/SetLedState.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 "SetLedState.h"
|
||||
SetLedState::SetLedState(const LedState &state, const unsigned int &keepAliveTime, const unsigned int &blinkPeriod)
|
||||
: mState(state), mKeepAliveTime(keepAliveTime), mBlinkPeriod(blinkPeriod)
|
||||
{
|
||||
}
|
||||
StatusCode SetLedState::GetLedState(LedState &state)
|
||||
{
|
||||
state = mState;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
unsigned int SetLedState::GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return mKeepAliveTime;
|
||||
}
|
||||
unsigned int SetLedState::GetBlinkTimeMs(void)
|
||||
{
|
||||
return mBlinkPeriod;
|
||||
}
|
||||
void SetLedState::DeleteState(void)
|
||||
{
|
||||
mKeepAliveTime = DELETED_LED_STATE;
|
||||
}
|
||||
std::shared_ptr<SetLedState> SetLedState::ControlLed(const std::string &ledName, const LedState &state,
|
||||
const long int &keepAliveTime, const unsigned int &blinkPeriod)
|
||||
{
|
||||
std::shared_ptr<SetLedState> ledState = std::make_shared<SetLedState>(state, keepAliveTime, blinkPeriod);
|
||||
std::shared_ptr<LedControlContext> ledState2 = ledState;
|
||||
IDeviceManager::GetInstance()->ControlLed(ledName, ledState2);
|
||||
return ledState;
|
||||
}
|
42
application/MissionManager/src/SetLedState.h
Normal file
42
application/MissionManager/src/SetLedState.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 SET_LED_STATE_H
|
||||
#define SET_LED_STATE_H
|
||||
#include "IDeviceManager.h"
|
||||
#include "LedControl.h"
|
||||
constexpr int LED_BLINKING_FAST_PERIOD = 500;
|
||||
constexpr int LED_BLINKING_SLOW_PERIOD = 1000;
|
||||
class SetLedState : public LedControlContext, public VSingleControl
|
||||
{
|
||||
public:
|
||||
SetLedState(const LedState &state, const unsigned int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
virtual ~SetLedState() = default;
|
||||
StatusCode GetLedState(LedState &state) override;
|
||||
unsigned int GetKeepAliveTimeMs(void) override;
|
||||
unsigned int GetBlinkTimeMs(void) override;
|
||||
void DeleteState(void);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<SetLedState> ControlLed(const std::string &ledName, const LedState &state,
|
||||
const long int &keepAliveTime = KEEP_ALIVE_FOREVER,
|
||||
const unsigned int &blinkPeriod = LED_NOT_BLINK);
|
||||
|
||||
private:
|
||||
const LedState mState;
|
||||
unsigned int mKeepAliveTime;
|
||||
const unsigned int mBlinkPeriod;
|
||||
};
|
||||
#endif
|
59
application/MissionManager/src/StorageHandleState.cpp
Normal file
59
application/MissionManager/src/StorageHandleState.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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 "StorageHandleState.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
StorageHandleState::StorageHandleState() : State("StorageHandleState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::STORAGE_HANDLE_STATE_INIT] =
|
||||
std::bind(&StorageHandleState::StorageStartInitHandle, this, _1);
|
||||
}
|
||||
void StorageHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== StorageHandleState::GoInState.\n");
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
||||
}
|
||||
void StorageHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== StorageHandleState::GoOutState.\n");
|
||||
}
|
||||
bool StorageHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
void StorageHandleState::Init(void)
|
||||
{
|
||||
std::shared_ptr<VStorageMoniter> monitor = shared_from_this();
|
||||
IStorageManager::GetInstance()->SetMonitor(monitor);
|
||||
}
|
||||
void StorageHandleState::UnInit(void)
|
||||
{
|
||||
}
|
||||
void StorageHandleState::ReportEvent(const StorageEvent &event)
|
||||
{
|
||||
LogInfo("StorageHandleState::ReportEvent.\n");
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
std::shared_ptr<VMissionData> message2 = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message2);
|
||||
}
|
||||
bool StorageHandleState::StorageStartInitHandle(VStateMachineData *msg)
|
||||
{
|
||||
Init();
|
||||
return EXECUTED;
|
||||
}
|
39
application/MissionManager/src/StorageHandleState.h
Normal file
39
application/MissionManager/src/StorageHandleState.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 STORAGE_HANDLE_STATE_H
|
||||
#define STORAGE_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
class StorageHandleState : public State,
|
||||
public DataProcessing,
|
||||
public VStorageMoniter,
|
||||
public std::enable_shared_from_this<StorageHandleState>
|
||||
{
|
||||
public:
|
||||
StorageHandleState();
|
||||
virtual ~StorageHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
private: // About VStorageMoniter
|
||||
void ReportEvent(const StorageEvent &event) override;
|
||||
bool StorageStartInitHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
84
application/MissionManager/src/TestMissionState.cpp
Normal file
84
application/MissionManager/src/TestMissionState.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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 "TestMissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
TestMissionState::TestMissionState() : MissionState("TestMissionState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] =
|
||||
std::bind(&TestMissionState::ResetKeyMediaTaskHandle, this, _1);
|
||||
mKeyClickHandle["reset"] = std::bind(&TestMissionState::ClickResetKey, this, _1);
|
||||
}
|
||||
void TestMissionState::GoInState()
|
||||
{
|
||||
MissionState::GoInState();
|
||||
LogInfo(" ========== TestMissionState::GoInState.\n");
|
||||
AppParam mAppParam(APP_MANAGER_DEVICE_IP, APP_MANAGER_HTTP_SERVER_PORT, APP_MANAGER_TCP_SERVER_PORT); // TODO:
|
||||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
std::shared_ptr<VAppMonitor> monitor =
|
||||
std::dynamic_pointer_cast<TestMissionState>(MissionState::shared_from_this());
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
ControlDeviceStatusLed(DeviceStatus::NORMAL);
|
||||
}
|
||||
void TestMissionState::GoOutState()
|
||||
{
|
||||
MissionState::GoOutState();
|
||||
LogInfo(" ========== TestMissionState::GoOutState.\n");
|
||||
}
|
||||
bool TestMissionState::SdCardEventReportSendToApp(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);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
SdCardStatus status = SdCardStatusConvert(data->mData);
|
||||
IAppManager::GetInstance()->SetSdCardStatus(status);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool TestMissionState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::MEDIA_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
||||
bool TestMissionState::ClickResetKey(const KeyEventData &data)
|
||||
{
|
||||
LogInfo("reset key click:make a media task.\n");
|
||||
// std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||
// static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||
// MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
std::shared_ptr<VMissionData> message =
|
||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::RESET_KEY_MEDIA_TASK));
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
return EXECUTED;
|
||||
}
|
||||
SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageEvent::SD_CARD_INSERT:
|
||||
return SdCardStatus::NORMAL;
|
||||
case StorageEvent::SD_CARD_REMOVE:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
case StorageEvent::SD_ABNORMAL:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
default:
|
||||
LogError("SdCardStatusConvert failed.\n");
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
37
application/MissionManager/src/TestMissionState.h
Normal file
37
application/MissionManager/src/TestMissionState.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 TEST_MISSION_STATE_H
|
||||
#define TEST_MISSION_STATE_H
|
||||
#include "AppMonitor.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class TestMissionState : public MissionState, public AppMonitor
|
||||
{
|
||||
public:
|
||||
TestMissionState();
|
||||
virtual ~TestMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||
bool ClickResetKey(const KeyEventData &data);
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
};
|
||||
#endif
|
68
application/MissionManager/src/TopState.cpp
Normal file
68
application/MissionManager/src/TopState.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "TopState.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "KeyControl.h"
|
||||
#include "MissionStateMachine.h"
|
||||
TopState::TopState() : State("TopState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::STORAGE_HANDLE_STATE_INIT] =
|
||||
std::bind(&TopState::StorageStartInitHandle, this, _1);
|
||||
}
|
||||
void TopState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== TopState::GoInState.\n");
|
||||
std::shared_ptr<VMcuMonitor> mcuMonitor = std::dynamic_pointer_cast<VMcuMonitor>(shared_from_this());
|
||||
McuMonitor::Init(mcuMonitor);
|
||||
std::shared_ptr<VMediaMonitor> mediaMonitor = std::dynamic_pointer_cast<VMediaMonitor>(shared_from_this());
|
||||
IMediaManager::GetInstance()->SetMediaMonitor(mediaMonitor);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::MISSION_STATE);
|
||||
std::shared_ptr<VKeyMonitor> keysMonitor = std::dynamic_pointer_cast<VKeyMonitor>(shared_from_this());
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(keysMonitor);
|
||||
}
|
||||
void TopState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== TopState::GoOutState.\n");
|
||||
}
|
||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
StatusCode TopState::ReportEvent(const MediaReportEvent &event)
|
||||
{
|
||||
LogInfo(" ReportEvent:\n");
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void TopState::KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs)
|
||||
{
|
||||
LogInfo(" KeyEventReport:key name = %s, key event = %s, time = %d\n",
|
||||
keyName.c_str(),
|
||||
PrintKeyEvent(static_cast<KeyEvent>(event)),
|
||||
timeMs);
|
||||
KeyEventData data(keyName, static_cast<KeyEvent>(event), timeMs);
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<KeyEventData>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::KEY_EVENT_HANDLE), data);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
}
|
||||
bool TopState::StorageStartInitHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
45
application/MissionManager/src/TopState.h
Normal file
45
application/MissionManager/src/TopState.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 TOP_STATE_H
|
||||
#define TOP_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "McuMonitor.h"
|
||||
class TopState : public State,
|
||||
public DataProcessing,
|
||||
public VMediaMonitor,
|
||||
public McuMonitor,
|
||||
public VKeyMonitor,
|
||||
public std::enable_shared_from_this<TopState>
|
||||
{
|
||||
public:
|
||||
TopState();
|
||||
virtual ~TopState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private: // About VMediaMonitor
|
||||
StatusCode ReportEvent(const MediaReportEvent &event) override;
|
||||
|
||||
private: // About KeyMonitor
|
||||
void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs) override;
|
||||
|
||||
private:
|
||||
bool StorageStartInitHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
42
application/MissionManager/src/UpgradeState.cpp
Normal file
42
application/MissionManager/src/UpgradeState.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 "IHuntingUpgrade.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
UpgradeState::UpgradeState() : State("UpgradeState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::CHECK_UPGRADE_FILE] = std::bind(&UpgradeState::CheckUpgradeFileHandle, this, _1);
|
||||
}
|
||||
void UpgradeState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== UpgradeState::GoInState.\n");
|
||||
}
|
||||
void UpgradeState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== UpgradeState::GoOutState.\n");
|
||||
}
|
||||
bool UpgradeState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool UpgradeState::CheckUpgradeFileHandle(VStateMachineData *msg)
|
||||
{
|
||||
// TODO: need to improve:It cannot be blocked.
|
||||
IHuntingUpgrade::GetInstance()->CheckUpgradeFile();
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
||||
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
|
65
application/main/CMakeLists.txt
Normal file
65
application/main/CMakeLists.txt
Normal file
|
@ -0,0 +1,65 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
|
||||
set(MAIN_INCLUDE_PATH "${APPLICATION_SOURCE_PATH}/main/src" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include" CACHE STRING INTERNAL FORCE)
|
||||
set(MAIN_INCLUDE_PATH "${MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include" CACHE STRING INTERNAL FORCE)
|
||||
include_directories(${MAIN_INCLUDE_PATH})
|
||||
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${HAL_SOURCE_PATH}/include
|
||||
)
|
||||
|
||||
aux_source_directory(./ SRC_FILES)
|
||||
# aux_source_directory(./src SRC_FILES)
|
||||
|
||||
# Mark src files for test.
|
||||
file(GLOB_RECURSE MAIN_SRC_FILE_THIS src/*.cpp src/*.c)
|
||||
set(MAIN_SRC_FILE "${MAIN_SRC_FILE_THIS}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
|
||||
set(TARGET_LIB MainLib)
|
||||
add_library(${TARGET_LIB} STATIC ${MAIN_SRC_FILE_THIS})
|
||||
set(TARGET_NAME ipc_x86)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
|
||||
set(LINK_LIB StatusCode Log Hal pthread dl)
|
||||
set(MAIN_LINK_LIB "${LINK_LIB}" CACHE STRING INTERNAL FORCE)
|
||||
target_link_libraries(${TARGET_LIB} ${MAIN_LINK_LIB})
|
||||
target_link_libraries(${TARGET_NAME} ${TARGET_LIB})
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
ipc_x86_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${MAIN_SRC_FILE_THIS}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/main
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
ipc_x86_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES} ${MAIN_SRC_FILE_THIS}
|
||||
WORKING_DIRECTORY ${APPLICATION_SOURCE_PATH}/main
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make ipc_x86_code_check
|
||||
COMMAND make ipc_x86_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
24
application/main/main.cpp
Normal file
24
application/main/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 "ILog.h"
|
||||
#include "MainThread.h"
|
||||
#include <thread>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
return 0;
|
||||
}
|
73
application/main/src/MainThread.cpp
Normal file
73
application/main/src/MainThread.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 "MainThread.h"
|
||||
#include "IHalCpp.h"
|
||||
#include "ILog.h"
|
||||
#include <thread>
|
||||
MainThread::MainThread()
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
std::shared_ptr<MainThread> &MainThread::GetInstance(std::shared_ptr<MainThread> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<MainThread>();
|
||||
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 MainThread::Init(void)
|
||||
{
|
||||
CreateLogModule();
|
||||
ILogInit(LOG_EASYLOGGING);
|
||||
CustomizationInit();
|
||||
mMainThreadRuning = true;
|
||||
CreateAllModules();
|
||||
// IHalInit();
|
||||
IHalCpp::GetInstance()->Init();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::UnInit(void)
|
||||
{
|
||||
IHalCpp::GetInstance()->UnInit();
|
||||
DestoryAllModules();
|
||||
ILogUnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MainThread::CreateAllModules(void)
|
||||
{
|
||||
// CreateLogModule();
|
||||
// CreateHalModule();
|
||||
CreateHalCppModule();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MainThread::DestoryAllModules(void)
|
||||
{
|
||||
}
|
||||
void MainThread::ResetAllPtrMaker(void)
|
||||
{
|
||||
}
|
||||
void MainThread::Runing(void)
|
||||
{
|
||||
while (mMainThreadRuning) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
44
application/main/src/MainThread.h
Normal file
44
application/main/src/MainThread.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 MAIN_THREAD_H
|
||||
#define MAIN_THREAD_H
|
||||
#include "StatusCode.h"
|
||||
#include <memory>
|
||||
class MainThread
|
||||
{
|
||||
public:
|
||||
MainThread();
|
||||
virtual ~MainThread() = default;
|
||||
static std::shared_ptr<MainThread> &GetInstance(std::shared_ptr<MainThread> *impl = nullptr);
|
||||
virtual StatusCode Init(void);
|
||||
virtual StatusCode UnInit(void);
|
||||
void Runing(void);
|
||||
void Exit(void)
|
||||
{
|
||||
mMainThreadRuning = false;
|
||||
}
|
||||
virtual void CustomizationInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
StatusCode CreateAllModules(void);
|
||||
void DestoryAllModules(void);
|
||||
void ResetAllPtrMaker(void);
|
||||
|
||||
private:
|
||||
bool mMainThreadRuning;
|
||||
};
|
||||
#endif // !MAIN_THREAD_H
|
3
external/.gitignore
vendored
3
external/.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
|
||||
goahead-5.2.0/GoAhead
|
||||
goahead-5.2.0/GoAhead
|
||||
ffmpeg/ffmpeg-6.1.1
|
3
external/CMakeLists.txt
vendored
3
external/CMakeLists.txt
vendored
|
@ -19,4 +19,5 @@ add_subdirectory(httpserver.h-master/src)
|
|||
# ================= httpserver end ================= #
|
||||
|
||||
add_subdirectory(cJSON-1.7.17)
|
||||
add_subdirectory(libhv/libhv-1.3.2)
|
||||
add_subdirectory(libhv/libhv-1.3.2)
|
||||
add_subdirectory(ffmpeg)
|
40
external/ffmpeg/CMakeLists.txt
vendored
Normal file
40
external/ffmpeg/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
|
||||
add_custom_target(
|
||||
ffmpeg
|
||||
# DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a
|
||||
# COMMAND mkdir ${GOAHEAD_UPLOAD_TMP_PATH}
|
||||
# COMMAND cp ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/modify/http.c ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/src
|
||||
# COMMAND touch ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/src/http.c
|
||||
COMMAND test -f ${EXTERNAL_SOURCE_PATH}/ffmpeg/Makefile || tar -xf ffmpeg_6.1.1.orig.tar.xz
|
||||
COMMAND cd ffmpeg-6.1.1 && ./configure --enable-cross-compile --target-os=linux --arch=arm64
|
||||
--cc=${CMAKE_C_COMPILER}
|
||||
--cxx=${CMAKE_CXX_COMPILER}
|
||||
--prefix=${EXTERNAL_LIBS_OUTPUT_PATH}/ffmpeg
|
||||
--disable-asm --enable-parsers --disable-decoders --enable-decoder=h264
|
||||
--disable-debug --enable-ffmpeg --enable-shared --enable-static --disable-stripping --disable-doc
|
||||
--enable-gpl --enable-nonfree --enable-version3 --enable-small
|
||||
--disable-mipsdsp --disable-mipsdspr2
|
||||
--disable-encoders
|
||||
--disable-muxers --enable-muxer=mov --enable-muxer=mp4
|
||||
--disable-decoders --enable-decoder=aac
|
||||
--disable-filters
|
||||
--disable-demuxers --enable-demuxer=mov
|
||||
--disable-parsers
|
||||
--disable-protocols --enable-protocol=file
|
||||
--disable-bsfs --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb
|
||||
--disable-indevs
|
||||
--disable-outdevs --disable-ffprobe --disable-ffmpeg --disable-ffplay --disable-debug
|
||||
COMMAND cd ffmpeg-6.1.1 && make
|
||||
COMMAND cd ffmpeg-6.1.1 && make install
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/ffmpeg/
|
||||
)
|
||||
|
||||
add_custom_target(
|
||||
remove_ffmpeg_source_files
|
||||
COMMAND rm -rf ffmpeg-6.1.1
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/ffmpeg/
|
||||
)
|
||||
|
||||
# 将clean目标依赖于我们自定义的clean_script目标
|
||||
add_dependencies(sdk_clean remove_ffmpeg_source_files)
|
10
external/ffmpeg/build_ffmpeg.sh
vendored
Executable file
10
external/ffmpeg/build_ffmpeg.sh
vendored
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
# 编译ffmpeg
|
||||
echo "Compile ffmpeg."
|
||||
cd ffmpeg-6.1.1
|
||||
./configure --enable-cross-compile --target-os=linux --arch=arm64 \
|
||||
--cc=gcc \
|
||||
--cxx=g++ \
|
||||
--prefix=/home/xiaojiazhu/project/tmp \
|
||||
--disable-asm --enable-parsers --disable-decoders --enable-decoder=h264 --enable-decoder=aac \
|
||||
--disable-debug --enable-ffmpeg --enable-shared --enable-static --disable-stripping --disable-doc
|
BIN
external/ffmpeg/ffmpeg_6.1.1.orig.tar.xz
vendored
Executable file
BIN
external/ffmpeg/ffmpeg_6.1.1.orig.tar.xz
vendored
Executable file
Binary file not shown.
|
@ -38,11 +38,11 @@ public:
|
|||
virtual ~VKeyMonitor() = default;
|
||||
virtual void KeyEventReport(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs);
|
||||
};
|
||||
class VirtualLedControl
|
||||
class LedControlContext
|
||||
{
|
||||
public:
|
||||
VirtualLedControl() = default;
|
||||
virtual ~VirtualLedControl() = default;
|
||||
LedControlContext() = default;
|
||||
virtual ~LedControlContext() = default;
|
||||
};
|
||||
class IDeviceManager
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
static std::shared_ptr<IDeviceManager> &GetInstance(std::shared_ptr<IDeviceManager> *impl = nullptr);
|
||||
virtual const StatusCode Init(void);
|
||||
virtual const StatusCode UnInit(void);
|
||||
virtual const StatusCode ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control);
|
||||
virtual const StatusCode ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control);
|
||||
virtual const StatusCode SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor);
|
||||
};
|
||||
#endif
|
|
@ -36,7 +36,7 @@ const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &
|
|||
LogInfo("DeviceManager::SetAllKeysMonitor\n");
|
||||
return KeyManager::GetInstance()->SetKeyMonitor(monitor);
|
||||
}
|
||||
const StatusCode DeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control)
|
||||
const StatusCode DeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control)
|
||||
{
|
||||
LedManager::GetInstance()->ControlLed(ledName, control);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
const StatusCode Init(void) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
const StatusCode SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor) override;
|
||||
const StatusCode ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control) override;
|
||||
const StatusCode ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control) override;
|
||||
|
||||
private:
|
||||
// std::vector<std::shared_ptr<LedManager>> mLedManagers;
|
||||
|
|
|
@ -39,7 +39,7 @@ const StatusCode IDeviceManager::UnInit(void)
|
|||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IDeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control)
|
||||
const StatusCode IDeviceManager::ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ void LedManager::Init(void)
|
|||
void LedManager::UnInit(void)
|
||||
{
|
||||
StopTimer();
|
||||
mMutex.lock();
|
||||
for (auto &iter : mAllLedHal) {
|
||||
iter.second->DeleteAllState();
|
||||
}
|
||||
mMutex.unlock();
|
||||
mAllLedHal.clear();
|
||||
}
|
||||
void LedManager::Timer(void)
|
||||
|
@ -53,7 +58,7 @@ void LedManager::Timer(void)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(LED_STATE_CHECK_PERIOD_MS));
|
||||
}
|
||||
}
|
||||
void LedManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control)
|
||||
void LedManager::ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(mMutex);
|
||||
std::shared_ptr<VSingleControl> singleControl = std::dynamic_pointer_cast<VSingleControl>(control);
|
||||
|
@ -61,6 +66,11 @@ void LedManager::ControlLed(const std::string &ledName, std::shared_ptr<VirtualL
|
|||
LogError("led can't be controled.\n");
|
||||
return;
|
||||
}
|
||||
auto iter = mAllLedHal.find(ledName);
|
||||
if (iter == mAllLedHal.end()) {
|
||||
LogError("Can't find led [%s].\n", ledName.c_str());
|
||||
return;
|
||||
}
|
||||
mAllLedHal[ledName]->AddLedState(singleControl);
|
||||
}
|
||||
void LedManager::StartTimer(void)
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
void UnInit(void);
|
||||
void StartTimer(void);
|
||||
void StopTimer(void);
|
||||
void ControlLed(const std::string &ledName, std::shared_ptr<VirtualLedControl> &control);
|
||||
void ControlLed(const std::string &ledName, std::shared_ptr<LedControlContext> &control);
|
||||
|
||||
private:
|
||||
void Timer(void);
|
||||
|
|
Binary file not shown.
BIN
output_files/libs/test_tools/libHalTestTool.a
Normal file
BIN
output_files/libs/test_tools/libHalTestTool.a
Normal file
Binary file not shown.
|
@ -42,8 +42,10 @@ endif()
|
|||
|
||||
set(TARGET_NAME HuntingCameraTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} McuProtocolTestTool UartDeviceTestTool)
|
||||
target_link_libraries(${TARGET_NAME} HuntingMainLib MissionManagerTestTool McuManagerTestTool McuAskBaseTestTool
|
||||
AppManagerTestTool HalTestTool DeviceManagerTestTool TestManager gtest gmock pthread)
|
||||
AppManagerTestTool HalTestTool DeviceManagerTestTool TestManager UartDevice Hal LinuxApiMock gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} UpgradeTool Servers)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -65,4 +65,18 @@ TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_KeyControlClick)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
/**
|
||||
* @brief Construct a new test f object
|
||||
* ../output_files/test/bin/HuntingCameraTest
|
||||
* --gtest_filter=HuntingCameraTest.HS_INTEGRATION_HunttingCamera_EXAMPLE_LedControl
|
||||
*/
|
||||
TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_LedControl)
|
||||
{
|
||||
SetAllLedsResult(mAllLedsMock);
|
||||
MockOtherSideIpcMissionReply(IpcMission::TEST);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
} // namespace DeviceManager_Mock_Test
|
|
@ -18,6 +18,7 @@
|
|||
#include "MainThread.h"
|
||||
#include <thread>
|
||||
const char *KEY_RESET = "reset";
|
||||
const char *LED_DEVICE_STATUS = "device_status";
|
||||
void MainThreadTest::CustomizationInit(void)
|
||||
{
|
||||
// Do nothing here to make sure test tool work.
|
||||
|
@ -44,6 +45,7 @@ void HuntingCameraTest::SetUp()
|
|||
MainThread::GetInstance(&mainThread);
|
||||
HalTestTool::Init();
|
||||
CreateAllKeysMcok();
|
||||
CreateAllLedsMcok();
|
||||
AppManagerTestTool::Init();
|
||||
MissionManagerTestTool::Init();
|
||||
mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||
|
@ -72,6 +74,7 @@ void HuntingCameraTest::TearDown()
|
|||
DeviceManagerTestTool::UnInit();
|
||||
DestroyAllCamerasMock();
|
||||
DestroyAllKeysMock();
|
||||
DestroyAllLedsMock();
|
||||
}
|
||||
void HuntingCameraTest::CreateAllCamerasMcok(void)
|
||||
{
|
||||
|
@ -86,13 +89,19 @@ void HuntingCameraTest::CreateAllKeysMcok(void)
|
|||
{
|
||||
std::shared_ptr<VKeyHal> key = HalTestTool::MakeKeyHalTest(KEY_RESET);
|
||||
mAllKeysMock[KEY_RESET] = key;
|
||||
// std::shared_ptr<VLedHal> led = HalTestTool::MakeLedHalTest(LED_TEST);
|
||||
// mAllLedsMock[LED_TEST] = led;
|
||||
HalTestTool::SetAllKeysResult(mAllKeysMock);
|
||||
}
|
||||
void HuntingCameraTest::DestroyAllKeysMock(void)
|
||||
{
|
||||
|
||||
mAllKeysMock.clear();
|
||||
// mAllLedsMock.clear();
|
||||
}
|
||||
void HuntingCameraTest::CreateAllLedsMcok(void)
|
||||
{
|
||||
std::shared_ptr<VLedHal> led = HalTestTool::MakeLedHalTest(LED_DEVICE_STATUS);
|
||||
mAllLedsMock[LED_DEVICE_STATUS] = led;
|
||||
}
|
||||
void HuntingCameraTest::DestroyAllLedsMock(void)
|
||||
{
|
||||
mAllLedsMock.clear();
|
||||
}
|
|
@ -52,11 +52,14 @@ private:
|
|||
void DestroyAllCamerasMock(void);
|
||||
void CreateAllKeysMcok(void);
|
||||
void DestroyAllKeysMock(void);
|
||||
void CreateAllLedsMcok(void);
|
||||
void DestroyAllLedsMock(void);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> mAllCamerasMock;
|
||||
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
|
||||
std::map<std::string, std::shared_ptr<VLedHal>> mAllLedsMock;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,18 +12,16 @@ include_directories(
|
|||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||
${TEST_TOOLS_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
aux_source_directory(. SRC_FILES)
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME HalTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} HalTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} Hal Log LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -37,6 +37,7 @@ endif()
|
|||
set(TARGET_NAME AppManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} AppManagerTestTool HalTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} AppManager Servers KeyControl LedControl Hal LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -35,6 +35,7 @@ endif()
|
|||
set(TARGET_NAME DeviceManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} DeviceManager DeviceManagerTestTool HalTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} Hal LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -196,4 +196,20 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControlLed4)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/DeviceManagerTest
|
||||
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControlLed5
|
||||
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControlLed5)
|
||||
{
|
||||
SetAllLedsResult(mAllLedsMock);
|
||||
IDeviceManager::GetInstance()->Init();
|
||||
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||
std::shared_ptr<LedControlContext> ledControl =
|
||||
DeviceManagerTestTool::ControlLed(LED_TEST, LedState::ON, KEEP_ALIVE_FOREVER, LED_NOT_BLINK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
DeviceManagerTestTool::DestoryLedControl(ledControl);
|
||||
DeviceManagerTestTool::ControlLed(LED_TEST, LedState::ON, KEEP_ALIVE_FOREVER, LED_NOT_BLINK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
} // namespace DeviceManagerTest
|
|
@ -54,8 +54,9 @@ public:
|
|||
void UnInit(void);
|
||||
|
||||
public:
|
||||
std::shared_ptr<VirtualLedControl> ControlLed(const std::string &ledName, const LedState &state,
|
||||
std::shared_ptr<LedControlContext> ControlLed(const std::string &ledName, const LedState &state,
|
||||
const unsigned int &aliveTimeMs, const unsigned int &blinkTimeMs);
|
||||
void DestoryLedControl(std::shared_ptr<LedControlContext> &ledControl);
|
||||
|
||||
protected:
|
||||
void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) override;
|
||||
|
|
|
@ -34,6 +34,7 @@ endif()
|
|||
set(TARGET_NAME HuntingUpgradeTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} HuntingUpgradeTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} HuntingUpgrade UpgradeTool Log LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -35,6 +35,7 @@ endif()
|
|||
set(TARGET_NAME IpcConfigTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} IpcConfigTestTool LinuxApi gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} IpcConfig LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -43,6 +43,7 @@ endif()
|
|||
set(TARGET_NAME McuManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} McuAskBase McuManager McuManagerTestTool McuAskBaseTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} McuProtocolTestTool UartDeviceTestTool UartDevice LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -36,6 +36,7 @@ endif()
|
|||
set(TARGET_NAME MediaManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} MediaManager MediaManagerTestTool HalTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} Hal LedControl LinuxApiMock)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<<<<<<< HEAD
|
||||
# 1. 工具
|
||||
|
||||
## 1.1. 概述
|
||||
|
@ -22,10 +21,4 @@ $ ./delete_test_code.sh ../../test/
|
|||
```
|
||||
$ cd //tools/shell
|
||||
$ ./delete_sdk_code.sh
|
||||
```
|
||||
=======
|
||||
# 1. 工具
|
||||
|
||||
## 1.1. 概述
|
||||
  该目录存放使用到的工具。
|
||||
>>>>>>> embedded-framework/master
|
||||
```
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
## 1.1. 使用说明
|
||||
|
||||
<<<<<<< HEAD
|
||||
1. 在本目录执行make;会下载源码,编译,并把llvm源码包(含生成的工具文件)拷贝到**用户根目录**,以方便不同目录的源码工程可以复用llvm工具;
|
||||
|
||||
**如果安装时使用普通用户执行make compile_llvm,编译时使用跟用户权限(或者加sudo),可能会提示命令不存在。**
|
||||
=======
|
||||
1. 在工程根目录执行make compile_llvm;会下载源码,编译,并把llvm源码包(含生成的工具文件)拷贝到用户根目录,以方便不同目录的源码工程可以复用llvm工具;
|
||||
>>>>>>> embedded-framework/master
|
||||
**如果安装时使用普通用户执行make compile_llvm,编译时使用跟用户权限(或者加sudo),可能会提示命令不存在。**
|
|
@ -24,7 +24,6 @@ find "$1" -type d -name "tool" | while read -r tool_dir; do
|
|||
else
|
||||
echo "No 'src' directory found in '$tool_dir'"
|
||||
fi
|
||||
<<<<<<< HEAD
|
||||
|
||||
# 检查CMakeLists.txt文件是否存在,然后删除
|
||||
cmake_file="$tool_dir/CMakeLists.txt"
|
||||
|
@ -36,8 +35,6 @@ find "$1" -type d -name "tool" | while read -r tool_dir; do
|
|||
echo "Error deleting 'CMakeLists.txt' in '$tool_dir'"
|
||||
fi
|
||||
fi
|
||||
=======
|
||||
>>>>>>> embedded-framework/master
|
||||
done
|
||||
|
||||
echo "Operation completed."
|
|
@ -30,7 +30,12 @@ enum class LedState
|
|||
ON,
|
||||
GREEN,
|
||||
RED,
|
||||
BLUE,
|
||||
YELLOW,
|
||||
GREEN_RED_MEANS_YELLOW,
|
||||
GREEN_BLUE_MEANS_CYAN,
|
||||
RED_BLUE_MEANS_PURPLE,
|
||||
GREEN_RED_BLUE_MEANS_WHITE,
|
||||
LEVEL_0,
|
||||
LEVEL_1,
|
||||
LEVEL_2,
|
||||
|
@ -44,39 +49,20 @@ class VSingleControl
|
|||
public:
|
||||
VSingleControl() = default;
|
||||
virtual ~VSingleControl() = default;
|
||||
virtual StatusCode GetLedState(LedState &state)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual unsigned int GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return KEEP_ALIVE_FOREVER;
|
||||
}
|
||||
virtual unsigned int GetBlinkTimeMs(void)
|
||||
{
|
||||
return LED_NOT_BLINK;
|
||||
}
|
||||
virtual StatusCode GetLedState(LedState &state);
|
||||
virtual unsigned int GetKeepAliveTimeMs(void);
|
||||
virtual unsigned int GetBlinkTimeMs(void);
|
||||
};
|
||||
class VLedControl
|
||||
{
|
||||
public:
|
||||
VLedControl() = default;
|
||||
virtual ~VLedControl() = default;
|
||||
virtual StatusCode SetLedState(const LedState &state)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
virtual void AddLedState(std::shared_ptr<VSingleControl> &control)
|
||||
{
|
||||
}
|
||||
virtual void CheckState(const unsigned int &period)
|
||||
{
|
||||
}
|
||||
// virtual void SetHalLedState(const VirtualLedState &state) {}
|
||||
virtual std::string GetLedName(void)
|
||||
{
|
||||
return "undefine";
|
||||
}
|
||||
virtual StatusCode SetLedState(const LedState &state);
|
||||
virtual void AddLedState(std::shared_ptr<VSingleControl> &control);
|
||||
virtual void CheckState(const unsigned int &period);
|
||||
virtual std::string GetLedName(void);
|
||||
virtual void DeleteAllState(void);
|
||||
};
|
||||
class LedControl : virtual public VLedControl
|
||||
{
|
||||
|
@ -87,6 +73,12 @@ public:
|
|||
void AddLedState(std::shared_ptr<VSingleControl> &state) override;
|
||||
|
||||
private:
|
||||
void DeleteAllState(void) override;
|
||||
/**
|
||||
* @brief Each time you control a light, check for invalid data to avoid wasting memory resources.
|
||||
*
|
||||
*/
|
||||
void DeleteUselessState(void);
|
||||
void NewLedStateStart(void);
|
||||
void DeleteTopLedState(void);
|
||||
void BlinkOff(std::shared_ptr<VSingleControl> &state);
|
||||
|
|
|
@ -14,9 +14,45 @@
|
|||
*/
|
||||
#include "LedControl.h"
|
||||
#include "ILog.h"
|
||||
#include <algorithm>
|
||||
StatusCode VSingleControl::GetLedState(LedState &state)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
unsigned int VSingleControl::GetKeepAliveTimeMs(void)
|
||||
{
|
||||
return KEEP_ALIVE_FOREVER;
|
||||
}
|
||||
unsigned int VSingleControl::GetBlinkTimeMs(void)
|
||||
{
|
||||
return LED_NOT_BLINK;
|
||||
}
|
||||
StatusCode VLedControl::SetLedState(const LedState &state)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
void VLedControl::AddLedState(std::shared_ptr<VSingleControl> &control)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
void VLedControl::CheckState(const unsigned int &period)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
std::string VLedControl::GetLedName(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return "undefine";
|
||||
}
|
||||
void VLedControl::DeleteAllState(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
void LedControl::AddLedState(std::shared_ptr<VSingleControl> &state)
|
||||
{
|
||||
LogInfo("Add led state.\n");
|
||||
DeleteUselessState();
|
||||
NewLedStateStart();
|
||||
LedState ledState = LedState::END;
|
||||
state->GetLedState(ledState);
|
||||
|
@ -27,6 +63,24 @@ void LedControl::AddLedState(std::shared_ptr<VSingleControl> &state)
|
|||
}
|
||||
mStates.push_back(state);
|
||||
}
|
||||
void LedControl::DeleteAllState(void)
|
||||
{
|
||||
mStates.clear();
|
||||
SetLedState(LedState::OFF);
|
||||
}
|
||||
void LedControl::DeleteUselessState(void)
|
||||
{
|
||||
constexpr bool DELETE_STATE = true;
|
||||
constexpr bool KEEP_STATE = false;
|
||||
auto is_to_remove = [](const std::shared_ptr<VSingleControl> &state) {
|
||||
if (DELETED_LED_STATE == state->GetKeepAliveTimeMs()) {
|
||||
LogInfo(" Delete useless led state.\n");
|
||||
return DELETE_STATE;
|
||||
}
|
||||
return KEEP_STATE;
|
||||
};
|
||||
mStates.erase(std::remove_if(mStates.begin(), mStates.end(), is_to_remove), mStates.end());
|
||||
}
|
||||
void LedControl::CheckState(const unsigned int &period)
|
||||
{
|
||||
const int TOP_STATE_SHOW = mStates.size() - 1;
|
||||
|
@ -71,6 +125,7 @@ void LedControl::DeleteTopLedState(void)
|
|||
mStates.erase(mStates.begin() + TOP_STATE_SHOW);
|
||||
const int NEXT_LED_STATE = mStates.size() - 1;
|
||||
if (NEXT_LED_STATE < 0) {
|
||||
SetLedState(LedState::OFF);
|
||||
return;
|
||||
}
|
||||
LogInfo("Top next led state.\n");
|
||||
|
|
Loading…
Reference in New Issue
Block a user