mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Fixed:McuManager reply what recv.
This commit is contained in:
parent
fad78bd4a4
commit
784d3a9b1d
57
doc/develop_standard.md
Normal file
57
doc/develop_standard.md
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# 1. SDK开发规范
|
||||||
|
|
||||||
|
## 1.1. 编码规范
|
||||||
|
|
||||||
|
### 1.1.1. 指针/智能指针
|
||||||
|
|
||||||
|
* C++编码只能使用智能指针;
|
||||||
|
* 指针遵循谁使用谁进行“非空”判断,且无比使用前进行“非空”判断;
|
||||||
|
* 智能指针经过转换后务必进行“非空”判断;
|
||||||
|
|
||||||
|
理论上,**明显不可能为空的指针,可以不进行“非空”判断**,可以不进行“非空”判断的场景:
|
||||||
|
|
||||||
|
```
|
||||||
|
void McuManagerImpl::OtherSideSendIpcMission(const unsigned int &serialNumber, const unsigned char &mission)
|
||||||
|
{
|
||||||
|
class McuRecvIpcMission : public McuRecvImpl, public McuRecv<unsigned char>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuRecvIpcMission(std::shared_ptr<McuManagerImpl> &mcuManager, const unsigned int &serialNumber,
|
||||||
|
const OtherSideSendType &sendType, const unsigned char &mission)
|
||||||
|
: McuRecvImpl(serialNumber, sendType)
|
||||||
|
{
|
||||||
|
McuRecv::mDataRecvReply = mission;
|
||||||
|
McuRecvImpl::mMcuManager = mcuManager;
|
||||||
|
}
|
||||||
|
~McuRecvIpcMission() = default;
|
||||||
|
void ReplyFinished(const bool result) override
|
||||||
|
{
|
||||||
|
// 此处可以不进行“非空”判断,该值在有限范围内(OtherSideSendIpcMission函数内部)就能看出是否为空
|
||||||
|
McuRecvImpl::mMcuManager->ReplyOtherSideSendIpcMission(ASK_RESULT::SUCCEED, McuRecvImpl::mSerialNumber);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
|
||||||
|
std::shared_ptr<McuManagerImpl> manager = std::dynamic_pointer_cast<McuManagerImpl>(SharedFromThis());
|
||||||
|
std::shared_ptr<VMcuRecv> recv =
|
||||||
|
std::make_shared<McuRecvIpcMission>(manager, serialNumber, OtherSideSendType::SEND_IPC_MISSION, mission);
|
||||||
|
if (monitor) {
|
||||||
|
monitor->RecvIpcMissionEvent(recv, static_cast<IpcMission>(mission));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||||
|
AddMcuRecv(recv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**没有进行“非空”判断的代码,应该开发测试用例,保证“空指针”的报错。**
|
||||||
|
|
||||||
|
### 1.1.2. 注释
|
||||||
|
|
||||||
|
* 注释必须使用英文,且使用翻译器翻译;
|
||||||
|
  避免编码问题导致的乱码,且需要保证阅读困难时可使用翻译器翻译成可读的中文;
|
||||||
|
**注:** 注释翻译工具使用[百度翻译](https://fanyi.baidu.com/);
|
||||||
|
|
||||||
|
### 1.1.3. C++继承
|
||||||
|
|
||||||
|
* 子类使用父类的函数时,函数前必须加父类名,降低阅读难度,没有父类名的一律为本类函数(有可能是虚函数);
|
|
@ -133,8 +133,8 @@ public:
|
||||||
VMcuMonitor() = default;
|
VMcuMonitor() = default;
|
||||||
virtual ~VMcuMonitor() = default;
|
virtual ~VMcuMonitor() = default;
|
||||||
virtual void RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission);
|
virtual void RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission);
|
||||||
virtual void RecvMcuHeartBeat(std::shared_ptr<VMcuRecv> &recv);
|
virtual void RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv);
|
||||||
virtual void RecvGetIntervalStart(std::shared_ptr<VMcuRecv> &recv);
|
virtual void RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv);
|
||||||
virtual void RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv);
|
virtual void RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv);
|
||||||
virtual void RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv);
|
virtual void RecvGetPirSensitivity(std::shared_ptr<VMcuRecv> &recv);
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,10 +52,10 @@ void VMcuRecv::ReplyFinished(const bool result)
|
||||||
void VMcuMonitor::RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission)
|
void VMcuMonitor::RecvIpcMissionEvent(std::shared_ptr<VMcuRecv> &recv, const IpcMission &mission)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void VMcuMonitor::RecvMcuHeartBeat(std::shared_ptr<VMcuRecv> &recv)
|
void VMcuMonitor::RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void VMcuMonitor::RecvGetIntervalStart(std::shared_ptr<VMcuRecv> &recv)
|
void VMcuMonitor::RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void VMcuMonitor::RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv)
|
void VMcuMonitor::RecvGetDateTime(std::shared_ptr<VMcuRecv> &recv)
|
||||||
|
|
|
@ -199,7 +199,7 @@ void McuManagerImpl::OtherSideSendHearBeat(const unsigned int &serialNumber)
|
||||||
std::make_shared<McuRecvHeartBeat>(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT);
|
std::make_shared<McuRecvHeartBeat>(manager, serialNumber, OtherSideSendType::SEND_HEART_BEAT);
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
||||||
monitor->RecvMcuHeartBeat(recv);
|
monitor->RecvMcuHeartBeatEvent(recv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||||
|
@ -220,6 +220,7 @@ void McuManagerImpl::OtherSideSendGetIntervalStart(const unsigned int &serialNum
|
||||||
~McuRecvGetIntervalStart() = default;
|
~McuRecvGetIntervalStart() = default;
|
||||||
void ReplyFinished(const bool result) override
|
void ReplyFinished(const bool result) override
|
||||||
{
|
{
|
||||||
|
LogInfo("OtherSideSendGetIntervalStart finised.\n");
|
||||||
McuRecvImpl::mMcuManager->ReplyOtherSideSendGetIntervalStart(mDataRecvReply, McuRecvImpl::mSerialNumber);
|
McuRecvImpl::mMcuManager->ReplyOtherSideSendGetIntervalStart(mDataRecvReply, McuRecvImpl::mSerialNumber);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -228,8 +229,8 @@ void McuManagerImpl::OtherSideSendGetIntervalStart(const unsigned int &serialNum
|
||||||
std::shared_ptr<VMcuRecv> recv =
|
std::shared_ptr<VMcuRecv> recv =
|
||||||
std::make_shared<McuRecvGetIntervalStart>(manager, serialNumber, OtherSideSendType::GET_INTERVAL_START);
|
std::make_shared<McuRecvGetIntervalStart>(manager, serialNumber, OtherSideSendType::GET_INTERVAL_START);
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
LogInfo("Mcu manager report get interval start to mcu monitor.\n");
|
||||||
monitor->RecvMcuHeartBeat(recv);
|
monitor->RecvGetIntervalStartEvent(recv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||||
|
@ -259,7 +260,7 @@ void McuManagerImpl::OtherSideSendGetDateTime(const unsigned int &serialNumber)
|
||||||
std::make_shared<McuRecvGetDateTime>(manager, serialNumber, OtherSideSendType::GET_DATE_TIME);
|
std::make_shared<McuRecvGetDateTime>(manager, serialNumber, OtherSideSendType::GET_DATE_TIME);
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
||||||
monitor->RecvMcuHeartBeat(recv);
|
monitor->RecvMcuHeartBeatEvent(recv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||||
|
@ -290,7 +291,7 @@ void McuManagerImpl::OtherSideSendGetPirSensitivity(const unsigned int &serialNu
|
||||||
std::make_shared<McuRecvGetDateTime>(manager, serialNumber, OtherSideSendType::GET_DATE_TIME);
|
std::make_shared<McuRecvGetDateTime>(manager, serialNumber, OtherSideSendType::GET_DATE_TIME);
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
LogInfo("Mcu manager report heart beat to mcu monitor.\n");
|
||||||
monitor->RecvMcuHeartBeat(recv);
|
monitor->RecvMcuHeartBeatEvent(recv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
LogWarning("mMonitor is nullptr, AddMcuRecv.\n");
|
||||||
|
@ -350,6 +351,6 @@ void McuManagerImpl::McuAskSendHeartBeatHandle(std::shared_ptr<VMcuRecv> &recv)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
|
std::shared_ptr<VMcuMonitor> monitor = GetMcuMonitor();
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
monitor->RecvMcuHeartBeat(recv);
|
monitor->RecvMcuHeartBeatEvent(recv);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -188,9 +188,9 @@ TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_OtherSideSendHeartB
|
||||||
public:
|
public:
|
||||||
MonitorTest() = default;
|
MonitorTest() = default;
|
||||||
virtual ~MonitorTest() = default;
|
virtual ~MonitorTest() = default;
|
||||||
void RecvMcuHeartBeat(std::shared_ptr<VMcuRecv> &recv) override
|
void RecvMcuHeartBeatEvent(std::shared_ptr<VMcuRecv> &recv) override
|
||||||
{
|
{
|
||||||
LogInfo("RecvMcuHeartBeat\n");
|
LogInfo("RecvMcuHeartBeatEvent\n");
|
||||||
// std::shared_ptr<McuAsk<ASK_RESULT>> ask = std::dynamic_pointer_cast<McuAsk<ASK_RESULT>>(recv);
|
// std::shared_ptr<McuAsk<ASK_RESULT>> ask = std::dynamic_pointer_cast<McuAsk<ASK_RESULT>>(recv);
|
||||||
// ask->mDataReply = ASK_RESULT::SUCCEED;
|
// ask->mDataReply = ASK_RESULT::SUCCEED;
|
||||||
recv->ReplyFinished(true);
|
recv->ReplyFinished(true);
|
||||||
|
@ -857,7 +857,6 @@ TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
|
||||||
McuAskBaseTestTool::ReplyFinished(result);
|
McuAskBaseTestTool::ReplyFinished(result);
|
||||||
if (result) {
|
if (result) {
|
||||||
LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast<int>(mDataReply));
|
LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast<int>(mDataReply));
|
||||||
// Do something here.
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("Ask data falied.\n");
|
LogError("Ask data falied.\n");
|
||||||
|
@ -899,4 +898,28 @@ TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_OtherSideSendIpcMissio
|
||||||
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
|
||||||
|
// --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_AUTO_OtherSideGetIntervalStart
|
||||||
|
TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_AUTO_OtherSideGetIntervalStart)
|
||||||
|
{
|
||||||
|
constexpr unsigned int TEST_SERIAL_NUMBER = 99;
|
||||||
|
class MonitorTest : public VMcuMonitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MonitorTest() = default;
|
||||||
|
virtual ~MonitorTest() = default;
|
||||||
|
void RecvGetIntervalStartEvent(std::shared_ptr<VMcuRecv> &recv) override
|
||||||
|
{
|
||||||
|
LogInfo("RecvGetIntervalStartEvent\n");
|
||||||
|
std::shared_ptr<McuRecv<unsigned char>> recvData = std::dynamic_pointer_cast<McuRecv<unsigned char>>(recv);
|
||||||
|
recv->ReplyFinished(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
IMcuManager::GetInstance()->Init();
|
||||||
|
MockOtherSideGetIntervalStart(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
|
|
@ -36,6 +36,7 @@ public:
|
||||||
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
|
||||||
void MockOtherSideAskIpcMission(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 MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
|
void MockOtherSideGetIntervalStart(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);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,11 @@ void McuManagerTestTool::MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &m
|
||||||
{
|
{
|
||||||
McuProtocolTestTool::MockOtherSideAskHeartBeat(mock, serialNumber);
|
McuProtocolTestTool::MockOtherSideAskHeartBeat(mock, serialNumber);
|
||||||
}
|
}
|
||||||
|
void McuManagerTestTool::MockOtherSideGetIntervalStart(std::shared_ptr<LinuxTest> &mock,
|
||||||
|
const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
McuProtocolTestTool::MockOtherSideAskGetIntervalStart(mock, serialNumber);
|
||||||
|
}
|
||||||
void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock)
|
void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock)
|
||||||
{
|
{
|
||||||
UartDeviceTestTool::SetUartDeviceOpenFailed(mock, gUartDevice);
|
UartDeviceTestTool::SetUartDeviceOpenFailed(mock, gUartDevice);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
### 1.1.2. 测试用例命名:
|
### 1.1.2. 测试用例命名:
|
||||||
|
|
||||||
1. 仿真:硬件仿真,使用hardware simulation的缩写:**HS**,硬件仿真只能运行在Ubuntu系统进行仿真测试;真实硬件接口使用real hardware的缩写:**RH**,真实硬件接口测试用例只能运行在开发板进行真机测试;不涉及使用NOT INVOLVED的缩写:**NI**,即可执行在Ubuntu也可以运行在开发板;
|
1. 仿真:硬件仿真,使用hardware simulation的缩写:**HS**,硬件仿真只能运行在Ubuntu系统进行仿真测试;真实硬件接口使用real hardware的缩写:**RH**,真实硬件接口测试用例只能运行在开发板进行真机测试;
|
||||||
2. 测试用例类型:含单元测试(UNIT)和集成测试(INTEGRATION);
|
2. 测试用例类型:含单元测试(UNIT)和集成测试(INTEGRATION);
|
||||||
3. 用例所属模块:大小驼峰;
|
3. 用例所属模块:大小驼峰;
|
||||||
4. 测试用例属性:EXAMPLE/AUTO/STRESS
|
4. 测试用例属性:EXAMPLE/AUTO/STRESS
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
void MockOtherSideAskIpcMission(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 MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
|
||||||
|
void MockOtherSideAskGetIntervalStart(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:
|
||||||
|
@ -75,6 +76,10 @@ private:
|
||||||
const unsigned int &serialNumber);
|
const unsigned int &serialNumber);
|
||||||
void OtherSideAskHeartBeatInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
void OtherSideAskHeartBeatInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
const unsigned int &serialNumber);
|
const unsigned int &serialNumber);
|
||||||
|
void OtherSideAskGetIntervalStartHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
const unsigned int &serialNumber);
|
||||||
|
void OtherSideAskGetIntervalStartInit(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);
|
||||||
|
|
|
@ -69,6 +69,10 @@ unsigned char REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT_X[] = {
|
||||||
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x02, 0x00, 0x0C, 0xFF, 0xFF};
|
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x02, 0x00, 0x0C, 0xFF, 0xFF};
|
||||||
unsigned char OTHER_SIDE_ASK_SEND_HEART_BEAT_X[] = {
|
unsigned char OTHER_SIDE_ASK_SEND_HEART_BEAT_X[] = {
|
||||||
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x02, 0x00, 0x0C, 0xFF, 0xFF};
|
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x02, 0x00, 0x0C, 0xFF, 0xFF};
|
||||||
|
unsigned char REPLY_OTHER_SIDE_ASK_GET_INTERVAL_START_X[] = {
|
||||||
|
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0xC1, 0x06, 0x00, 0x0F, 0x00, 0x00, 0x00, 0xFF, 0xFF};
|
||||||
|
unsigned char OTHER_SIDE_ASK_GET_INTERVAL_START_X[] = {
|
||||||
|
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x41, 0x06, 0x00, 0x0C, 0xFF, 0xFF};
|
||||||
McuProtocolTestTool::McuProtocolTestTool()
|
McuProtocolTestTool::McuProtocolTestTool()
|
||||||
{
|
{
|
||||||
mThreadRuning = false;
|
mThreadRuning = false;
|
||||||
|
@ -145,6 +149,11 @@ void McuProtocolTestTool::MockOtherSideAskHeartBeat(std::shared_ptr<LinuxTest> &
|
||||||
{
|
{
|
||||||
OtherSideAskHeartBeatHandle(mock, mUartFd, serialNumber);
|
OtherSideAskHeartBeatHandle(mock, mUartFd, serialNumber);
|
||||||
}
|
}
|
||||||
|
void McuProtocolTestTool::MockOtherSideAskGetIntervalStart(std::shared_ptr<LinuxTest> &mock,
|
||||||
|
const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
OtherSideAskGetIntervalStartHandle(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;
|
||||||
|
@ -708,7 +717,7 @@ void McuProtocolTestTool::OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest>
|
||||||
serialNumber,
|
serialNumber,
|
||||||
REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION,
|
REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION,
|
||||||
nullptr,
|
nullptr,
|
||||||
sizeof(OTHER_SIDE_ASK_SEND_IPC_MISSION_X));
|
sizeof(REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION_X));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void McuProtocolTestTool::OtherSideAskHeartBeatHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
void McuProtocolTestTool::OtherSideAskHeartBeatHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
@ -755,7 +764,55 @@ void McuProtocolTestTool::OtherSideAskHeartBeatInit(std::shared_ptr<LinuxTest> &
|
||||||
serialNumber,
|
serialNumber,
|
||||||
REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT,
|
REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT,
|
||||||
nullptr,
|
nullptr,
|
||||||
sizeof(OTHER_SIDE_ASK_SEND_HEART_BEAT_X));
|
sizeof(REPLY_OTHER_SIDE_ASK_SEND_HEART_BEAT_X));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void McuProtocolTestTool::OtherSideAskGetIntervalStartHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
LogInfo("OtherSideAskGetIntervalStartHandle\n");
|
||||||
|
auto handle = [=, &mock](McuProtocolTestTool *testTool) {
|
||||||
|
testTool->OtherSideAskGetIntervalStartInit(mock, uartFd, serialNumber);
|
||||||
|
};
|
||||||
|
if (mLockThread.joinable()) {
|
||||||
|
mLockThread.join();
|
||||||
|
}
|
||||||
|
mLockThread = std::thread(handle, this);
|
||||||
|
}
|
||||||
|
void McuProtocolTestTool::OtherSideAskGetIntervalStartInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
|
||||||
|
const unsigned int &serialNumber)
|
||||||
|
{
|
||||||
|
LockProtocolHandle();
|
||||||
|
unsigned int serialNum = serialNumber;
|
||||||
|
serialNum = htonl(serialNum);
|
||||||
|
memcpy(
|
||||||
|
OTHER_SIDE_ASK_GET_INTERVAL_START_X + PROTOCOL_SERIAL_NUMBER_OFFSET, &serialNum, PROTOCOL_SERIAL_NUMBER_LENGTH);
|
||||||
|
ResetCheckCode(OTHER_SIDE_ASK_GET_INTERVAL_START_X, sizeof(OTHER_SIDE_ASK_GET_INTERVAL_START_X));
|
||||||
|
ReplySelectSucceed(mock, uartFd);
|
||||||
|
constexpr int LEFT_DATA_LENGTH = sizeof(OTHER_SIDE_ASK_GET_INTERVAL_START_X) - PROTOCOL_DATA_KEY_HEAD_LENGTH;
|
||||||
|
auto apiReadKeyHead = [=](int fd, void *buf, size_t count) {
|
||||||
|
memcpy(buf, OTHER_SIDE_ASK_GET_INTERVAL_START_X, PROTOCOL_DATA_KEY_HEAD_LENGTH);
|
||||||
|
McuProtocolTestTool::PrintHexadecimalData(
|
||||||
|
buf, PROTOCOL_DATA_KEY_HEAD_LENGTH, "OtherSideAskGetIntervalStartInit read:");
|
||||||
|
};
|
||||||
|
auto apiReadLeftData = [=](int fd, void *buf, size_t count) {
|
||||||
|
memcpy(buf, OTHER_SIDE_ASK_GET_INTERVAL_START_X + PROTOCOL_DATA_KEY_HEAD_LENGTH, LEFT_DATA_LENGTH);
|
||||||
|
McuProtocolTestTool::PrintHexadecimalData(buf, LEFT_DATA_LENGTH, "OtherSideAskGetIntervalStartInit 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_GET_INTERVAL_START,
|
||||||
|
nullptr,
|
||||||
|
sizeof(REPLY_OTHER_SIDE_ASK_GET_INTERVAL_START_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)
|
||||||
|
|
|
@ -14,6 +14,14 @@
|
||||||
*/
|
*/
|
||||||
#include "ProtocolMonitor.h"
|
#include "ProtocolMonitor.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
|
static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log)
|
||||||
|
{
|
||||||
|
printf("%s { 0x%02X", log, *(unsigned char *)buf);
|
||||||
|
for (size_t i = 1; i < bufLength; i++) {
|
||||||
|
printf(", 0x%02X", *((unsigned char *)buf + i));
|
||||||
|
}
|
||||||
|
printf(" }\n");
|
||||||
|
}
|
||||||
std::shared_ptr<ProtocolMonitor> &ProtocolMonitor::GetInstance(std::shared_ptr<ProtocolMonitor> *impl)
|
std::shared_ptr<ProtocolMonitor> &ProtocolMonitor::GetInstance(std::shared_ptr<ProtocolMonitor> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<ProtocolMonitor>();
|
static auto instance = std::make_shared<ProtocolMonitor>();
|
||||||
|
@ -34,7 +42,19 @@ void ProtocolMonitor::MonitorWriteProtocolData(const short &head, const unsigned
|
||||||
}
|
}
|
||||||
void ProtocolMonitorTest::Init(std::shared_ptr<ProtocolMonitorTest> &test)
|
void ProtocolMonitorTest::Init(std::shared_ptr<ProtocolMonitorTest> &test)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _)).WillRepeatedly(DoAll(Return()));
|
auto printfParam = [=](const short &head,
|
||||||
|
const unsigned int &serialNumber,
|
||||||
|
const short &command,
|
||||||
|
const void *data,
|
||||||
|
const short &packetLength) {
|
||||||
|
LogInfo("MonitorWriteProtocolData called.\n");
|
||||||
|
PrintHexadecimalData(&head, sizeof(head), "MonitorWriteProtocolData(head):");
|
||||||
|
PrintHexadecimalData(&serialNumber, sizeof(serialNumber), "MonitorWriteProtocolData(serialNumber):");
|
||||||
|
PrintHexadecimalData(&command, sizeof(command), "MonitorWriteProtocolData(command):");
|
||||||
|
PrintHexadecimalData(&packetLength, sizeof(packetLength), "MonitorWriteProtocolData(packetLength):");
|
||||||
|
};
|
||||||
|
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(_, _, _, _, _))
|
||||||
|
.WillRepeatedly(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(printfParam)), Return()));
|
||||||
}
|
}
|
||||||
void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &test, const short &head,
|
void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &test, const short &head,
|
||||||
const unsigned int &serialNumber, const short &command, const void *data,
|
const unsigned int &serialNumber, const short &command, const void *data,
|
||||||
|
@ -46,6 +66,10 @@ void ProtocolMonitorTest::WriteDataOnce(std::shared_ptr<ProtocolMonitorTest> &te
|
||||||
const void *data,
|
const void *data,
|
||||||
const short &packetLength) {
|
const short &packetLength) {
|
||||||
};
|
};
|
||||||
|
PrintHexadecimalData(&head, sizeof(head), "WriteDataOnce(head):");
|
||||||
|
PrintHexadecimalData(&serialNumber, sizeof(serialNumber), "WriteDataOnce(serialNumber):");
|
||||||
|
PrintHexadecimalData(&command, sizeof(command), "WriteDataOnce(command):");
|
||||||
|
PrintHexadecimalData(&packetLength, sizeof(packetLength), "WriteDataOnce(packetLength):");
|
||||||
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
|
EXPECT_CALL(*test.get(), MonitorWriteProtocolData(head, serialNumber, command, _, packetLength))
|
||||||
.Times(1)
|
.Times(1)
|
||||||
.WillOnce(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(printfParam)), Return()));
|
.WillOnce(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(printfParam)), Return()));
|
||||||
|
|
|
@ -194,8 +194,8 @@ void McuProtocol::ReplyOtherSideSendGetIntervalStart(const ReplyResult &result,
|
||||||
SetTime interval(hour, min, second);
|
SetTime interval(hour, min, second);
|
||||||
std::shared_ptr<VProtocolParam> param =
|
std::shared_ptr<VProtocolParam> param =
|
||||||
std::make_shared<ProtocolParam<SetTime>>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_GET_INTERVAL_START, interval);
|
std::make_shared<ProtocolParam<SetTime>>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_GET_INTERVAL_START, interval);
|
||||||
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
|
||||||
param->mSerialNumber = serialNumber;
|
param->mSerialNumber = serialNumber;
|
||||||
|
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
||||||
WriteProtocolData(
|
WriteProtocolData(
|
||||||
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
|
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,8 @@ void McuProtocol::ReplyOtherSideSendGetDateTime(const ReplyResult &result, const
|
||||||
SetDateTime dateTime(year, mon, day, hour, min, second);
|
SetDateTime dateTime(year, mon, day, hour, min, second);
|
||||||
std::shared_ptr<VProtocolParam> param =
|
std::shared_ptr<VProtocolParam> param =
|
||||||
std::make_shared<ProtocolParam<SetDateTime>>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_GET_DATE_TIME, dateTime);
|
std::make_shared<ProtocolParam<SetDateTime>>(PROTOCOL_COMMAND::REPLY_OTHER_SIDE_ASK_GET_DATE_TIME, dateTime);
|
||||||
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
|
||||||
param->mSerialNumber = serialNumber;
|
param->mSerialNumber = serialNumber;
|
||||||
|
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
||||||
WriteProtocolData(
|
WriteProtocolData(
|
||||||
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
|
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), NULL_CONTEXT, handle->GetSerialNumber());
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,12 @@ ProtocolHandle::ProtocolHandle(const void *data, const size_t &length)
|
||||||
std::bind(&ProtocolHandle::AnalyzeOtherSideSendIpcMissionPacket, this, _1);
|
std::bind(&ProtocolHandle::AnalyzeOtherSideSendIpcMissionPacket, this, _1);
|
||||||
mAnalyzePacketFunc[OTHER_SIDE_ASK_SEND_HEART_BEAT] =
|
mAnalyzePacketFunc[OTHER_SIDE_ASK_SEND_HEART_BEAT] =
|
||||||
std::bind(&ProtocolHandle::AnalyzeOtherSideSendHeartBeatPacket, this, _1);
|
std::bind(&ProtocolHandle::AnalyzeOtherSideSendHeartBeatPacket, this, _1);
|
||||||
|
mAnalyzePacketFunc[OTHER_SIDE_ASK_GET_INTERVAL_START] =
|
||||||
|
std::bind(&ProtocolHandle::AnalyzeOtherSideSendGetIntervalStart, this, _1);
|
||||||
|
mAnalyzePacketFunc[OTHER_SIDE_ASK_GET_DATE_TIME] =
|
||||||
|
std::bind(&ProtocolHandle::AnalyzeOtherSideSendGetDataTime, this, _1);
|
||||||
|
mAnalyzePacketFunc[OTHER_SIDE_ASK_GET_PIR_SENSITIVITY] =
|
||||||
|
std::bind(&ProtocolHandle::AnalyzeOtherSideSendGetPirSensitivity, this, _1);
|
||||||
}
|
}
|
||||||
ProtocolHandle::~ProtocolHandle()
|
ProtocolHandle::~ProtocolHandle()
|
||||||
{
|
{
|
||||||
|
@ -110,6 +116,7 @@ void ProtocolHandle::MallocPacketDataBuff(const void *data, const size_t dataLen
|
||||||
// packet.mCheckCode = BigEndianConversion(packet.mCheckCode);
|
// packet.mCheckCode = BigEndianConversion(packet.mCheckCode);
|
||||||
memcpy(mProtocolData + packetLength - CHECK_CODE_LENGTH, &packet.mCheckCode, CHECK_CODE_LENGTH);
|
memcpy(mProtocolData + packetLength - CHECK_CODE_LENGTH, &packet.mCheckCode, CHECK_CODE_LENGTH);
|
||||||
mProtocolDataLength = packetLength;
|
mProtocolDataLength = packetLength;
|
||||||
|
ProtocolHandle::PrintHexadecimalData(mProtocolData, mProtocolDataLength, "Make protocol packet:");
|
||||||
}
|
}
|
||||||
void ProtocolHandle::MakeProtocolPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
void ProtocolHandle::MakeProtocolPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user