Merge branch 'master-develop' of gitee.com:shenzhen-jiuyilian/ipc into m-develop

This commit is contained in:
Fancy code 2024-05-14 20:05:57 +08:00
commit a1e14a3f27
17 changed files with 376 additions and 139 deletions

View File

@ -102,6 +102,7 @@ public:
VMcuMonitor() = default;
virtual ~VMcuMonitor() = default;
virtual void RecvIpcMissionEvent(std::shared_ptr<VMcuAsk> &recv, const IpcMission &mission);
virtual void RecvMcuHeartBeat(std::shared_ptr<VMcuAsk> &recv);
};
class IMcuManager
{

View File

@ -17,6 +17,9 @@
void VMcuMonitor::RecvIpcMissionEvent(std::shared_ptr<VMcuAsk> &recv, const IpcMission &mission)
{
}
void VMcuMonitor::RecvMcuHeartBeat(std::shared_ptr<VMcuAsk> &recv)
{
}
std::shared_ptr<IMcuManager> &IMcuManager::GetInstance(std::shared_ptr<IMcuManager> *impl)
{
static auto instance = std::make_shared<IMcuManager>();

View File

@ -15,6 +15,43 @@
#include "McuManagerImpl.h"
#include "ILog.h"
#include "UartRecvAsk.h"
class OtherSideSend : public UartRecvAsk, public McuAsk<ASK_RESULT>
{
public:
OtherSideSend(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
const OtherSideSendType &sendType)
: mMcuManager(mcuManager), mSendType(sendType)
{
McuAsk::mSerialNumber = serialNumber;
}
virtual ~OtherSideSend() = default;
protected:
std::shared_ptr<McuManagerImpl> mMcuManager;
public:
const OtherSideSendType mSendType;
};
template <typename T>
class OtherSideSendWithData : public OtherSideSend
{
public:
OtherSideSendWithData(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
const OtherSideSendType &sendType, const T &otherSideData)
: OtherSideSend(mcuManager, serialNumber, sendType), mOtherSideData(otherSideData)
{
}
virtual ~OtherSideSendWithData() = default;
public:
const T mOtherSideData;
};
McuManagerImpl::McuManagerImpl()
{
mMcuAskHandle[OtherSideSendType::SEND_IPC_MISSION] =
std::bind(&McuManagerImpl::McuAskSendIpcMissionHandle, this, _1);
mMcuAskHandle[OtherSideSendType::SEND_HEART_BEAT] = std::bind(&McuManagerImpl::McuAskSendHeartBeatHandle, this, _1);
}
std::shared_ptr<VProtocolBase> McuManagerImpl::SharedFromThis(void)
{
return shared_from_this();
@ -29,11 +66,21 @@ const StatusCode McuManagerImpl::UnInit(void)
{
McuDevice::UnInit();
McuProtocol::UnInit();
mMcuAskList.clear();
return CreateStatusCode(STATUS_CODE_OK);
}
const StatusCode McuManagerImpl::SetMcuMonitor(std::shared_ptr<VMcuMonitor> &monitor)
{
std::lock_guard<std::mutex> locker(mMutex);
mMonitor = monitor;
for (auto ask : mMcuAskList) {
std::shared_ptr<OtherSideSend> data = std::dynamic_pointer_cast<OtherSideSend>(ask);
auto handle = mMcuAskHandle.find(data->mSendType);
if (handle != mMcuAskHandle.end()) {
handle->second(ask);
}
}
mMcuAskList.clear();
return CreateStatusCode(STATUS_CODE_OK);
}
const StatusCode McuManagerImpl::GetIpcMission(std::shared_ptr<VMcuAsk> &ask)
@ -116,32 +163,90 @@ std::shared_ptr<VMcuMonitor> McuManagerImpl::GetMcuMonitor(void)
}
void McuManagerImpl::OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
{
class OtherSideSend : public UartRecvAsk, public McuAsk<ASK_RESULT>
class OtherSideSendV2 : public OtherSideSendWithData<unsigned char>
{
public:
OtherSideSend(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber)
: mMcuManager(mcuManager)
OtherSideSendV2(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
const OtherSideSendType &sendType, const unsigned char &mission)
: OtherSideSendWithData(mcuManager, serialNumber, sendType, mission)
{
mSerialNumber = serialNumber;
}
~OtherSideSend() = default;
~OtherSideSendV2() = default;
void ReplyFinished(const bool result) override
{
if (result) {
mMcuManager->ReplyOtherSideSendIpcMission(mDataReply, mSerialNumber);
}
mMcuManager->ReplyOtherSideSendIpcMission(McuAsk::mDataReply, VMcuAsk::mSerialNumber);
}
std::shared_ptr<McuManagerImpl> mMcuManager;
};
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
std::shared_ptr<McuManagerImpl> manager = std::dynamic_pointer_cast<McuManagerImpl>(SharedFromThis());
std::shared_ptr<VMcuAsk> ask =
std::make_shared<OtherSideSendV2>(manager, serialNumber, OtherSideSendType::SEND_IPC_MISSION, mission);
if (monitor) {
std::shared_ptr<McuManagerImpl> manager = std::dynamic_pointer_cast<McuManagerImpl>(SharedFromThis());
std::shared_ptr<VMcuAsk> ask = std::make_shared<OtherSideSend>(manager, serialNumber);
monitor->RecvIpcMissionEvent(ask, static_cast<IpcMission>(mission));
}
else {
LogWarning("mMonitor is nullptr, AddMcuAsk.\n");
AddMcuAsk(ask);
}
}
void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber)
{
class OtherSideSendV2 : public OtherSideSend
{
public:
OtherSideSendV2(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
const OtherSideSendType &sendType)
: OtherSideSend(mcuManager, serialNumber, sendType)
{
}
~OtherSideSendV2() = default;
void ReplyFinished(const bool result) override
{
LogInfo("Mcu monitor reply heart beat.\n");
mMcuManager->ReplyOtherSideSendHeartBeat(mSerialNumber);
}
};
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
std::shared_ptr<McuManagerImpl> manager = std::dynamic_pointer_cast<McuManagerImpl>(SharedFromThis());
std::shared_ptr<VMcuAsk> ask =
std::make_shared<OtherSideSendV2>(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT);
if (monitor) {
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
monitor->RecvMcuHeartBeat(ask);
}
else {
LogWarning("mMonitor is nullptr, AddMcuAsk.\n");
AddMcuAsk(ask);
}
}
void McuManagerImpl::ReplyOtherSideSendIpcMission(const ASK_RESULT &result, const unsigned int &serialNumber)
{
LogInfo("ReplyOtherSideSendIpcMission\n");
return McuProtocol::ReplyOtherSideSendIpcMission(static_cast<ReplyResult>(result), serialNumber);
McuProtocol::ReplyOtherSideSendIpcMission(static_cast<ReplyResult>(result), serialNumber);
}
void McuManagerImpl::ReplyOtherSideSendHeartBeat(const unsigned int &serialNumber)
{
LogInfo("ReplyOtherSideSendHeartBeat\n");
McuProtocol::ReplyOtherSideSendHearBeat(static_cast<ReplyResult>(ASK_RESULT::SUCCEED), serialNumber);
}
void McuManagerImpl::AddMcuAsk(std::shared_ptr<VMcuAsk> &ask)
{
std::lock_guard<std::mutex> locker(mMutex);
mMcuAskList.push_back(ask);
}
void McuManagerImpl::McuAskSendIpcMissionHandle(std::shared_ptr<VMcuAsk> &ask)
{
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
std::shared_ptr<OtherSideSendWithData<unsigned char>> data =
std::dynamic_pointer_cast<OtherSideSendWithData<unsigned char>>(ask);
if (monitor) {
monitor->RecvIpcMissionEvent(ask, static_cast<IpcMission>(data->mOtherSideData));
}
}
void McuManagerImpl::McuAskSendHeartBeatHandle(std::shared_ptr<VMcuAsk> &ask)
{
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
if (monitor) {
monitor->RecvMcuHeartBeat(ask);
}
}

View File

@ -17,10 +17,22 @@
#include "IMcuManager.h"
#include "McuDevice.h"
#include "McuProtocol.h"
#include <functional>
#include <list>
#include <map>
#include <mutex>
using std::placeholders::_1;
using McuAskHandleFunc = std::function<void(std::shared_ptr<VMcuAsk> &)>;
enum class OtherSideSendType
{
SEND_IPC_MISSION,
SEND_HEART_BEAT,
END
};
class McuManagerImpl : public McuDevice, public McuProtocol, public std::enable_shared_from_this<McuManagerImpl>
{
public:
McuManagerImpl() = default;
McuManagerImpl();
virtual ~McuManagerImpl() = default;
std::shared_ptr<VProtocolBase> SharedFromThis(void) override;
const StatusCode Init(void) override;
@ -42,9 +54,28 @@ private:
private:
void OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission) override;
/**
* @brief The heartbeat packet must be processed by the state machine in the main thread. When the state machine
* blocks/freezes, it can be restored by the external microcontroller after powering off and restarting.
* @param serialNumber
*/
void OtherSideSendHearBeat(const unsigned int &serialNumber) override;
void ReplyOtherSideSendIpcMission(const ASK_RESULT &result, const unsigned int &serialNumber);
void ReplyOtherSideSendHeartBeat(const unsigned int &serialNumber);
private: // About mMcuAskList
void AddMcuAsk(std::shared_ptr<VMcuAsk> &ask);
void McuAskSendIpcMissionHandle(std::shared_ptr<VMcuAsk> &ask);
void McuAskSendHeartBeatHandle(std::shared_ptr<VMcuAsk> &ask);
private:
std::mutex mMutex;
std::weak_ptr<VMcuMonitor> mMonitor;
/**
* @brief If the monitor has not been registered yet, it is necessary to cache the reported messages and report them
* again when the monitor is registered.
*/
std::list<std::shared_ptr<VMcuAsk>> mMcuAskList;
std::map<OtherSideSendType, McuAskHandleFunc> mMcuAskHandle;
};
#endif

View File

@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OTHER_SIDE_ASK_H
#define OTHER_SIDE_ASK_H
#ifndef UART_RECV_ASK_H
#define UART_RECV_ASK_H
#include "McuAskBase.h"
class UartRecvAsk : public McuAskBase
{

View File

@ -64,13 +64,13 @@ public:
std::shared_ptr<LinuxTest> 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<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_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<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
{
@ -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<ASK_RESULT>, 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<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
* 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<IpcMission>, 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<IpcMission>, 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<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)
// --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<ASK_RESULT>, 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<ASK_RESULT>, 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<ASK_RESULT>, 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<ASK_RESULT>, 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<ASK_RESULT>, 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<ASK_RESULT>, 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<ASK_RESULT>, 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<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.
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

View File

@ -20,7 +20,7 @@ include_directories(
aux_source_directory(./src TEST_TOOL_SRC_FILES)
set(TEST_TOOL_TARGET McuManagerTestTool)
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
target_link_libraries(${TEST_TOOL_TARGET} McuProtocolTestTool UartDeviceTestTool LinuxApiMock Log)
target_link_libraries(${TEST_TOOL_TARGET} McuManager McuProtocolTestTool UartDeviceTestTool LinuxApiMock Log)
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
add_custom_target(

View File

@ -34,7 +34,8 @@ public:
void Init(std::shared_ptr<LinuxTest> &mock);
void UnInit(void);
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 MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr<LinuxTest> &mock);

View File

@ -44,9 +44,13 @@ bool McuManagerTestTool::CheckAskExist(const std::shared_ptr<VMcuAsk> &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)
{

View File

@ -31,7 +31,8 @@ public:
virtual ~McuProtocolTestTool() = default;
void Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
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);
private:
@ -70,6 +71,10 @@ private:
const unsigned int &serialNumber);
void OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
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:
static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log);

View File

@ -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<ProtocolMonitor> monitor = std::make_shared<ProtocolMonitor>();
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);
}
void McuProtocolTestTool::MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
{
OtherSideAskHeartBeatHandle(mock, mUartFd, serialNumber);
}
void McuProtocolTestTool::ReadNothingAnyTime(std::shared_ptr<LinuxTest> &mock)
{
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,
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<LinuxTest>
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)
{
printf("%s { 0x%02X", log, *(unsigned char *)buf);

View File

@ -28,6 +28,10 @@ std::shared_ptr<ProtocolMonitor> &ProtocolMonitor::GetInstance(std::shared_ptr<P
}
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)
{
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return()));
@ -41,7 +45,6 @@ void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &te
const short &command,
const void *data,
const short &packetLength) {
//
};
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
.Times(1)

View File

@ -14,48 +14,25 @@
*/
#ifndef PROTOCOL_MONITOR_H
#define PROTOCOL_MONITOR_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "GtestUsing.h"
#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
{
public:
ProtocolMonitor() = default;
virtual ~ProtocolMonitor() = default;
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,
const void *data, const short &packetLength)
{
}
const void *data, const short &packetLength);
};
class ProtocolMonitorTest : public ProtocolMonitor
{

View File

@ -112,9 +112,8 @@ class OtherSideAsk
public:
OtherSideAsk() = default;
virtual ~OtherSideAsk() = default;
virtual void OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
{
}
virtual void OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission);
virtual void OtherSideSendHearBeat(const unsigned int &serialNumber);
};
class VProtocolRecv : public OtherSideReply, public OtherSideAsk
{
@ -148,6 +147,7 @@ protected:
protected:
void ReplyOtherSideSendIpcMission(const ReplyResult &result, const unsigned int &serialNumber);
void ReplyOtherSideSendHearBeat(const ReplyResult &result, const unsigned int &serialNumber);
protected:
size_t GetKeyHeadLength(void) override;

View File

@ -16,6 +16,12 @@
#include "ILog.h"
#include "ProtocolHandle.h"
#include <string.h>
void OtherSideAsk::OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
{
}
void OtherSideAsk::OtherSideSendHearBeat(const unsigned int &serialNumber)
{
}
std::shared_ptr<VProtocolRecv> &VProtocolRecv::GetInstance(std::shared_ptr<VProtocolRecv> *impl)
{
static auto instance = std::make_shared<VProtocolRecv>();
@ -155,6 +161,18 @@ void McuProtocol::ReplyOtherSideSendIpcMission(const ReplyResult &result, const
WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
}
void McuProtocol::ReplyOtherSideSendHearBeat(const ReplyResult &result, const unsigned int &serialNumber)
{
std::shared_ptr<VProtocolContext> NULL_CONTEXT;
// 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));
std::shared_ptr<VProtocolParam> param =
std::make_shared<VProtocolParam>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT);
param->mSerialNumber = serialNumber;
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
}
size_t McuProtocol::GetKeyHeadLength(void)
{
return ProtocolHandle::GetKeyHeadLength();

View File

@ -41,6 +41,8 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr<VProtocolParam> &param) : 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<const unsigned char>(param);
}
void ProtocolHandle::MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr<VProtocolParam> &param)
{
MakeNoUserDataPacket(param);
}
void ProtocolHandle::MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> &param)
{
MakeProtocolData<const unsigned char>(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> ProtocolHandle::CreateProtocolData(const std::shared_ptr<VProtocolParam> &param)

View File

@ -161,13 +161,14 @@ private:
void MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeAskGetPhotosensitivityPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeReplyOtherSideSendIpcMissionPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeReplyOtherSideSendHeartBeatPacket(const std::shared_ptr<VProtocolParam> &param);
template <typename T>
void MakeProtocolData(const std::shared_ptr<VProtocolParam> &param)
{
constexpr int PARAM_DATA_LENGTH = sizeof(T);
std::shared_ptr<ProtocolParam<T>> SetParam = std::dynamic_pointer_cast<ProtocolParam<T>>(param);
if (!SetParam) {
LogError("Invalid param.\n");
LogError("MakeProtocolData::Invalid param.\n");
return;
}
MallocPacketDataBuff(&(SetParam->mData), PARAM_DATA_LENGTH, param->mCommand);