Add:contor infrared light and get photosensitivity value.

This commit is contained in:
Fancy code 2024-02-12 23:46:11 -08:00
parent 67993b88ca
commit b190fcead7
12 changed files with 282 additions and 5 deletions

View File

@ -537,12 +537,14 @@ end
   流水号用于强绑定问答型协议的发送数据和回复数据,回复者原数据回传即可。例如:
```
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_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01, 0x00, 0x0C, 0x71, 0x88};
unsigned char REPLY_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xAA, 0x89};
```
   流水号管理发送方和接收方互相独立,各自往外发的协议中流水号存在重复的可能,接收方直接复制回传即可。
   流水号必须大于等于10用于代码初始化值代码意义上表示无效的流水号。
**校验码算法**
   校验码算法使用ModBus CRC16方法计算。

View File

@ -34,6 +34,12 @@ enum class ASK_RESULT
TIMEOUT,
END
};
enum class ControlLight
{
TRUN_OFF = 0,
TRUN_ON,
END
};
typedef struct mcu_ask_date_time
{
const unsigned short mYear;
@ -99,5 +105,7 @@ public:
const unsigned char &min, const unsigned char &second);
virtual const StatusCode SetDateTime(std::shared_ptr<VMcuAsk> &ask, const McuAskDateTime &value);
virtual const StatusCode SetPirSensitivity(std::shared_ptr<VMcuAsk> &ask, const unsigned char &sensitivity);
virtual const StatusCode ContorlInfraredLight(std::shared_ptr<VMcuAsk> &ask, const ControlLight &control);
virtual const StatusCode GetPhotosensitivityValue(std::shared_ptr<VMcuAsk> &ask);
};
#endif

View File

@ -56,6 +56,14 @@ const StatusCode IMcuManager::SetDateTime(std::shared_ptr<VMcuAsk> &ask, const M
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
const StatusCode IMcuManager::SetPirSensitivity(std::shared_ptr<VMcuAsk> &ask, const unsigned char &sensitivity)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
const StatusCode IMcuManager::ContorlInfraredLight(std::shared_ptr<VMcuAsk> &ask, const ControlLight &control)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
const StatusCode IMcuManager::GetPhotosensitivityValue(std::shared_ptr<VMcuAsk> &ask)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}

View File

@ -65,6 +65,16 @@ const StatusCode McuManagerImpl::SetPirSensitivity(std::shared_ptr<VMcuAsk> &ask
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
return McuProtocol::SetPirSensitivity(sensitivity, context);
}
const StatusCode McuManagerImpl::ContorlInfraredLight(std::shared_ptr<VMcuAsk> &ask, const ControlLight &control)
{
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
return McuProtocol::ContorlInfraredLight(static_cast<const unsigned char>(control), context);
}
const StatusCode McuManagerImpl::GetPhotosensitivityValue(std::shared_ptr<VMcuAsk> &ask)
{
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
return McuProtocol::GetPhotosensitivityValue(context);
}
std::shared_ptr<VMcuMonitor> McuManagerImpl::GetMcuMonitor(void)
{
auto monitor = mMonitor.lock();

View File

@ -33,6 +33,8 @@ public:
const unsigned char &min, const unsigned char &second) override;
const StatusCode SetDateTime(std::shared_ptr<VMcuAsk> &ask, const McuAskDateTime &value) override;
const StatusCode SetPirSensitivity(std::shared_ptr<VMcuAsk> &ask, const unsigned char &sensitivity) override;
const StatusCode ContorlInfraredLight(std::shared_ptr<VMcuAsk> &ask, const ControlLight &control) override;
const StatusCode GetPhotosensitivityValue(std::shared_ptr<VMcuAsk> &ask) override;
private:
std::shared_ptr<VMcuMonitor> GetMcuMonitor(void);

View File

@ -283,6 +283,68 @@ 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)
{
/**
* @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<ASK_RESULT>, 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<int>(mDataReply));
// Do something here.
}
else {
LogError("Ask data falied.\n");
}
}
};
IMcuManager::GetInstance()->Init();
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskTest>();
IMcuManager::GetInstance()->ContorlInfraredLight(ask, ControlLight::TRUN_ON);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
IMcuManager::GetInstance()->UnInit();
}
// ../output_files/test/bin/McuManagerTest
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_EXAMPLE_GetPhotosensitivityValue)
{
/**
* @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<ASK_RESULT>, 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<int>(mDataReply));
// Do something here.
}
else {
LogError("Ask data falied.\n");
}
}
};
IMcuManager::GetInstance()->Init();
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskTest>();
IMcuManager::GetInstance()->GetPhotosensitivityValue(ask);
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)
{
@ -343,6 +405,31 @@ 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)
{

View File

@ -52,6 +52,12 @@ private:
size_t count);
void SetPirSensitivityProtocolInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
size_t count);
bool ContorlInfraredLightHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
void ContorlInfraredLightInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
bool GetPhotosensitivityValueHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
size_t count);
void GetPhotosensitivityValueInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
size_t count);
void LockProtocolHandle(void);
void UnlockProtocolHandle(void);
void UnlockThread(void);
@ -67,8 +73,10 @@ private:
static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const int event);
private:
// virtual void MonitorWriteProtocolData(const short &head, const unsigned int &serialNumber, const short &command,
// const void *data, const short &packetLength)
// virtual void MonitorWriteProtocolData(const short &head, const unsigned int
// &serialNumber, const short &command,
// const void *data, const short
// &packetLength)
// {
// }

View File

@ -54,6 +54,13 @@ unsigned char ASK_SET_PIR_SENSITIVITY_X[] = {
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x08, 0x00, 0x0D, 0x09, 0xFF, 0xFF};
unsigned char REPLY_SET_PIR_SENSITIVITY_X[] = {
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x0D, 0x01, 0xFF, 0xFF};
unsigned char ASK_CONTORL_INFRARED_LIGHT_X[] = {
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x0A, 0x00, 0x0D, 0x01, 0xFF, 0xFF};
unsigned char REPLY_ASK_CONTORL_INFRARED_LIGHT_X[] = {
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0A, 0x00, 0x0D, 0x01, 0xFF, 0xFF};
unsigned char ASK_GET_PHOTOSENSITIVITY_X[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x81, 0x0B, 0x00, 0x0C, 0xFF, 0xFF};
unsigned char REPLY_ASK_GET_PHOTOSENSITIVITY_X[] = {
0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0B, 0x00, 0x0D, 0x0A, 0xFF, 0xFF};
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[] = {
@ -72,6 +79,8 @@ McuProtocolTestTool::McuProtocolTestTool()
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));
mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::ContorlInfraredLightHandle, this, _1, _2, _3, _4));
mProtocolHandle.push_back(std::bind(&McuProtocolTestTool::GetPhotosensitivityValueHandle, this, _1, _2, _3, _4));
}
void McuProtocolTestTool::Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart)
{
@ -97,6 +106,7 @@ void McuProtocolTestTool::Init(std::shared_ptr<LinuxTest> &mock, const UartInfo
return;
}
}
LogWarning("Can't find protocol handle function.\n");
};
EXPECT_CALL(*mock.get(), fx_write(uartFd, _, _))
.WillRepeatedly(
@ -441,6 +451,107 @@ void McuProtocolTestTool::SetPirSensitivityProtocolInit(std::shared_ptr<LinuxTes
.WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(apiReadLeftData)), Return(LEFT_DATA_LENGTH)))
.WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING)));
}
bool McuProtocolTestTool::ContorlInfraredLightHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
const void *buf, size_t count)
{
if (sizeof(ASK_CONTORL_INFRARED_LIGHT_X) == count && memcmp(ASK_CONTORL_INFRARED_LIGHT_X + PROTOCOL_COMMAND_OFFSET,
(unsigned char *)buf + PROTOCOL_COMMAND_OFFSET,
PROTOCOL_COMMAND_LENGTH) == 0) {
short replyCheckCode =
calculate_check_sum(REPLY_ASK_CONTORL_INFRARED_LIGHT_X,
sizeof(REPLY_ASK_CONTORL_INFRARED_LIGHT_X) - PROTOCOL_CHECK_CODE_LENGTH);
replyCheckCode = htons(replyCheckCode);
LogInfo("Set ASK_CONTORL_INFRARED_LIGHT_X, 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->ContorlInfraredLightInit(mock, uartFd, buf, count);
};
if (mLockThread.joinable()) {
mLockThread.join();
}
mLockThread = std::thread(handle, this);
return PROTOCOL_HANDLED;
}
return PROTOCOL_NOT_HANDLED;
}
void McuProtocolTestTool::ContorlInfraredLightInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
size_t count)
{
LockProtocolHandle();
memcpy(REPLY_ASK_CONTORL_INFRARED_LIGHT_X + PROTOCOL_SERIAL_NUMBER_OFFSET,
(unsigned char *)buf + PROTOCOL_SERIAL_NUMBER_OFFSET,
PROTOCOL_SERIAL_NUMBER_LENGTH);
ResetCheckCode(REPLY_ASK_CONTORL_INFRARED_LIGHT_X, sizeof(REPLY_ASK_CONTORL_INFRARED_LIGHT_X));
ReplySelectSucceed(mock, uartFd);
constexpr int LEFT_DATA_LENGTH = sizeof(REPLY_ASK_CONTORL_INFRARED_LIGHT_X) - PROTOCOL_DATA_KEY_HEAD_LENGTH;
auto apiReadKeyHead = [=](int fd, void *buf, size_t count) {
memcpy(buf, REPLY_ASK_CONTORL_INFRARED_LIGHT_X, 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_ASK_CONTORL_INFRARED_LIGHT_X + 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)));
}
bool McuProtocolTestTool::GetPhotosensitivityValueHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
const void *buf, size_t count)
{
if (sizeof(ASK_GET_PHOTOSENSITIVITY_X) == count && memcmp(ASK_GET_PHOTOSENSITIVITY_X + PROTOCOL_COMMAND_OFFSET,
(unsigned char *)buf + PROTOCOL_COMMAND_OFFSET,
PROTOCOL_COMMAND_LENGTH) == 0) {
short replyCheckCode = calculate_check_sum(
REPLY_ASK_GET_PHOTOSENSITIVITY_X, sizeof(REPLY_ASK_GET_PHOTOSENSITIVITY_X) - PROTOCOL_CHECK_CODE_LENGTH);
replyCheckCode = htons(replyCheckCode);
LogInfo("Set ASK_GET_PHOTOSENSITIVITY_X, 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->GetPhotosensitivityValueInit(mock, uartFd, buf, count);
};
if (mLockThread.joinable()) {
mLockThread.join();
}
mLockThread = std::thread(handle, this);
return PROTOCOL_HANDLED;
}
return PROTOCOL_NOT_HANDLED;
}
void McuProtocolTestTool::GetPhotosensitivityValueInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
const void *buf, size_t count)
{
LockProtocolHandle();
memcpy(REPLY_ASK_GET_PHOTOSENSITIVITY_X + PROTOCOL_SERIAL_NUMBER_OFFSET,
(unsigned char *)buf + PROTOCOL_SERIAL_NUMBER_OFFSET,
PROTOCOL_SERIAL_NUMBER_LENGTH);
ResetCheckCode(REPLY_ASK_GET_PHOTOSENSITIVITY_X, sizeof(REPLY_ASK_GET_PHOTOSENSITIVITY_X));
ReplySelectSucceed(mock, uartFd);
constexpr int LEFT_DATA_LENGTH = sizeof(REPLY_ASK_GET_PHOTOSENSITIVITY_X) - PROTOCOL_DATA_KEY_HEAD_LENGTH;
auto apiReadKeyHead = [=](int fd, void *buf, size_t count) {
memcpy(buf, REPLY_ASK_GET_PHOTOSENSITIVITY_X, 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_ASK_GET_PHOTOSENSITIVITY_X + 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(); };

View File

@ -31,6 +31,8 @@ class VProtocolContext
public:
VProtocolContext() = default;
virtual ~VProtocolContext() = default;
unsigned int mSerialNumber;
short mCheckCode; // TODO: Need to improve
};
template <typename T>
class ProtocolContext : public VProtocolContext
@ -122,6 +124,8 @@ protected:
const unsigned char &hour, const unsigned char &min, const unsigned char &second,
std::shared_ptr<VProtocolContext> &context);
const StatusCode SetPirSensitivity(const unsigned char &sensitivity, std::shared_ptr<VProtocolContext> &context);
const StatusCode ContorlInfraredLight(const unsigned char &control, std::shared_ptr<VProtocolContext> &context);
const StatusCode GetPhotosensitivityValue(std::shared_ptr<VProtocolContext> &context);
void DataHandleThread(void);
protected:

View File

@ -109,6 +109,23 @@ const StatusCode McuProtocol::SetPirSensitivity(const unsigned char &sensitivity
return WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
}
const StatusCode McuProtocol::ContorlInfraredLight(const unsigned char &control,
std::shared_ptr<VProtocolContext> &context)
{
std::shared_ptr<VProtocolParam> param =
std::make_shared<ProtocolParam<const unsigned char>>(PROTOCOL_COMMAND::ASK_CONTORL_INFRARED_LIGHT, control);
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
return WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
}
const StatusCode McuProtocol::GetPhotosensitivityValue(std::shared_ptr<VProtocolContext> &context)
{
std::shared_ptr<VProtocolParam> param =
std::make_shared<VProtocolParam>(PROTOCOL_COMMAND::ASK_GET_PHOTOSENSITIVITY);
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
return WriteProtocolData(
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
}
void McuProtocol::DataHandleThread(void)
{
mThreadRuning = true;

View File

@ -35,6 +35,10 @@ ProtocolHandle::ProtocolHandle(const std::shared_ptr<VProtocolParam> &param) : m
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);
mMakePacketFunc[ASK_CONTORL_INFRARED_LIGHT] =
std::bind(&ProtocolHandle::MakeAskControlInfraredLightPacket, this, _1);
mMakePacketFunc[ASK_GET_PHOTOSENSITIVITY] = std::bind(&ProtocolHandle::MakeAskGetPhotosensitivityPacket, this, _1);
/**************************************************************************************************************************/
mMakePacketFunc[REPLY_OTHER_SIDE_ASK_SEND_IPC_MISSION] =
std::bind(&ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket, this, _1);
}
@ -49,6 +53,9 @@ ProtocolHandle::ProtocolHandle(const void *data, const size_t &length)
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);
mAnalyzePacketFunc[REPLY_CONTORL_INFRARED_LIGHT] = std::bind(&ProtocolHandle::AnalyzeReplyResultPacket, this, _1);
mAnalyzePacketFunc[REPLY_GET_PHOTOSENSITIVITY] = std::bind(&ProtocolHandle::AnalyzeReplyResultPacket, this, _1);
/**************************************************************************************************************************/
mAnalyzePacketFunc[OTHER_SIDE_ASK_SEND_IPC_MISSION] =
std::bind(&ProtocolHandle::AnalyzeOtherSideSendIpcMissionPacket, this, _1);
}
@ -157,6 +164,14 @@ void ProtocolHandle::MakeReplyOtherSideSendIpcMissionPacket(const std::shared_pt
{
MakeProtocolData<const unsigned char>(param);
}
void ProtocolHandle::MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> &param)
{
MakeProtocolData<const unsigned char>(param);
}
void ProtocolHandle::MakeAskGetPhotosensitivityPacket(const std::shared_ptr<VProtocolParam> &param)
{
MakeNoUserDataPacket(param);
}
void ProtocolHandle::AnalyzeProtocolPacket(void)
{
ProtocolPacket packet = {0};
@ -165,7 +180,6 @@ void ProtocolHandle::AnalyzeProtocolPacket(void)
(unsigned char *)mProtocolData + mProtocolDataLength - sizeof(unsigned short),
sizeof(unsigned short));
HostByteOrderConversion(packet);
PrintHexadecimalData(&packet, sizeof(ProtocolPacket), "HostByteOrderConversion=");
if (CheckoutTheCheckCode(packet) == false) {
LogError("CheckoutTheCheckCode failed.\n");
return;

View File

@ -49,6 +49,10 @@ enum PROTOCOL_COMMAND
REPLY_SET_DATE_TIME = 0x0107,
ASK_SET_PIR_SENSITIVITY = 0x8108,
REPLY_SET_PIR_SENSITIVITY = 0x0108,
ASK_CONTORL_INFRARED_LIGHT = 0x810A,
REPLY_CONTORL_INFRARED_LIGHT = 0x010A,
ASK_GET_PHOTOSENSITIVITY = 0x810B,
REPLY_GET_PHOTOSENSITIVITY = 0x010B,
/**
* @brief The protocol starting from here is a request sent from the other end.
*
@ -141,6 +145,8 @@ private:
void MakeAskSetFeedingCyclePacket(const std::shared_ptr<VProtocolParam> &param);
void MakeAskSetDateTimePacket(const std::shared_ptr<VProtocolParam> &param);
void MakeAskSetPirSensitivityPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeAskControlInfraredLightPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeAskGetPhotosensitivityPacket(const std::shared_ptr<VProtocolParam> &param);
void MakeReplyOtherSideSendIpcMissionPacket(const std::shared_ptr<VProtocolParam> &param);
template <typename T>
void MakeProtocolData(const std::shared_ptr<VProtocolParam> &param)