diff --git a/middleware/McuManager/src/McuManagerImpl.cpp b/middleware/McuManager/src/McuManagerImpl.cpp index 59c70473..69fc5389 100644 --- a/middleware/McuManager/src/McuManagerImpl.cpp +++ b/middleware/McuManager/src/McuManagerImpl.cpp @@ -179,6 +179,7 @@ void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber) ~OtherSideSendV2() = default; void ReplyFinished(const bool result) override { + LogInfo("Mcu monitor reply heart beat.\n"); mMcuManager->ReplyOtherSideSendHeartBeat(mSerialNumber); } }; @@ -187,6 +188,7 @@ void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber) std::shared_ptr ask = std::make_shared(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT); if (monitor) { + LogInfo("Mcu manager report heart beat to mcu monitor.\n"); monitor->RecvMcuHeartBeat(ask); } else { diff --git a/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp b/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp index 797707e9..3f911c30 100644 --- a/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp +++ b/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp @@ -64,13 +64,13 @@ public: std::shared_ptr mLinuxTest; }; // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_GetIpcMission +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_GetIpcMission /** * @brief Construct a new test f object * This test is an example that demonstrates how to obtain IpcMission data and add the business code after obtaining the * data in the abstract interface. */ -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission) +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_GetIpcMission) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -104,13 +104,13 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_GetIpcMission2 +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_GetIpcMission2 /** * @brief Construct a new test f object * This test is an example that demonstrates how to obtain IpcMission data and add the business code after obtaining the * data in the abstract interface. */ -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission2) +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_GetIpcMission2) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -144,14 +144,14 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetIpcMission2) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMission +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMission /** * @brief Construct a new test f object * This example demonstrates how to use a monitor to capture event information sent by an MCU. You must assign a value - * to the processing result (mDataReply member) and call the ReplyCompleted function to complete the entire process. + * to the processing result (mDataReply member) and call the ReplyFinished function to complete the entire process. */ constexpr unsigned int TEST_SERIAL_NUMBER = 2; -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMission) +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMission) { class MonitorTest : public VMcuMonitor { @@ -168,15 +168,45 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMissio } }; IMcuManager::GetInstance()->Init(); - OtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER); + MockOtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER); std::shared_ptr monitor = std::make_shared(); IMcuManager::GetInstance()->SetMcuMonitor(monitor); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendHeartBeat +/** + * @brief Construct a new test f object + * This example demonstrates how to use a monitor to capture event information sent by an MCU. You must assign a value + * to the processing result (mDataReply member) and call the ReplyFinished function to complete the entire process. + */ +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendHeartBeat) +{ + class MonitorTest : public VMcuMonitor + { + public: + MonitorTest() = default; + virtual ~MonitorTest() = default; + void RecvMcuHeartBeat(std::shared_ptr &recv) override + { + LogInfo("RecvMcuHeartBeat\n"); + std::shared_ptr> ask = std::dynamic_pointer_cast>(recv); + ask->mDataReply = ASK_RESULT::SUCCEED; + recv->ReplyFinished(true); + EXPECT_EQ(TEST_SERIAL_NUMBER, recv->mSerialNumber); + } + }; + IMcuManager::GetInstance()->Init(); + MockOtherSideAskHeartBeat(mLinuxTest, TEST_SERIAL_NUMBER); + std::shared_ptr monitor = std::make_shared(); + IMcuManager::GetInstance()->SetMcuMonitor(monitor); + std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + IMcuManager::GetInstance()->UnInit(); +} +// ../output_files/test/bin/McuManagerTest +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply) { class McuAskTest : public McuAskBase { @@ -196,8 +226,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_FeedWatchDog -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_FeedWatchDog +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_FeedWatchDog) { class McuAskTest : public McuAskBase { @@ -217,8 +247,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog) { class McuAskTest : public McuAsk, public McuAskBase { @@ -249,8 +279,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatc IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetDateTime -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetDateTime) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetDateTime +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_SetDateTime) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -283,8 +313,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetDateTime) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -316,8 +346,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -349,8 +379,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue) { /** * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the @@ -382,8 +412,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityVal IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMission +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMission) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -417,9 +447,10 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission) * @brief This use case demonstrates that only the serial port was opened and written successfully, and no data was * read. * Run Test: - * ../output_files/test/bin/McuManagerTest --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission_1 + * ../output_files/test/bin/McuManagerTest + * --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMission_1 */ -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission_1) +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMission_1) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -451,8 +482,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission_1) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMission +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMission2) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -483,33 +514,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission) -{ - constexpr unsigned int TEST_SERIAL_NUMBER = 99; - class MonitorTest : public VMcuMonitor - { - public: - MonitorTest() = default; - virtual ~MonitorTest() = default; - void RecvIpcMissionEvent(std::shared_ptr &recv, const IpcMission &mission) override - { - LogInfo("RecvIpcMissionEvent\n"); - std::shared_ptr> ask = std::dynamic_pointer_cast>(recv); - ask->mDataReply = ASK_RESULT::SUCCEED; - recv->ReplyFinished(true); - } - }; - IMcuManager::GetInstance()->Init(); - OtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER); - std::shared_ptr monitor = std::make_shared(); - IMcuManager::GetInstance()->SetMcuMonitor(monitor); - std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - IMcuManager::GetInstance()->UnInit(); -} -// ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_CutOffPowerSupply -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_CutOffPowerSupply) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_CutOffPowerSupply +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_CutOffPowerSupply) { class McuAskTest : public McuAskBaseTestTool { @@ -532,8 +538,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_CutOffPowerSupply) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_FeedWatchDog -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_FeedWatchDog) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_FeedWatchDog +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_FeedWatchDog) { class McuAskTest : public McuAskBaseTestTool { @@ -556,8 +562,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_FeedWatchDog) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -590,8 +596,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDo IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2 -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2 +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -625,8 +631,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDo IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -696,8 +702,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetDataTime -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetDataTime +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetDataTime) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -731,8 +737,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetDataTime2 -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime2) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetDataTime2 +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetDataTime2) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -767,8 +773,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime2) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetPirSensitivity -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -801,8 +807,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetPirSensitivity2 -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity2 +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity2) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -836,8 +842,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2) IMcuManager::GetInstance()->UnInit(); } // ../output_files/test/bin/McuManagerTest -// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMissionFailed -TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed) +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMissionFailed +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMissionFailed) { class McuAskTest : public McuAsk, public McuAskBaseTestTool { @@ -869,4 +875,29 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed) EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted. IMcuManager::GetInstance()->UnInit(); } +// ../output_files/test/bin/McuManagerTest +// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission) +{ + constexpr unsigned int TEST_SERIAL_NUMBER = 99; + class MonitorTest : public VMcuMonitor + { + public: + MonitorTest() = default; + virtual ~MonitorTest() = default; + void RecvIpcMissionEvent(std::shared_ptr &recv, const IpcMission &mission) override + { + LogInfo("RecvIpcMissionEvent\n"); + std::shared_ptr> ask = std::dynamic_pointer_cast>(recv); + ask->mDataReply = ASK_RESULT::SUCCEED; + recv->ReplyFinished(true); + } + }; + IMcuManager::GetInstance()->Init(); + MockOtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER); + std::shared_ptr monitor = std::make_shared(); + IMcuManager::GetInstance()->SetMcuMonitor(monitor); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + IMcuManager::GetInstance()->UnInit(); +} } // namespace McuManagerMockTest \ No newline at end of file diff --git a/test/middleware/McuManager/tool/include/McuManagerTestTool.h b/test/middleware/McuManager/tool/include/McuManagerTestTool.h index 6556a7e9..3c34e3e6 100644 --- a/test/middleware/McuManager/tool/include/McuManagerTestTool.h +++ b/test/middleware/McuManager/tool/include/McuManagerTestTool.h @@ -34,7 +34,8 @@ public: void Init(std::shared_ptr &mock); void UnInit(void); bool CheckAskExist(const std::shared_ptr &ask); - void OtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber); + void MockOtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber); + void MockOtherSideAskHeartBeat(std::shared_ptr &mock, const unsigned int &serialNumber); void MockMcuDeviceOpenFailed(std::shared_ptr &mock); void MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr &mock); diff --git a/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp b/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp index 2f81030f..93bcbff1 100644 --- a/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp +++ b/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp @@ -44,9 +44,13 @@ bool McuManagerTestTool::CheckAskExist(const std::shared_ptr &ask) { return mMcuManagerMock->CheckAskExist(ask); } -void McuManagerTestTool::OtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber) +void McuManagerTestTool::MockOtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber) { - McuProtocolTestTool::OtherSideAskIpcMission(mock, serialNumber); + McuProtocolTestTool::MockOtherSideAskIpcMission(mock, serialNumber); +} +void McuManagerTestTool::MockOtherSideAskHeartBeat(std::shared_ptr &mock, const unsigned int &serialNumber) +{ + McuProtocolTestTool::MockOtherSideAskHeartBeat(mock, serialNumber); } void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr &mock) { diff --git a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h index f53d1a89..34541b2b 100644 --- a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h +++ b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h @@ -31,7 +31,8 @@ public: virtual ~McuProtocolTestTool() = default; void Init(std::shared_ptr &mock, const UartInfo &uart); void UnInit(void); - void OtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber); + void MockOtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber); + void MockOtherSideAskHeartBeat(std::shared_ptr &mock, const unsigned int &serialNumber); void ReadNothingAnyTime(std::shared_ptr &mock); private: @@ -70,6 +71,10 @@ private: const unsigned int &serialNumber); void OtherSideAskIpcMissionInit(std::shared_ptr &mock, const int &uartFd, const unsigned int &serialNumber); + void OtherSideAskHeartBeatHandle(std::shared_ptr &mock, const int &uartFd, + const unsigned int &serialNumber); + void OtherSideAskHeartBeatInit(std::shared_ptr &mock, const int &uartFd, + const unsigned int &serialNumber); private: static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log); diff --git a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp index a0f8325d..17827385 100644 --- a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp +++ b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp @@ -65,6 +65,10 @@ unsigned char REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION_X[] = { 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x01, 0x00, 0x0D, 0x0A, 0xFF, 0xFF}; unsigned char OTHER_SIDE_ASK_SEND_IPC_MISSION_X[] = { 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x01, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; +unsigned char REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT_X[] = { + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x02, 0x00, 0x0C, 0xFF, 0xFF}; +unsigned char OTHER_SIDE_ASK_SEND_HEART_BEAT_X[] = { + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x02, 0x00, 0x0C, 0xFF, 0xFF}; McuProtocolTestTool::McuProtocolTestTool() { mThreadRuning = false; @@ -133,10 +137,14 @@ void McuProtocolTestTool::UnInit(void) std::shared_ptr monitor = std::make_shared(); ProtocolMonitor::GetInstance(&monitor); } -void McuProtocolTestTool::OtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber) +void McuProtocolTestTool::MockOtherSideAskIpcMission(std::shared_ptr &mock, const unsigned int &serialNumber) { OtherSideAskIpcMissionHandle(mock, mUartFd, serialNumber); } +void McuProtocolTestTool::MockOtherSideAskHeartBeat(std::shared_ptr &mock, const unsigned int &serialNumber) +{ + OtherSideAskHeartBeatHandle(mock, mUartFd, serialNumber); +} void McuProtocolTestTool::ReadNothingAnyTime(std::shared_ptr &mock) { static size_t WRITE_COUNT = -1; @@ -228,6 +236,7 @@ void McuProtocolTestTool::ReplySelectTimeOut(std::shared_ptr &mock, c bool McuProtocolTestTool::MonitorProtocolPacket(std::shared_ptr &mock, const int &uartFd, const void *buf, size_t count) { + LogInfo("MonitorProtocolPacket\n"); short head; unsigned int serialNumber; short command; @@ -633,7 +642,6 @@ void McuProtocolTestTool::UnlockProtocolHandle(void) } void McuProtocolTestTool::LockProtocolHandle(void) { - // mMutex.lock(); } void McuProtocolTestTool::UnlockThread(void) @@ -703,6 +711,53 @@ void McuProtocolTestTool::OtherSideAskIpcMissionInit(std::shared_ptr sizeof(OTHER_SIDE_ASK_SEND_IPC_MISSION_X)); } } +void McuProtocolTestTool::OtherSideAskHeartBeatHandle(std::shared_ptr &mock, const int &uartFd, + const unsigned int &serialNumber) +{ + LogInfo("OtherSideAskHeartBeatHandle\n"); + auto handle = [=, &mock](McuProtocolTestTool *testTool) { + testTool->OtherSideAskHeartBeatInit(mock, uartFd, serialNumber); + }; + if (mLockThread.joinable()) { + mLockThread.join(); + } + mLockThread = std::thread(handle, this); +} +void McuProtocolTestTool::OtherSideAskHeartBeatInit(std::shared_ptr &mock, const int &uartFd, + const unsigned int &serialNumber) +{ + LockProtocolHandle(); + unsigned int serialNum = serialNumber; + serialNum = htonl(serialNum); + memcpy(OTHER_SIDE_ASK_SEND_HEART_BEAT_X + PROTOCOL_SERIAL_NUMBER_OFFSET, &serialNum, PROTOCOL_SERIAL_NUMBER_LENGTH); + ResetCheckCode(OTHER_SIDE_ASK_SEND_HEART_BEAT_X, sizeof(OTHER_SIDE_ASK_SEND_HEART_BEAT_X)); + ReplySelectSucceed(mock, uartFd); + constexpr int LEFT_DATA_LENGTH = sizeof(OTHER_SIDE_ASK_SEND_HEART_BEAT_X) - PROTOCOL_DATA_KEY_HEAD_LENGTH; + auto apiReadKeyHead = [=](int fd, void *buf, size_t count) { + memcpy(buf, OTHER_SIDE_ASK_SEND_HEART_BEAT_X, PROTOCOL_DATA_KEY_HEAD_LENGTH); + McuProtocolTestTool::PrintHexadecimalData( + buf, PROTOCOL_DATA_KEY_HEAD_LENGTH, "OtherSideAskHeartBeatInit read:"); + }; + auto apiReadLeftData = [=](int fd, void *buf, size_t count) { + memcpy(buf, OTHER_SIDE_ASK_SEND_HEART_BEAT_X + PROTOCOL_DATA_KEY_HEAD_LENGTH, LEFT_DATA_LENGTH); + McuProtocolTestTool::PrintHexadecimalData(buf, LEFT_DATA_LENGTH, "OtherSideAskHeartBeatInit read:"); + UnlockProtocolHandle(); + }; + EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _)) + .WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(apiReadKeyHead)), Return(PROTOCOL_DATA_KEY_HEAD_LENGTH))) + .WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(apiReadLeftData)), Return(LEFT_DATA_LENGTH))) + .WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING))); + std::shared_ptr test = + std::dynamic_pointer_cast(ProtocolMonitorTest::GetInstance()); + if (test) { + ProtocolMonitorTest::WriteDataOnce(test, + PROTOCOL_HEAD, + serialNumber, + REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT, + nullptr, + sizeof(OTHER_SIDE_ASK_SEND_HEART_BEAT_X)); + } +} void McuProtocolTestTool::PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log) { printf("%s { 0x%02X", log, *(unsigned char *)buf); diff --git a/test/utils/McuProtocol/tool/src/ProtocolMonitor.cpp b/test/utils/McuProtocol/tool/src/ProtocolMonitor.cpp index b6bd8861..ec40cc37 100644 --- a/test/utils/McuProtocol/tool/src/ProtocolMonitor.cpp +++ b/test/utils/McuProtocol/tool/src/ProtocolMonitor.cpp @@ -28,6 +28,10 @@ std::shared_ptr &ProtocolMonitor::GetInstance(std::shared_ptr

&test) { EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return())); @@ -41,7 +45,6 @@ void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr &te const short &command, const void *data, const short &packetLength) { - // }; EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength)) .Times(1) diff --git a/test/utils/McuProtocol/tool/src/ProtocolMonitor.h b/test/utils/McuProtocol/tool/src/ProtocolMonitor.h index 73ce399e..3d49168e 100644 --- a/test/utils/McuProtocol/tool/src/ProtocolMonitor.h +++ b/test/utils/McuProtocol/tool/src/ProtocolMonitor.h @@ -14,48 +14,25 @@ */ #ifndef PROTOCOL_MONITOR_H #define PROTOCOL_MONITOR_H -#include -#include +#include "GtestUsing.h" #include -using ::testing::_; -using ::testing::Action; -using ::testing::ActionInterface; -using ::testing::AnyNumber; -using ::testing::Assign; -using ::testing::AtLeast; -using ::testing::ByMove; -using ::testing::ByRef; -using ::testing::DefaultValue; -using ::testing::DoAll; -using ::testing::DoDefault; -using ::testing::IgnoreResult; -using ::testing::Invoke; -using ::testing::InvokeWithoutArgs; -using ::testing::MakePolymorphicAction; -using ::testing::PolymorphicAction; -using ::testing::Return; -using ::testing::ReturnNew; -using ::testing::ReturnNull; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::ReturnRefOfCopy; -using ::testing::ReturnRoundRobin; -using ::testing::SaveArg; -using ::testing::SetArgPointee; -using ::testing::SetArgumentPointee; -using ::testing::Unused; -using ::testing::WithArgs; -using ::testing::internal::BuiltInDefaultValue; class ProtocolMonitor { public: ProtocolMonitor() = default; virtual ~ProtocolMonitor() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + /** + * @brief This function is used to monitor whether the data written to the serial port matches the protocol and + * belongs to a piling function. + * @param head Whether to match the protocol header. + * @param serialNumber Whether to match the serial number. + * @param command Whether to match command words. + * @param data + * @param packetLength Whether to match the packet length. + */ virtual void MonitorWriteProtocolData(const short &head, const unsigned int &serialNumber, const short &command, - const void *data, const short &packetLength) - { - } + const void *data, const short &packetLength); }; class ProtocolMonitorTest : public ProtocolMonitor { diff --git a/utils/McuProtocol/src/McuProtocol.cpp b/utils/McuProtocol/src/McuProtocol.cpp index dc4766b9..c8ed2342 100644 --- a/utils/McuProtocol/src/McuProtocol.cpp +++ b/utils/McuProtocol/src/McuProtocol.cpp @@ -164,8 +164,10 @@ void McuProtocol::ReplyOtherSideSendIpcMission(const ReplyResult &result, const void McuProtocol::ReplyOtherSideSendHearBeat(const ReplyResult &result, const unsigned int &serialNumber) { std::shared_ptr NULL_CONTEXT; - std::shared_ptr param = std::make_shared>( - PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT, static_cast(result)); + // std::shared_ptr param = std::make_shared>( + // PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT, static_cast(result)); + std::shared_ptr param = + std::make_shared(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT); param->mSerialNumber = serialNumber; std::shared_ptr handle = ProtocolHandle::CreateProtocolData(param); WriteProtocolData( diff --git a/utils/McuProtocol/src/ProtocolHandle.cpp b/utils/McuProtocol/src/ProtocolHandle.cpp index 0cbeb7cb..4c27ba63 100644 --- a/utils/McuProtocol/src/ProtocolHandle.cpp +++ b/utils/McuProtocol/src/ProtocolHandle.cpp @@ -41,6 +41,8 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr ¶m) : m /**************************************************************************************************************************/ mMakePacketFunc[REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION] = std::bind(&ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket, this, _1); + mMakePacketFunc[REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT] = + std::bind(&ProtocolHandle::MakeReplyOtherSideSendHeartBeatPacket, this, _1); } ProtocolHandle::ProtocolHandle(const void *data, const size_t &length) { @@ -166,6 +168,10 @@ void ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket(const std::shared_pt { MakeProtocolData(param); } +void ProtocolHandle::MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr ¶m) +{ + MakeNoUserDataPacket(param); +} void ProtocolHandle::MakeAskControlInfraredLightPacket(const std::shared_ptr ¶m) { MakeProtocolData(param); @@ -232,13 +238,11 @@ void ProtocolHandle::AnalyzeOtherSideSendIpcMissionPacket(const ProtocolPacket & void ProtocolHandle::AnalyzeOtherSideSendHeartBeatPacket(const ProtocolPacket &packet) { LogInfo("AnalyzeOtherSideSendHeartBeatPacket\n"); - unsigned char ipcMission = ReplyOneBytePacketResult(packet); - VProtocolRecv::GetInstance()->OtherSideSendIpcMission(mProtocolSerialNumber, ipcMission); + VProtocolRecv::GetInstance()->OtherSideSendHearBeat(mProtocolSerialNumber); } bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet) { short code = calculate_check_sum(mProtocolData, mProtocolDataLength - CHECK_CODE_LENGTH); - // short packetCode = BigEndianConversion(code); if (code == packet.mCheckCode) { return true; } @@ -247,12 +251,10 @@ bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet) void ProtocolHandle::Init(void) { - // mSerialNumber = 1; } void ProtocolHandle::UnInit(void) { - // mSerialNumber = 1; } std::shared_ptr ProtocolHandle::CreateProtocolData(const std::shared_ptr ¶m) diff --git a/utils/McuProtocol/src/ProtocolHandle.h b/utils/McuProtocol/src/ProtocolHandle.h index 1411ab18..2079ce2f 100644 --- a/utils/McuProtocol/src/ProtocolHandle.h +++ b/utils/McuProtocol/src/ProtocolHandle.h @@ -161,13 +161,14 @@ private: void MakeAskControlInfraredLightPacket(const std::shared_ptr ¶m); void MakeAskGetPhotosensitivityPacket(const std::shared_ptr ¶m); void MakeReplyOtherSideSendIpcMissionPacket(const std::shared_ptr ¶m); + void MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr ¶m); template void MakeProtocolData(const std::shared_ptr ¶m) { constexpr int PARAM_DATA_LENGTH = sizeof(T); std::shared_ptr> SetParam = std::dynamic_pointer_cast>(param); if (!SetParam) { - LogError("Invalid param.\n"); + LogError("MakeProtocolData::Invalid param.\n"); return; } MallocPacketDataBuff(&(SetParam->mData), PARAM_DATA_LENGTH, param->mCommand);