diff --git a/CMakeLists.txt b/CMakeLists.txt index e0914214..3c9e8b31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/application/MissionManager/CMakeLists.txt b/application/MissionManager/CMakeLists.txt index b566318a..10d17bb1 100644 --- a/application/MissionManager/CMakeLists.txt +++ b/application/MissionManager/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( ${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 @@ -29,7 +30,7 @@ aux_source_directory(./src SRC_FILES) set(TARGET_NAME MissionManager) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager DeviceManager HuntingUpgrade KeyControl StatusCode Log) +target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager DeviceManager HuntingUpgrade KeyControl LedControl StatusCode Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/application/MissionManager/src/LedsHandle.cpp b/application/MissionManager/src/LedsHandle.cpp new file mode 100644 index 00000000..57fab914 --- /dev/null +++ b/application/MissionManager/src/LedsHandle.cpp @@ -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(); +} \ No newline at end of file diff --git a/application/MissionManager/src/LedsHandle.h b/application/MissionManager/src/LedsHandle.h new file mode 100644 index 00000000..e394d5be --- /dev/null +++ b/application/MissionManager/src/LedsHandle.h @@ -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 mDeviceStatus; +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/MissionState.cpp b/application/MissionManager/src/MissionState.cpp index a872ff9e..04b3608e 100644 --- a/application/MissionManager/src/MissionState.cpp +++ b/application/MissionManager/src/MissionState.cpp @@ -30,6 +30,7 @@ void MissionState::GoInState() void MissionState::GoOutState() { LogInfo(" ========== MissionState::GoOutState.\n"); + LedsHandle::DeleteAllLeds(); } bool MissionState::ExecuteStateMsg(VStateMachineData *msg) { diff --git a/application/MissionManager/src/MissionState.h b/application/MissionManager/src/MissionState.h index 5b119883..2f5fcca2 100644 --- a/application/MissionManager/src/MissionState.h +++ b/application/MissionManager/src/MissionState.h @@ -16,7 +16,11 @@ #define MISSION_STATE_H #include "DataProcessing.h" #include "IStateMachine.h" -class MissionState : public State, public DataProcessing, public std::enable_shared_from_this +#include "LedsHandle.h" +class MissionState : public State, + public DataProcessing, + public LedsHandle, + public std::enable_shared_from_this { public: MissionState(const std::string &name); diff --git a/application/MissionManager/src/SetLedState.cpp b/application/MissionManager/src/SetLedState.cpp new file mode 100644 index 00000000..d0f9b81a --- /dev/null +++ b/application/MissionManager/src/SetLedState.cpp @@ -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::ControlLed(const std::string &ledName, const LedState &state, + const long int &keepAliveTime, const unsigned int &blinkPeriod) +{ + std::shared_ptr ledState = std::make_shared(state, keepAliveTime, blinkPeriod); + std::shared_ptr ledState2 = ledState; + IDeviceManager::GetInstance()->ControlLed(ledName, ledState2); + return ledState; +} \ No newline at end of file diff --git a/application/MissionManager/src/SetLedState.h b/application/MissionManager/src/SetLedState.h new file mode 100644 index 00000000..e18ba582 --- /dev/null +++ b/application/MissionManager/src/SetLedState.h @@ -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 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 \ No newline at end of file diff --git a/application/MissionManager/src/TestMissionState.cpp b/application/MissionManager/src/TestMissionState.cpp index 2dd95a99..7af850d7 100644 --- a/application/MissionManager/src/TestMissionState.cpp +++ b/application/MissionManager/src/TestMissionState.cpp @@ -34,6 +34,7 @@ void TestMissionState::GoInState() std::shared_ptr monitor = std::dynamic_pointer_cast(MissionState::shared_from_this()); IAppManager::GetInstance()->SetAppMonitor(monitor); + ControlDeviceStatusLed(DeviceStatus::NORMAL); } void TestMissionState::GoOutState() { diff --git a/external/.gitignore b/external/.gitignore index 8b47a85e..9c683404 100644 --- a/external/.gitignore +++ b/external/.gitignore @@ -1,2 +1,3 @@ -goahead-5.2.0/GoAhead \ No newline at end of file +goahead-5.2.0/GoAhead +ffmpeg/ffmpeg-6.1.1 \ No newline at end of file diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ce28bb86..1b27a22c 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -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) \ No newline at end of file +add_subdirectory(libhv/libhv-1.3.2) +add_subdirectory(ffmpeg) \ No newline at end of file diff --git a/external/ffmpeg/CMakeLists.txt b/external/ffmpeg/CMakeLists.txt new file mode 100644 index 00000000..908b6802 --- /dev/null +++ b/external/ffmpeg/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/external/ffmpeg/build_ffmpeg.sh b/external/ffmpeg/build_ffmpeg.sh new file mode 100755 index 00000000..92ee6896 --- /dev/null +++ b/external/ffmpeg/build_ffmpeg.sh @@ -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 diff --git a/external/ffmpeg/ffmpeg_6.1.1.orig.tar.xz b/external/ffmpeg/ffmpeg_6.1.1.orig.tar.xz new file mode 100755 index 00000000..3c4a2a24 Binary files /dev/null and b/external/ffmpeg/ffmpeg_6.1.1.orig.tar.xz differ diff --git a/middleware/DeviceManager/include/IDeviceManager.h b/middleware/DeviceManager/include/IDeviceManager.h index a479a4a1..a6a53897 100644 --- a/middleware/DeviceManager/include/IDeviceManager.h +++ b/middleware/DeviceManager/include/IDeviceManager.h @@ -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 &GetInstance(std::shared_ptr *impl = nullptr); virtual const StatusCode Init(void); virtual const StatusCode UnInit(void); - virtual const StatusCode ControlLed(const std::string &ledName, std::shared_ptr &control); + virtual const StatusCode ControlLed(const std::string &ledName, std::shared_ptr &control); virtual const StatusCode SetAllKeysMonitor(std::shared_ptr &monitor); }; #endif \ No newline at end of file diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp index c97eea37..a23b1913 100644 --- a/middleware/DeviceManager/src/DeviceManager.cpp +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -36,7 +36,7 @@ const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr & LogInfo("DeviceManager::SetAllKeysMonitor\n"); return KeyManager::GetInstance()->SetKeyMonitor(monitor); } -const StatusCode DeviceManager::ControlLed(const std::string &ledName, std::shared_ptr &control) +const StatusCode DeviceManager::ControlLed(const std::string &ledName, std::shared_ptr &control) { LedManager::GetInstance()->ControlLed(ledName, control); return CreateStatusCode(STATUS_CODE_OK); diff --git a/middleware/DeviceManager/src/DeviceManager.h b/middleware/DeviceManager/src/DeviceManager.h index faf003c7..682ce656 100644 --- a/middleware/DeviceManager/src/DeviceManager.h +++ b/middleware/DeviceManager/src/DeviceManager.h @@ -26,7 +26,7 @@ public: const StatusCode Init(void) override; const StatusCode UnInit(void) override; const StatusCode SetAllKeysMonitor(std::shared_ptr &monitor) override; - const StatusCode ControlLed(const std::string &ledName, std::shared_ptr &control) override; + const StatusCode ControlLed(const std::string &ledName, std::shared_ptr &control) override; private: // std::vector> mLedManagers; diff --git a/middleware/DeviceManager/src/IDeviceManager.cpp b/middleware/DeviceManager/src/IDeviceManager.cpp index 3c3ff155..4ad0e7d1 100644 --- a/middleware/DeviceManager/src/IDeviceManager.cpp +++ b/middleware/DeviceManager/src/IDeviceManager.cpp @@ -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 &control) +const StatusCode IDeviceManager::ControlLed(const std::string &ledName, std::shared_ptr &control) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } diff --git a/middleware/DeviceManager/src/LedManager.cpp b/middleware/DeviceManager/src/LedManager.cpp index a1477220..5f3a33ae 100644 --- a/middleware/DeviceManager/src/LedManager.cpp +++ b/middleware/DeviceManager/src/LedManager.cpp @@ -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 &control) +void LedManager::ControlLed(const std::string &ledName, std::shared_ptr &control) { std::lock_guard locker(mMutex); std::shared_ptr singleControl = std::dynamic_pointer_cast(control); @@ -61,6 +66,11 @@ void LedManager::ControlLed(const std::string &ledName, std::shared_ptrAddLedState(singleControl); } void LedManager::StartTimer(void) diff --git a/middleware/DeviceManager/src/LedManager.h b/middleware/DeviceManager/src/LedManager.h index 07d1ca8b..2ebc6eab 100644 --- a/middleware/DeviceManager/src/LedManager.h +++ b/middleware/DeviceManager/src/LedManager.h @@ -31,7 +31,7 @@ public: void UnInit(void); void StartTimer(void); void StopTimer(void); - void ControlLed(const std::string &ledName, std::shared_ptr &control); + void ControlLed(const std::string &ledName, std::shared_ptr &control); private: void Timer(void); diff --git a/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp b/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp index e38c8437..1a0dc5dd 100644 --- a/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp +++ b/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp @@ -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 \ No newline at end of file diff --git a/test/application/HuntingCamera/src_mock/HuntingCameraTest.cpp b/test/application/HuntingCamera/src_mock/HuntingCameraTest.cpp index 9759b887..579e0adb 100644 --- a/test/application/HuntingCamera/src_mock/HuntingCameraTest.cpp +++ b/test/application/HuntingCamera/src_mock/HuntingCameraTest.cpp @@ -18,6 +18,7 @@ #include "MainThread.h" #include 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 key = HalTestTool::MakeKeyHalTest(KEY_RESET); mAllKeysMock[KEY_RESET] = key; - // std::shared_ptr 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 led = HalTestTool::MakeLedHalTest(LED_DEVICE_STATUS); + mAllLedsMock[LED_DEVICE_STATUS] = led; +} +void HuntingCameraTest::DestroyAllLedsMock(void) +{ + mAllLedsMock.clear(); } \ No newline at end of file diff --git a/test/application/HuntingCamera/src_mock/HuntingCameraTest.h b/test/application/HuntingCamera/src_mock/HuntingCameraTest.h index 3cae61d3..29215075 100644 --- a/test/application/HuntingCamera/src_mock/HuntingCameraTest.h +++ b/test/application/HuntingCamera/src_mock/HuntingCameraTest.h @@ -52,11 +52,14 @@ private: void DestroyAllCamerasMock(void); void CreateAllKeysMcok(void); void DestroyAllKeysMock(void); + void CreateAllLedsMcok(void); + void DestroyAllLedsMock(void); protected: std::shared_ptr mLinuxTest; std::map> mAllCamerasMock; std::map> mAllKeysMock; + std::map> mAllLedsMock; }; #endif \ No newline at end of file diff --git a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp index cd56856b..ebe37f02 100644 --- a/test/middleware/DeviceManager/src/DeviceManager_Test.cpp +++ b/test/middleware/DeviceManager/src/DeviceManager_Test.cpp @@ -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 monitor = std::make_shared(); + IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor); + std::shared_ptr 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 \ No newline at end of file diff --git a/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h index 9ee60272..56f0a526 100644 --- a/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h +++ b/test/middleware/DeviceManager/tool/include/DeviceManagerTestTool.h @@ -54,8 +54,9 @@ public: void UnInit(void); public: - std::shared_ptr ControlLed(const std::string &ledName, const LedState &state, + std::shared_ptr ControlLed(const std::string &ledName, const LedState &state, const unsigned int &aliveTimeMs, const unsigned int &blinkTimeMs); + void DestoryLedControl(std::shared_ptr &ledControl); protected: void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) override; diff --git a/utils/LedControl/include/LedControl.h b/utils/LedControl/include/LedControl.h index c0c1a1a1..af957861 100644 --- a/utils/LedControl/include/LedControl.h +++ b/utils/LedControl/include/LedControl.h @@ -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 &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 &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 &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 &state); diff --git a/utils/LedControl/src/LedControl.cpp b/utils/LedControl/src/LedControl.cpp index 62fea645..3191ae7c 100644 --- a/utils/LedControl/src/LedControl.cpp +++ b/utils/LedControl/src/LedControl.cpp @@ -14,9 +14,45 @@ */ #include "LedControl.h" #include "ILog.h" +#include +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 &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 &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 &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 &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");