diff --git a/middleware/McuManager/include/IMcuManager.h b/middleware/McuManager/include/IMcuManager.h index be18239..a1374f1 100644 --- a/middleware/McuManager/include/IMcuManager.h +++ b/middleware/McuManager/include/IMcuManager.h @@ -93,5 +93,6 @@ public: virtual const StatusCode SetFeedingCycleForWatchDog(std::shared_ptr &ask, const unsigned char &hour, const unsigned char &min, const unsigned char &second); virtual const StatusCode SetDateTime(std::shared_ptr &ask, const McuAskDateTime &value); + virtual const StatusCode SetPirSensitivity(std::shared_ptr &ask, const unsigned char &sensitivity); }; #endif \ No newline at end of file diff --git a/middleware/McuManager/src/IMcuManager.cpp b/middleware/McuManager/src/IMcuManager.cpp index 5e919c3..6b508d0 100644 --- a/middleware/McuManager/src/IMcuManager.cpp +++ b/middleware/McuManager/src/IMcuManager.cpp @@ -52,6 +52,10 @@ const StatusCode IMcuManager::SetFeedingCycleForWatchDog(std::shared_ptr &ask, const McuAskDateTime &value) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +const StatusCode IMcuManager::SetPirSensitivity(std::shared_ptr &ask, const unsigned char &sensitivity) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/middleware/McuManager/src/McuManagerImpl.cpp b/middleware/McuManager/src/McuManagerImpl.cpp index 4828557..d582b7a 100644 --- a/middleware/McuManager/src/McuManagerImpl.cpp +++ b/middleware/McuManager/src/McuManagerImpl.cpp @@ -52,4 +52,9 @@ const StatusCode McuManagerImpl::SetDateTime(std::shared_ptr &ask, cons std::shared_ptr context = std::make_shared>>(ask); return McuProtocol::McuSetDateTime( value.mYear, value.mMon, value.mDay, value.mHour, value.mMin, value.mSecond, context); +} +const StatusCode McuManagerImpl::SetPirSensitivity(std::shared_ptr &ask, const unsigned char &sensitivity) +{ + std::shared_ptr context = std::make_shared>>(ask); + return McuProtocol::SetPirSensitivity(sensitivity, context); } \ No newline at end of file diff --git a/middleware/McuManager/src/McuManagerImpl.h b/middleware/McuManager/src/McuManagerImpl.h index d50569e..4538036 100644 --- a/middleware/McuManager/src/McuManagerImpl.h +++ b/middleware/McuManager/src/McuManagerImpl.h @@ -31,5 +31,6 @@ public: const StatusCode SetFeedingCycleForWatchDog(std::shared_ptr &ask, const unsigned char &hour, const unsigned char &min, const unsigned char &second) override; const StatusCode SetDateTime(std::shared_ptr &ask, const McuAskDateTime &value) override; + const StatusCode SetPirSensitivity(std::shared_ptr &ask, const unsigned char &sensitivity) override; }; #endif \ No newline at end of file diff --git a/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp b/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp index ce005e6..7b2a1d6 100644 --- a/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp +++ b/test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp @@ -221,6 +221,37 @@ 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) +{ + /** + * @brief The user needs to derive a subclass of McuAskBase and add the business code after obtaining data in the + * abstract interface. + */ + class McuAskTest : public McuAsk, public McuAskBase + { + public: + McuAskTest() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY) {} // using McuAskBlock::NOT_BLOCK + virtual ~McuAskTest() = default; + void ReplyFinished(const bool result) override + { + McuAskBase::ReplyFinished(result); + if (result) { + LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast(mDataReply)); + // Do something here. + } + else { + LogError("Ask data falied.\n"); + } + } + }; + IMcuManager::GetInstance()->Init(); + std::shared_ptr ask = std::make_shared(); + IMcuManager::GetInstance()->SetPirSensitivity(ask, 9); + 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) { @@ -538,4 +569,73 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetDataTime2) 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.INTEGRATION_McuManager_AUTO_SetPirSensitivity +TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity) +{ + class McuAskTest : public McuAsk, public McuAskBaseTestTool + { + public: + McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, + McuAskReply::NEED_REPLY) // using McuAskBlock::NOT_BLOCK + { + } + virtual ~McuAskTest() = default; + void ReplyFinished(const bool result) override + { + McuAskBaseTestTool::ReplyFinished(result); + if (result) { + LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast(mDataReply)); + // Do something here. + } + else { + LogError("Ask data falied.\n"); + } + } + }; + IMcuManager::GetInstance()->Init(); + std::shared_ptr ask = std::make_shared(); + std::shared_ptr testTool = std::dynamic_pointer_cast(ask); + testTool->McuAskDefaultFeatures(testTool); + StatusCode code = IMcuManager::GetInstance()->SetPirSensitivity(ask, 1); + EXPECT_EQ(code.mStatusCode, STATUS_CODE_OK); // STATUS_CODE_OK means write data to mcu succeed. + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + 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.INTEGRATION_McuManager_AUTO_SetPirSensitivity2 +TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2) +{ + class McuAskTest : public McuAsk, public McuAskBaseTestTool + { + public: + McuAskTest() + : McuAskBaseTestTool(McuAskBlock::NOT_BLOCK, + McuAskReply::NEED_REPLY) // using McuAskBlock::NOT_BLOCK + { + } + virtual ~McuAskTest() = default; + void ReplyFinished(const bool result) override + { + McuAskBaseTestTool::ReplyFinished(result); + if (result) { + LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast(mDataReply)); + // Do something here. + } + else { + LogError("Ask data falied.\n"); + } + } + }; + IMcuManager::GetInstance()->Init(); + std::shared_ptr ask = std::make_shared(); + std::shared_ptr testTool = std::dynamic_pointer_cast(ask); + testTool->McuAskDefaultFeatures(testTool); + StatusCode code = IMcuManager::GetInstance()->SetPirSensitivity(ask, 2); + 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)); + EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted. + IMcuManager::GetInstance()->UnInit(); +} } // namespace McuManagerMockTest \ No newline at end of file diff --git a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h index a800f67..638e5f8 100644 --- a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h +++ b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h @@ -46,6 +46,10 @@ private: void FeedingCycleProtocolInit(std::shared_ptr &mock, const int &uartFd, const void *buf, size_t count); bool SetDataTimeProtocolHandle(std::shared_ptr &mock, const int &uartFd, const void *buf, size_t count); void SetDataTimeProtocolInit(std::shared_ptr &mock, const int &uartFd, const void *buf, size_t count); + bool SetPirSensitivityProtocolHandle(std::shared_ptr &mock, const int &uartFd, const void *buf, + size_t count); + void SetPirSensitivityProtocolInit(std::shared_ptr &mock, const int &uartFd, const void *buf, + size_t count); void LockProtocolHandle(void); void UnlockProtocolHandle(void); void UnlockThread(void); diff --git a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp index b8b772a..08e318e 100644 --- a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp +++ b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp @@ -30,17 +30,21 @@ constexpr size_t PROTOCOL_DATA_KEY_HEAD_LENGTH = 10; constexpr size_t PROTOCOL_COMMAND_LENGTH = 6; constexpr size_t PROTOCOL_CHECK_CODE_LENGTH = sizeof(short); constexpr size_t PROTOCOL_SERIAL_NUMBER_LENGTH = sizeof(unsigned int); -unsigned char ASK_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x0C, 0x71, 0x88}; -unsigned char REPLY_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xAA, 0x89}; -unsigned char ASK_CUT_OFF_POWER_SUPPLY[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x02, 0x00, 0x0C, 0x81, 0x88}; -unsigned char ASK_FEED_WATCH_DOG[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x03, 0x00, 0x0C, 0xD0, 0x48}; +unsigned char ASK_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x0C, 0xFF, 0xFF}; +unsigned char REPLY_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; +unsigned char ASK_CUT_OFF_POWER_SUPPLY[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x02, 0x00, 0x0C, 0xFF, 0xFF}; +unsigned char ASK_FEED_WATCH_DOG[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x03, 0x00, 0x0C, 0xFF, 0xFF}; unsigned char ASK_SET_FEEDING_CYCLE[] = { - 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x04, 0x00, 0x0F, 0x01, 0x01, 0x01, 0xA7, 0x9A}; + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x04, 0x00, 0x0F, 0x01, 0x01, 0x01, 0xFF, 0xFF}; unsigned char REPLY_SET_FEEDING_CYCLE[] = { - 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x0D, 0x01, 0x52, 0x26}; + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; unsigned char ASK_SET_DATE_TIME[] = { 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x07, 0x00, 0x13, 0xDE, 0x07, 0x01, 0x0F, 0x00, 0x00, 0x00, 0xFF, 0xFF}; unsigned char REPLY_SET_DATE_TIME[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; +unsigned char ASK_SET_PIR_SENSITIVITY[] = { + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x08, 0x00, 0x0D, 0x09, 0xFF, 0xFF}; +unsigned char REPLY_SET_PIR_SENSITIVITY[] = { + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; McuProtocolTestTool::McuProtocolTestTool() { mThreadRuning = false; @@ -52,6 +56,7 @@ McuProtocolTestTool::McuProtocolTestTool() mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::FeedWatchDogProtocolHandle, this, _1, _2, _3, _4)); mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::FeedingCycleProtocolHandle, this, _1, _2, _3, _4)); mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::SetDataTimeProtocolHandle, this, _1, _2, _3, _4)); + mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::SetPirSensitivityProtocolHandle, this, _1, _2, _3, _4)); } void McuProtocolTestTool::Init(std::shared_ptr &mock, const UartInfo &uart) { @@ -163,9 +168,11 @@ bool McuProtocolTestTool::IpcMissionProtocolHandle(std::shared_ptr &m if (sizeof(ASK_IPC_MISSION) == count && memcmp(ASK_IPC_MISSION + PROTOCOL_COMMAND_LENGTH, (unsigned char *)buf + PROTOCOL_COMMAND_LENGTH, 2) == 0) { LogInfo("Set REPLY_IPC_MISSION\n"); - short askCheckCode = calculate_check_sum(ASK_IPC_MISSION, sizeof(ASK_IPC_MISSION) - PROTOCOL_CHECK_CODE_LENGTH); - askCheckCode = htons(askCheckCode); - EXPECT_EQ(memcmp((unsigned char *)ASK_IPC_MISSION + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, 2), 0); + short askCheckCode = calculate_check_sum((unsigned char *)buf, count - PROTOCOL_CHECK_CODE_LENGTH); + // askCheckCode = htons(askCheckCode); + int result = memcmp( + (unsigned char *)buf + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, PROTOCOL_CHECK_CODE_LENGTH); + EXPECT_EQ(result, 0) << "ask protocol data errer, check code isn't right."; auto handle = [=, &mock](McuProtocolTestTool *testTool) { testTool->IpcMissionProtocolInit(mock, uartFd, buf, count); }; @@ -206,12 +213,11 @@ bool McuProtocolTestTool::CutOffPowerSupplyProtocolHandle(std::shared_ptr if (sizeof(ASK_FEED_WATCH_DOG) == count && memcmp(ASK_FEED_WATCH_DOG + PROTOCOL_COMMAND_LENGTH, (unsigned char *)buf + PROTOCOL_COMMAND_LENGTH, 2) == 0) { LogInfo("Set ASK_FEED_WATCH_DOG\n"); - short askCheckCode = - calculate_check_sum(ASK_FEED_WATCH_DOG, sizeof(ASK_FEED_WATCH_DOG) - PROTOCOL_CHECK_CODE_LENGTH); - askCheckCode = htons(askCheckCode); - EXPECT_EQ(memcmp((unsigned char *)ASK_FEED_WATCH_DOG + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, 2), - 0); + short askCheckCode = calculate_check_sum((unsigned char *)buf, count - PROTOCOL_CHECK_CODE_LENGTH); + // askCheckCode = htons(askCheckCode); + int result = memcmp( + (unsigned char *)buf + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, PROTOCOL_CHECK_CODE_LENGTH); + EXPECT_EQ(result, 0) << "ask protocol data errer, check code isn't right."; // IpcMissionProtocolInit(mock, uartFd); return PROTOCOL_HANDLED; } @@ -243,11 +249,11 @@ bool McuProtocolTestTool::FeedingCycleProtocolHandle(std::shared_ptr calculate_check_sum(REPLY_SET_FEEDING_CYCLE, sizeof(REPLY_SET_FEEDING_CYCLE) - PROTOCOL_CHECK_CODE_LENGTH); replyCheckCode = htons(replyCheckCode); LogInfo("Set ASK_SET_FEEDING_CYCLE, reply data check code = 0x%x\n", replyCheckCode); - short askCheckCode = - calculate_check_sum(ASK_SET_FEEDING_CYCLE, sizeof(ASK_SET_FEEDING_CYCLE) - PROTOCOL_CHECK_CODE_LENGTH); - askCheckCode = htons(askCheckCode); - EXPECT_EQ(memcmp((unsigned char *)ASK_SET_FEEDING_CYCLE + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, 2), - 0); + short askCheckCode = calculate_check_sum((unsigned char *)buf, count - PROTOCOL_CHECK_CODE_LENGTH); + // askCheckCode = htons(askCheckCode); + int result = memcmp( + (unsigned char *)buf + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, PROTOCOL_CHECK_CODE_LENGTH); + EXPECT_EQ(result, 0) << "ask protocol data errer, check code isn't right."; auto handle = [=, &mock](McuProtocolTestTool *testTool) { testTool->FeedingCycleProtocolInit(mock, uartFd, buf, count); }; @@ -329,6 +335,54 @@ void McuProtocolTestTool::SetDataTimeProtocolInit(std::shared_ptr &mo .WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(apiReadLeftData)), Return(LEFT_DATA_LENGTH))) .WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING))); } +bool McuProtocolTestTool::SetPirSensitivityProtocolHandle(std::shared_ptr &mock, const int &uartFd, + const void *buf, size_t count) +{ + if (sizeof(ASK_SET_PIR_SENSITIVITY) == count && + memcmp(ASK_SET_PIR_SENSITIVITY + PROTOCOL_COMMAND_LENGTH, (unsigned char *)buf + PROTOCOL_COMMAND_LENGTH, 2) == + 0) { + short replyCheckCode = calculate_check_sum(REPLY_SET_PIR_SENSITIVITY, + sizeof(REPLY_SET_PIR_SENSITIVITY) - PROTOCOL_CHECK_CODE_LENGTH); + replyCheckCode = htons(replyCheckCode); + LogInfo("Set ASK_SET_PIR_SENSITIVITY, reply data check code = 0x%x\n", replyCheckCode); + short askCheckCode = calculate_check_sum((unsigned char *)buf, count - PROTOCOL_CHECK_CODE_LENGTH); + // askCheckCode = htons(askCheckCode); + int result = memcmp( + (unsigned char *)buf + count - PROTOCOL_CHECK_CODE_LENGTH, &askCheckCode, PROTOCOL_CHECK_CODE_LENGTH); + EXPECT_EQ(result, 0) << "ask protocol data errer, check code isn't right."; + auto handle = [=, &mock](McuProtocolTestTool *testTool) { + testTool->SetDataTimeProtocolInit(mock, uartFd, buf, count); + }; + if (mLockThread.joinable()) { + mLockThread.join(); + } + mLockThread = std::thread(handle, this); + return PROTOCOL_HANDLED; + } + return PROTOCOL_NOT_HANDLED; +} +void McuProtocolTestTool::SetPirSensitivityProtocolInit(std::shared_ptr &mock, const int &uartFd, + const void *buf, size_t count) +{ + LockProtocolHandle(); + memcpy(REPLY_SET_PIR_SENSITIVITY + 2, (unsigned char *)buf + 2, PROTOCOL_SERIAL_NUMBER_LENGTH); + ResetCheckCode(REPLY_SET_PIR_SENSITIVITY, sizeof(REPLY_SET_PIR_SENSITIVITY)); + ReplySelectSucceed(mock, uartFd); + constexpr int LEFT_DATA_LENGTH = sizeof(REPLY_SET_PIR_SENSITIVITY) - PROTOCOL_DATA_KEY_HEAD_LENGTH; + auto apiReadKeyHead = [=](int fd, void *buf, size_t count) { + memcpy(buf, REPLY_SET_PIR_SENSITIVITY, PROTOCOL_DATA_KEY_HEAD_LENGTH); + McuProtocolTestTool::PrintHexadecimalData(buf, PROTOCOL_DATA_KEY_HEAD_LENGTH, READ_PRINT); + }; + auto apiReadLeftData = [=](int fd, void *buf, size_t count) { + memcpy(buf, REPLY_SET_PIR_SENSITIVITY + PROTOCOL_DATA_KEY_HEAD_LENGTH, LEFT_DATA_LENGTH); + McuProtocolTestTool::PrintHexadecimalData(buf, LEFT_DATA_LENGTH, READ_PRINT); + 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))); +} void McuProtocolTestTool::UnlockProtocolHandle(void) { auto unlockThread = [=](McuProtocolTestTool *testTool) { testTool->UnlockThread(); }; diff --git a/utils/McuProtocol/include/McuProtocol.h b/utils/McuProtocol/include/McuProtocol.h index 2ea2c6e..377d6e1 100644 --- a/utils/McuProtocol/include/McuProtocol.h +++ b/utils/McuProtocol/include/McuProtocol.h @@ -106,6 +106,7 @@ public: const StatusCode McuSetDateTime(const unsigned short &year, const unsigned char &mon, const unsigned char &day, const unsigned char &hour, const unsigned char &min, const unsigned char &second, std::shared_ptr &context); + const StatusCode SetPirSensitivity(const unsigned char &sensitivity, std::shared_ptr &context); void DataHandleThread(void); protected: diff --git a/utils/McuProtocol/src/McuProtocol.cpp b/utils/McuProtocol/src/McuProtocol.cpp index 7201f86..4329f4b 100644 --- a/utils/McuProtocol/src/McuProtocol.cpp +++ b/utils/McuProtocol/src/McuProtocol.cpp @@ -100,6 +100,15 @@ const StatusCode McuProtocol::McuSetDateTime(const unsigned short &year, const u return WriteProtocolData( handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber()); } +const StatusCode McuProtocol::SetPirSensitivity(const unsigned char &sensitivity, + std::shared_ptr &context) +{ + std::shared_ptr param = + std::make_shared>(PROTOCOL_COMMAND::ASK_SET_PIR_SENSITIVITY, sensitivity); + std::shared_ptr handle = ProtocolHandle::CreateProtocolData(param); + return WriteProtocolData( + handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber()); +} void McuProtocol::DataHandleThread(void) { mThreadRuning = true; diff --git a/utils/McuProtocol/src/ProtocolHandle.cpp b/utils/McuProtocol/src/ProtocolHandle.cpp index c0ca8ed..2acd737 100644 --- a/utils/McuProtocol/src/ProtocolHandle.cpp +++ b/utils/McuProtocol/src/ProtocolHandle.cpp @@ -35,6 +35,7 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr ¶m) : m mMakePacketFunc[ASK_FEED_WATCH_DOG] = std::bind(&ProtocolHandle::MakeAskFeedWatchDogPacket, this, _1); mMakePacketFunc[ASK_SET_FEEDING_CYCLE] = std::bind(&ProtocolHandle::MakeAskSetFeedingCyclePacket, this, _1); mMakePacketFunc[ASK_SET_DATE_TIME] = std::bind(&ProtocolHandle::MakeAskSetDateTimePacket, this, _1); + mMakePacketFunc[ASK_SET_PIR_SENSITIVITY] = std::bind(&ProtocolHandle::MakeAskSetPirSensitivityPacket, this, _1); } ProtocolHandle::ProtocolHandle(const void *data, const size_t &length) { @@ -46,6 +47,7 @@ ProtocolHandle::ProtocolHandle(const void *data, const size_t &length) mAnalyzePacketFunc[REPLY_IPC_MISSION] = std::bind(&ProtocolHandle::AnalyzeReplyIpcMissionPacket, this, _1); mAnalyzePacketFunc[REPLY_SET_FEEDING_CYCLE] = std::bind(&ProtocolHandle::AnalyzeReplyResultPacket, this, _1); mAnalyzePacketFunc[REPLY_SET_DATE_TIME] = std::bind(&ProtocolHandle::AnalyzeReplyResultPacket, this, _1); + mAnalyzePacketFunc[REPLY_SET_PIR_SENSITIVITY] = std::bind(&ProtocolHandle::AnalyzeReplyResultPacket, this, _1); } ProtocolHandle::~ProtocolHandle() { @@ -138,6 +140,10 @@ void ProtocolHandle::MakeAskSetDateTimePacket(const std::shared_ptr(param); } +void ProtocolHandle::MakeAskSetPirSensitivityPacket(const std::shared_ptr ¶m) +{ + MakeProtocolData(param); +} void ProtocolHandle::AnalyzeProtocolPacket(void) { ProtocolPacket packet = {0}; diff --git a/utils/McuProtocol/src/ProtocolHandle.h b/utils/McuProtocol/src/ProtocolHandle.h index 8e8b8c0..012e5a5 100644 --- a/utils/McuProtocol/src/ProtocolHandle.h +++ b/utils/McuProtocol/src/ProtocolHandle.h @@ -45,6 +45,8 @@ enum PROTOCOL_COMMAND REPLY_SET_FEEDING_CYCLE = 0x0104, ASK_SET_DATE_TIME = 0x8107, REPLY_SET_DATE_TIME = 0x0107, + ASK_SET_PIR_SENSITIVITY = 0x8108, + REPLY_SET_PIR_SENSITIVITY = 0x0108, PROTOCOL_COMMAND_END }; constexpr unsigned char ZERO_MEANS_SHUTDOWN_WATCH_DOG = 0x00; @@ -126,6 +128,7 @@ private: void MakeAskFeedWatchDogPacket(const std::shared_ptr ¶m); void MakeAskSetFeedingCyclePacket(const std::shared_ptr ¶m); void MakeAskSetDateTimePacket(const std::shared_ptr ¶m); + void MakeAskSetPirSensitivityPacket(const std::shared_ptr ¶m); template void MakeProtocolData(const std::shared_ptr ¶m) {