Add:mcu manager.
This commit is contained in:
parent
5057623540
commit
5ef7097863
|
@ -179,6 +179,7 @@ void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber)
|
||||||
~OtherSideSendV2() = default;
|
~OtherSideSendV2() = default;
|
||||||
void ReplyFinished(const bool result) override
|
void ReplyFinished(const bool result) override
|
||||||
{
|
{
|
||||||
|
LogInfo("Mcu monitor reply heart beat.\n");
|
||||||
mMcuManager->ReplyOtherSideSendHeartBeat(mSerialNumber);
|
mMcuManager->ReplyOtherSideSendHeartBeat(mSerialNumber);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -187,6 +188,7 @@ void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber)
|
||||||
std::shared_ptr<VMcuAsk> ask =
|
std::shared_ptr<VMcuAsk> ask =
|
||||||
std::make_shared<OtherSideSendV2>(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT);
|
std::make_shared<OtherSideSendV2>(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT);
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
|
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
||||||
monitor->RecvMcuHeartBeat(ask);
|
monitor->RecvMcuHeartBeat(ask);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -64,13 +64,13 @@ public:
|
||||||
std::shared_ptr<LinuxTest> mLinuxTest;
|
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||||
};
|
};
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../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
|
* @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
|
* 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.
|
* 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../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
|
* @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
|
* 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.
|
* 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../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
|
* @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
|
* 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;
|
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
|
class MonitorTest : public VMcuMonitor
|
||||||
{
|
{
|
||||||
|
@ -168,15 +168,45 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_OtherSideSendIpcMissio
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
IMcuManager::GetInstance()->Init();
|
IMcuManager::GetInstance()->Init();
|
||||||
OtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER);
|
MockOtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER);
|
||||||
std::shared_ptr<VMcuMonitor> monitor = std::make_shared<MonitorTest>();
|
std::shared_ptr<VMcuMonitor> monitor = std::make_shared<MonitorTest>();
|
||||||
IMcuManager::GetInstance()->SetMcuMonitor(monitor);
|
IMcuManager::GetInstance()->SetMcuMonitor(monitor);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendHeartBeat
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply)
|
/**
|
||||||
|
* @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<VMcuAsk> &recv) override
|
||||||
|
{
|
||||||
|
LogInfo("RecvMcuHeartBeat\n");
|
||||||
|
std::shared_ptr<McuAsk<ASK_RESULT>> ask = std::dynamic_pointer_cast<McuAsk<ASK_RESULT>>(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<VMcuMonitor> monitor = std::make_shared<MonitorTest>();
|
||||||
|
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
|
class McuAskTest : public McuAskBase
|
||||||
{
|
{
|
||||||
|
@ -196,8 +226,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_CutOffPowerSupply)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_FeedWatchDog
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_FeedWatchDog
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_FeedWatchDog)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAskBase
|
class McuAskTest : public McuAskBase
|
||||||
{
|
{
|
||||||
|
@ -217,8 +247,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_FeedWatchDog)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatchDog)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBase
|
||||||
{
|
{
|
||||||
|
@ -249,8 +279,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_SetFeedingCycleForWatc
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetDateTime
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetDateTime
|
||||||
TEST_F(McuManagerMockTest, 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_SetPirSensitivity
|
||||||
TEST_F(McuManagerMockTest, 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_ContorlInfraredLight
|
||||||
TEST_F(McuManagerMockTest, 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue
|
||||||
TEST_F(McuManagerMockTest, 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
|
* @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();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMission
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMission)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<IpcMission>, 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
|
* @brief This use case demonstrates that only the serial port was opened and written successfully, and no data was
|
||||||
* read.
|
* read.
|
||||||
* Run Test:
|
* 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<IpcMission>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -451,8 +482,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission_1)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMission
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMission2)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -483,33 +514,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_CutOffPowerSupply
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_OtherSideSendIpcMission)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_CutOffPowerSupply)
|
||||||
{
|
|
||||||
constexpr unsigned int TEST_SERIAL_NUMBER = 99;
|
|
||||||
class MonitorTest : public VMcuMonitor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MonitorTest() = default;
|
|
||||||
virtual ~MonitorTest() = default;
|
|
||||||
void RecvIpcMissionEvent(std::shared_ptr<VMcuAsk> &recv, const IpcMission &mission) override
|
|
||||||
{
|
|
||||||
LogInfo("RecvIpcMissionEvent\n");
|
|
||||||
std::shared_ptr<McuAsk<ASK_RESULT>> ask = std::dynamic_pointer_cast<McuAsk<ASK_RESULT>>(recv);
|
|
||||||
ask->mDataReply = ASK_RESULT::SUCCEED;
|
|
||||||
recv->ReplyFinished(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
IMcuManager::GetInstance()->Init();
|
|
||||||
OtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER);
|
|
||||||
std::shared_ptr<VMcuMonitor> monitor = std::make_shared<MonitorTest>();
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAskBaseTestTool
|
class McuAskTest : public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -532,8 +538,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_CutOffPowerSupply)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_FeedWatchDog
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_FeedWatchDog
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_FeedWatchDog)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_FeedWatchDog)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAskBaseTestTool
|
class McuAskTest : public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -556,8 +562,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_FeedWatchDog)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -590,8 +596,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDo
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDog2)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -625,8 +631,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetFeedingCycleForWatchDo
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -696,8 +702,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_STRESS_MultiThreadWrite)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetDataTime
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetDataTime
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetDataTime)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -731,8 +737,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetDataTime2
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetDataTime2
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime2)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetDataTime2)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -767,8 +773,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime2)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetPirSensitivity
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -801,8 +807,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_SetPirSensitivity2
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity2
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_SetPirSensitivity2)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<ASK_RESULT>, public McuAskBaseTestTool
|
||||||
{
|
{
|
||||||
|
@ -836,8 +842,8 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2)
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMissionFailed
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_GetIpcMissionFailed
|
||||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
|
||||||
{
|
{
|
||||||
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
|
class McuAskTest : public McuAsk<IpcMission>, 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.
|
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
|
||||||
IMcuManager::GetInstance()->UnInit();
|
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<VMcuAsk> &recv, const IpcMission &mission) override
|
||||||
|
{
|
||||||
|
LogInfo("RecvIpcMissionEvent\n");
|
||||||
|
std::shared_ptr<McuAsk<ASK_RESULT>> ask = std::dynamic_pointer_cast<McuAsk<ASK_RESULT>>(recv);
|
||||||
|
ask->mDataReply = ASK_RESULT::SUCCEED;
|
||||||
|
recv->ReplyFinished(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
IMcuManager::GetInstance()->Init();
|
||||||
|
MockOtherSideAskIpcMission(mLinuxTest, TEST_SERIAL_NUMBER);
|
||||||
|
std::shared_ptr<VMcuMonitor> monitor = std::make_shared<MonitorTest>();
|
||||||
|
IMcuManager::GetInstance()->SetMcuMonitor(monitor);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
|
IMcuManager::GetInstance()->UnInit();
|
||||||
|
}
|
||||||
} // namespace McuManagerMockTest
|
} // namespace McuManagerMockTest
|
|
@ -34,7 +34,8 @@ public:
|
||||||
void Init(std::shared_ptr<LinuxTest> &mock);
|
void Init(std::shared_ptr<LinuxTest> &mock);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
||||||
void OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
void MockOtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
|
void MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
void MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock);
|
void MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock);
|
||||||
void MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr<LinuxTest> &mock);
|
void MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr<LinuxTest> &mock);
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,13 @@ bool McuManagerTestTool::CheckAskExist(const std::shared_ptr<VMcuAsk> &ask)
|
||||||
{
|
{
|
||||||
return mMcuManagerMock->CheckAskExist(ask);
|
return mMcuManagerMock->CheckAskExist(ask);
|
||||||
}
|
}
|
||||||
void McuManagerTestTool::OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
void McuManagerTestTool::MockOtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
||||||
{
|
{
|
||||||
McuProtocolTestTool::OtherSideAskIpcMission(mock, serialNumber);
|
McuProtocolTestTool::MockOtherSideAskIpcMission(mock, serialNumber);
|
||||||
|
}
|
||||||
|
void McuManagerTestTool::MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
McuProtocolTestTool::MockOtherSideAskHeartBeat(mock, serialNumber);
|
||||||
}
|
}
|
||||||
void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock)
|
void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,8 @@ public:
|
||||||
virtual ~McuProtocolTestTool() = default;
|
virtual ~McuProtocolTestTool() = default;
|
||||||
void Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
|
void Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
void OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
void MockOtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
|
void MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
void ReadNothingAnyTime(std::shared_ptr<LinuxTest> &mock);
|
void ReadNothingAnyTime(std::shared_ptr<LinuxTest> &mock);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -70,6 +71,10 @@ private:
|
||||||
const unsigned int &serialNumber);
|
const unsigned int &serialNumber);
|
||||||
void OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
void OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
const unsigned int &serialNumber);
|
const unsigned int &serialNumber);
|
||||||
|
void OtherSideAskHeartBeatHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
const unsigned int &serialNumber);
|
||||||
|
void OtherSideAskHeartBeatInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
const unsigned int &serialNumber);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log);
|
static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log);
|
||||||
|
|
|
@ -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};
|
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x01, 0x00, 0x0D, 0x0A, 0xFF, 0xFF};
|
||||||
unsigned char OTHER_SIDE_ASK_SEND_IPC_MISSION_X[] = {
|
unsigned char OTHER_SIDE_ASK_SEND_IPC_MISSION_X[] = {
|
||||||
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x01, 0x00, 0x0D, 0x01, 0xFF, 0xFF};
|
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()
|
McuProtocolTestTool::McuProtocolTestTool()
|
||||||
{
|
{
|
||||||
mThreadRuning = false;
|
mThreadRuning = false;
|
||||||
|
@ -133,10 +137,14 @@ void McuProtocolTestTool::UnInit(void)
|
||||||
std::shared_ptr<ProtocolMonitor> monitor = std::make_shared<ProtocolMonitor>();
|
std::shared_ptr<ProtocolMonitor> monitor = std::make_shared<ProtocolMonitor>();
|
||||||
ProtocolMonitor::GetInstance(&monitor);
|
ProtocolMonitor::GetInstance(&monitor);
|
||||||
}
|
}
|
||||||
void McuProtocolTestTool::OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
void McuProtocolTestTool::MockOtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
||||||
{
|
{
|
||||||
OtherSideAskIpcMissionHandle(mock, mUartFd, serialNumber);
|
OtherSideAskIpcMissionHandle(mock, mUartFd, serialNumber);
|
||||||
}
|
}
|
||||||
|
void McuProtocolTestTool::MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
OtherSideAskHeartBeatHandle(mock, mUartFd, serialNumber);
|
||||||
|
}
|
||||||
void McuProtocolTestTool::ReadNothingAnyTime(std::shared_ptr<LinuxTest> &mock)
|
void McuProtocolTestTool::ReadNothingAnyTime(std::shared_ptr<LinuxTest> &mock)
|
||||||
{
|
{
|
||||||
static size_t WRITE_COUNT = -1;
|
static size_t WRITE_COUNT = -1;
|
||||||
|
@ -228,6 +236,7 @@ void McuProtocolTestTool::ReplySelectTimeOut(std::shared_ptr<LinuxTest> &mock, c
|
||||||
bool McuProtocolTestTool::MonitorProtocolPacket(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
|
bool McuProtocolTestTool::MonitorProtocolPacket(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
|
LogInfo("MonitorProtocolPacket\n");
|
||||||
short head;
|
short head;
|
||||||
unsigned int serialNumber;
|
unsigned int serialNumber;
|
||||||
short command;
|
short command;
|
||||||
|
@ -633,7 +642,6 @@ void McuProtocolTestTool::UnlockProtocolHandle(void)
|
||||||
}
|
}
|
||||||
void McuProtocolTestTool::LockProtocolHandle(void)
|
void McuProtocolTestTool::LockProtocolHandle(void)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
mMutex.lock();
|
mMutex.lock();
|
||||||
}
|
}
|
||||||
void McuProtocolTestTool::UnlockThread(void)
|
void McuProtocolTestTool::UnlockThread(void)
|
||||||
|
@ -703,6 +711,53 @@ void McuProtocolTestTool::OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest>
|
||||||
sizeof(OTHER_SIDE_ASK_SEND_IPC_MISSION_X));
|
sizeof(OTHER_SIDE_ASK_SEND_IPC_MISSION_X));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void McuProtocolTestTool::OtherSideAskHeartBeatHandle(std::shared_ptr<LinuxTest> &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<LinuxTest> &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<ProtocolMonitorTest> test =
|
||||||
|
std::dynamic_pointer_cast<ProtocolMonitorTest>(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)
|
void McuProtocolTestTool::PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log)
|
||||||
{
|
{
|
||||||
printf("%s { 0x%02X", log, *(unsigned char *)buf);
|
printf("%s { 0x%02X", log, *(unsigned char *)buf);
|
||||||
|
|
|
@ -28,6 +28,10 @@ std::shared_ptr<ProtocolMonitor> &ProtocolMonitor::GetInstance(std::shared_ptr<P
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
void ProtocolMonitor::MonitorWriteProtocolData(const short &head, const unsigned int &serialNumber,
|
||||||
|
const short &command, const void *data, const short &packetLength)
|
||||||
|
{
|
||||||
|
}
|
||||||
void ProtocolMonitorTest::Init(std::shared_ptr<ProtocolMonitorTest> &test)
|
void ProtocolMonitorTest::Init(std::shared_ptr<ProtocolMonitorTest> &test)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return()));
|
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return()));
|
||||||
|
@ -41,7 +45,6 @@ void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &te
|
||||||
const short &command,
|
const short &command,
|
||||||
const void *data,
|
const void *data,
|
||||||
const short &packetLength) {
|
const short &packetLength) {
|
||||||
//
|
|
||||||
};
|
};
|
||||||
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
|
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
|
||||||
.Times(1)
|
.Times(1)
|
||||||
|
|
|
@ -14,48 +14,25 @@
|
||||||
*/
|
*/
|
||||||
#ifndef PROTOCOL_MONITOR_H
|
#ifndef PROTOCOL_MONITOR_H
|
||||||
#define PROTOCOL_MONITOR_H
|
#define PROTOCOL_MONITOR_H
|
||||||
#include <gmock/gmock.h>
|
#include "GtestUsing.h"
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
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
|
class ProtocolMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProtocolMonitor() = default;
|
ProtocolMonitor() = default;
|
||||||
virtual ~ProtocolMonitor() = default;
|
virtual ~ProtocolMonitor() = default;
|
||||||
static std::shared_ptr<ProtocolMonitor> &GetInstance(std::shared_ptr<ProtocolMonitor> *impl = nullptr);
|
static std::shared_ptr<ProtocolMonitor> &GetInstance(std::shared_ptr<ProtocolMonitor> *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,
|
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
|
class ProtocolMonitorTest : public ProtocolMonitor
|
||||||
{
|
{
|
||||||
|
|
|
@ -164,8 +164,10 @@ void McuProtocol::ReplyOtherSideSendIpcMission(const ReplyResult &result, const
|
||||||
void McuProtocol::ReplyOtherSideSendHearBeat(const ReplyResult &result, const unsigned int &serialNumber)
|
void McuProtocol::ReplyOtherSideSendHearBeat(const ReplyResult &result, const unsigned int &serialNumber)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VProtocolContext> NULL_CONTEXT;
|
std::shared_ptr<VProtocolContext> NULL_CONTEXT;
|
||||||
std::shared_ptr<VProtocolParam> param = std::make_shared<ProtocolParam<const unsigned char>>(
|
// std::shared_ptr<VProtocolParam> param = std::make_shared<ProtocolParam<const unsigned char>>(
|
||||||
PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT, static_cast<const unsigned char>(result));
|
// PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT, static_cast<const unsigned char>(result));
|
||||||
|
std::shared_ptr<VProtocolParam> param =
|
||||||
|
std::make_shared<VProtocolParam>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT);
|
||||||
param->mSerialNumber = serialNumber;
|
param->mSerialNumber = serialNumber;
|
||||||
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
||||||
WriteProtocolData(
|
WriteProtocolData(
|
||||||
|
|
|
@ -41,6 +41,8 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr<VProtocolParam> ¶m) : m
|
||||||
/**************************************************************************************************************************/
|
/**************************************************************************************************************************/
|
||||||
mMakePacketFunc[REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION] =
|
mMakePacketFunc[REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION] =
|
||||||
std::bind(&ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket, this, _1);
|
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)
|
ProtocolHandle::ProtocolHandle(const void *data, const size_t &length)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +168,10 @@ void ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket(const std::shared_pt
|
||||||
{
|
{
|
||||||
MakeProtocolData<const unsigned char>(param);
|
MakeProtocolData<const unsigned char>(param);
|
||||||
}
|
}
|
||||||
|
void ProtocolHandle::MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
|
{
|
||||||
|
MakeNoUserDataPacket(param);
|
||||||
|
}
|
||||||
void ProtocolHandle::MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
void ProtocolHandle::MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
{
|
{
|
||||||
MakeProtocolData<const unsigned char>(param);
|
MakeProtocolData<const unsigned char>(param);
|
||||||
|
@ -232,13 +238,11 @@ void ProtocolHandle::AnalyzeOtherSideSendIpcMissionPacket(const ProtocolPacket &
|
||||||
void ProtocolHandle::AnalyzeOtherSideSendHeartBeatPacket(const ProtocolPacket &packet)
|
void ProtocolHandle::AnalyzeOtherSideSendHeartBeatPacket(const ProtocolPacket &packet)
|
||||||
{
|
{
|
||||||
LogInfo("AnalyzeOtherSideSendHeartBeatPacket\n");
|
LogInfo("AnalyzeOtherSideSendHeartBeatPacket\n");
|
||||||
unsigned char ipcMission = ReplyOneBytePacketResult(packet);
|
VProtocolRecv::GetInstance()->OtherSideSendHearBeat(mProtocolSerialNumber);
|
||||||
VProtocolRecv::GetInstance()->OtherSideSendIpcMission(mProtocolSerialNumber, ipcMission);
|
|
||||||
}
|
}
|
||||||
bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet)
|
bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet)
|
||||||
{
|
{
|
||||||
short code = calculate_check_sum(mProtocolData, mProtocolDataLength - CHECK_CODE_LENGTH);
|
short code = calculate_check_sum(mProtocolData, mProtocolDataLength - CHECK_CODE_LENGTH);
|
||||||
// short packetCode = BigEndianConversion(code);
|
|
||||||
if (code == packet.mCheckCode) {
|
if (code == packet.mCheckCode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -247,12 +251,10 @@ bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet)
|
||||||
|
|
||||||
void ProtocolHandle::Init(void)
|
void ProtocolHandle::Init(void)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
mSerialNumber = 1;
|
mSerialNumber = 1;
|
||||||
}
|
}
|
||||||
void ProtocolHandle::UnInit(void)
|
void ProtocolHandle::UnInit(void)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
mSerialNumber = 1;
|
mSerialNumber = 1;
|
||||||
}
|
}
|
||||||
std::shared_ptr<ProtocolHandle> ProtocolHandle::CreateProtocolData(const std::shared_ptr<VProtocolParam> ¶m)
|
std::shared_ptr<ProtocolHandle> ProtocolHandle::CreateProtocolData(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
|
|
|
@ -161,13 +161,14 @@ private:
|
||||||
void MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
void MakeAskGetPhotosensitivityPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeAskGetPhotosensitivityPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
void MakeReplyOtherSideSendIpcMissionPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeReplyOtherSideSendIpcMissionPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
|
void MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void MakeProtocolData(const std::shared_ptr<VProtocolParam> ¶m)
|
void MakeProtocolData(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
{
|
{
|
||||||
constexpr int PARAM_DATA_LENGTH = sizeof(T);
|
constexpr int PARAM_DATA_LENGTH = sizeof(T);
|
||||||
std::shared_ptr<ProtocolParam<T>> SetParam = std::dynamic_pointer_cast<ProtocolParam<T>>(param);
|
std::shared_ptr<ProtocolParam<T>> SetParam = std::dynamic_pointer_cast<ProtocolParam<T>>(param);
|
||||||
if (!SetParam) {
|
if (!SetParam) {
|
||||||
LogError("Invalid param.\n");
|
LogError("MakeProtocolData::Invalid param.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MallocPacketDataBuff(&(SetParam->mData), PARAM_DATA_LENGTH, param->mCommand);
|
MallocPacketDataBuff(&(SetParam->mData), PARAM_DATA_LENGTH, param->mCommand);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user