mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Add:Feed watch dog protocol.
This commit is contained in:
parent
4a904e004e
commit
2feccc7d36
|
@ -185,7 +185,7 @@ void McuDevice::AddMcuAsk(std::shared_ptr<VMcuAsk> &ask)
|
|||
mAllAsk.push_back(ask);
|
||||
}
|
||||
}
|
||||
void McuDevice::SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<VMcuAsk> &ask)
|
||||
bool McuDevice::SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<VMcuAsk> &ask)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(mMutex);
|
||||
for (auto iter = mAllAsk.begin(); iter != mAllAsk.end(); ++iter) {
|
||||
|
@ -196,10 +196,11 @@ void McuDevice::SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<V
|
|||
}
|
||||
if (serialNumber == listData->mSerialNumber) {
|
||||
ask = listData;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LogWarning("Can't find mcu ask recork.\n");
|
||||
return false;
|
||||
}
|
||||
void McuDevice::DeleteMcuAsk(std::shared_ptr<VMcuAsk> &ask)
|
||||
{
|
||||
|
|
|
@ -39,15 +39,15 @@ public:
|
|||
void DeviceRecvThread(void);
|
||||
void McuAskHandleThread(void);
|
||||
|
||||
private:
|
||||
protected:
|
||||
void DeviceRecvData(const char *keyHead, const size_t headLength);
|
||||
void AddMcuAsk(std::shared_ptr<VMcuAsk> &ask);
|
||||
void SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<VMcuAsk> &ask);
|
||||
bool SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<VMcuAsk> &ask);
|
||||
void DeleteMcuAsk(std::shared_ptr<VMcuAsk> &ask);
|
||||
void DeleteAllAsk(void);
|
||||
void TraverseCheckAllAsk(void);
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::mutex mMutex;
|
||||
void *mUartDevice;
|
||||
std::thread mUartRecvThread;
|
||||
|
|
|
@ -139,6 +139,26 @@ 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)
|
||||
{
|
||||
class McuAskTest : public McuAskBase
|
||||
{
|
||||
public:
|
||||
McuAskTest()
|
||||
: McuAskBase(McuAskBlock::UNRELATED, McuAskReply::NEED_NOT_REPLY) {} // using McuAskReply::NEED_NOT_REPLY
|
||||
virtual ~McuAskTest() = default;
|
||||
};
|
||||
IMcuManager::GetInstance()->Init();
|
||||
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskTest>();
|
||||
StatusCode code = IMcuManager::GetInstance()->FeedWatchDog(ask);
|
||||
if (IsCodeOK(code) == true) {
|
||||
LogInfo("Write data to mcu succeed.\n");
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/McuManagerTest
|
||||
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMission
|
||||
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
|
||||
{
|
||||
|
@ -164,8 +184,7 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
|
|||
std::shared_ptr<McuAskBaseTestTool> testTool = std::dynamic_pointer_cast<McuAskBaseTestTool>(ask);
|
||||
testTool->McuAskDefaultFeatures(testTool);
|
||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||
constexpr int NO_USER_USING_AFTER_ASK = 2; // ask and testTool
|
||||
EXPECT_EQ(ask.use_count(), NO_USER_USING_AFTER_ASK); // TODO: neet to improve.
|
||||
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/McuManagerTest
|
||||
|
@ -195,8 +214,7 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission2)
|
|||
testTool->McuAskDefaultFeatures(testTool);
|
||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
constexpr int NO_USER_USING_AFTER_ASK = 2; // ask and testTool
|
||||
EXPECT_EQ(ask.use_count(), NO_USER_USING_AFTER_ASK);
|
||||
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
}
|
||||
// ../output_files/test/bin/McuManagerTest
|
||||
|
@ -218,8 +236,7 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_CutOffPowerSupply)
|
|||
std::shared_ptr<McuAskBaseTestTool> testTool = std::dynamic_pointer_cast<McuAskBaseTestTool>(ask);
|
||||
testTool->McuAskDefaultFeatures(testTool);
|
||||
StatusCode code = IMcuManager::GetInstance()->CutOffPowerSupply(ask);
|
||||
constexpr int NO_USER_USING_AFTER_ASK = 2; // ask and testTool
|
||||
EXPECT_EQ(ask.use_count(), NO_USER_USING_AFTER_ASK);
|
||||
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
|
||||
EXPECT_EQ(code.mStatusCode, STATUS_CODE_OK); // STATUS_CODE_OK means write data to mcu succeed.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
IMcuManager::GetInstance()->UnInit();
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
McuManagerImplTest() = default;
|
||||
virtual ~McuManagerImplTest() = default;
|
||||
MOCK_METHOD1(DeleteMcuAsk, void(std::shared_ptr<VMcuAsk> &));
|
||||
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
||||
};
|
||||
class McuManagerTestTool : virtual public McuProtocolTestTool
|
||||
{
|
||||
|
@ -62,6 +63,7 @@ public:
|
|||
virtual ~McuManagerTestTool() = default;
|
||||
void Init(std::shared_ptr<LinuxTest> &mock);
|
||||
void UnInit(void);
|
||||
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
||||
|
||||
private:
|
||||
std::shared_ptr<McuManagerImplTest> mMcuManagerMock;
|
||||
|
|
20
test/middleware/McuManager/tool/src/McuManagerImplTest.cpp
Normal file
20
test/middleware/McuManager/tool/src/McuManagerImplTest.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "McuManagerTestTool.h"
|
||||
bool McuManagerImplTest::CheckAskExist(const std::shared_ptr<VMcuAsk> &ask)
|
||||
{
|
||||
std::shared_ptr<VMcuAsk> result;
|
||||
return SearchMcuAsk(ask->mSerialNumber, result);
|
||||
}
|
|
@ -28,7 +28,7 @@ void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
|||
{
|
||||
LogInfo("McuManagerTestTool::Init\n");
|
||||
mMcuManagerMock = std::make_shared<McuManagerImplTest>();
|
||||
EXPECT_CALL(*mMcuManagerMock.get(), DeleteMcuAsk(_)).Times(500);
|
||||
// EXPECT_CALL(*mMcuManagerMock.get(), DeleteMcuAsk(_)).Times(500);
|
||||
OverrideMcuManagerMakePtrObject();
|
||||
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
||||
std::shared_ptr<McuManagerMakePtrTest> test = std::dynamic_pointer_cast<McuManagerMakePtrTest>(tmp);
|
||||
|
@ -49,4 +49,8 @@ void McuManagerTestTool::UnInit(void)
|
|||
std::shared_ptr<McuManagerMakePtr> impl = std::make_shared<McuManagerMakePtr>();
|
||||
McuManagerMakePtr::GetInstance(&impl);
|
||||
UartDeviceTestTool::UnregisterUartDevice(gUartDevice);
|
||||
}
|
||||
bool McuManagerTestTool::CheckAskExist(const std::shared_ptr<VMcuAsk> &ask)
|
||||
{
|
||||
return mMcuManagerMock->CheckAskExist(ask);
|
||||
}
|
|
@ -24,6 +24,7 @@ const unsigned char REPLY_IPC_MISSION[] = {
|
|||
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xAA, 0x89};
|
||||
const unsigned char ASK_CUT_OFF_POWER_SUPPLY[] = {
|
||||
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x02, 0x00, 0x0C, 0x81, 0x88};
|
||||
const unsigned char ASK_FEED_WATCH_DOG[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x03, 0x00, 0x0C, 0xD0, 0x48};
|
||||
void McuProtocolTestTool::Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart)
|
||||
{
|
||||
int uartFd = GetDeviceMockFd(uart);
|
||||
|
@ -39,6 +40,10 @@ void McuProtocolTestTool::Init(std::shared_ptr<LinuxTest> &mock, const UartInfo
|
|||
LogInfo("Set ASK_CUT_OFF_POWER_SUPPLY\n");
|
||||
// IpcMissionProtocolInit(mock, uartFd);
|
||||
}
|
||||
if (sizeof(ASK_FEED_WATCH_DOG) == count && memcmp(ASK_FEED_WATCH_DOG, buf, count) == 0) {
|
||||
LogInfo("Set ASK_FEED_WATCH_DOG\n");
|
||||
// IpcMissionProtocolInit(mock, uartFd);
|
||||
}
|
||||
};
|
||||
EXPECT_CALL(*mock.get(), fx_write(uartFd, _, _))
|
||||
.WillRepeatedly(
|
||||
|
|
|
@ -30,6 +30,8 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr<VProtocolParam> ¶m) : m
|
|||
mMakePacketFunc[ASK_IPC_MISSION] = std::bind(&ProtocolHandle::MakeAskIpcMissionPacket, this, std::placeholders::_1);
|
||||
mMakePacketFunc[ASK_CUT_OFF_PWOER_SUPPLY] =
|
||||
std::bind(&ProtocolHandle::MakeAskCutOffPowerSupplyPacket, this, std::placeholders::_1);
|
||||
mMakePacketFunc[ASK_FEED_WATCH_DOG] =
|
||||
std::bind(&ProtocolHandle::MakeAskFeedWatchDogPacket, this, std::placeholders::_1);
|
||||
}
|
||||
ProtocolHandle::ProtocolHandle(const void *data, const size_t &length)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user