From 686f2a7ffe9219d305c73ce5754cd1b57aad8aff Mon Sep 17 00:00:00 2001 From: DashyFox Date: Wed, 21 Feb 2024 17:08:53 +0300 Subject: [PATCH] fix Accept --- IR_Encoder.cpp | 14 +++++++------- IR_Encoder.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/IR_Encoder.cpp b/IR_Encoder.cpp index 64a9837..1c8c594 100644 --- a/IR_Encoder.cpp +++ b/IR_Encoder.cpp @@ -68,7 +68,7 @@ void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool need rawSend(sendBuffer, packSize); } -void IR_Encoder::sendACK(uint16_t addrTo, uint8_t addInfo, bool forAll = false) { +void IR_Encoder::sendAccept(uint16_t addrTo, uint8_t addInfo, bool forAll = false) { memset(sendBuffer, 0x00, dataByteSizeMax); sendBuffer[0] = IR_MSG_ACCEPT << 5; sendBuffer[0] |= addInfo & IR_MASK_MSG_INFO; @@ -106,22 +106,22 @@ void IR_Encoder::sendRequest(uint16_t addrTo, uint8_t addInfo) { rawSend(sendBuffer, msgBytes + addrBytes + addrBytes + crcBytes); } -void IR_Encoder::sendBack(uint8_t* data = nullptr, uint8_t len = 0){ +void IR_Encoder::sendBack(uint8_t* data = nullptr, uint8_t len = 0) { _sendBack(false, 0, data, len); } -void IR_Encoder::sendBackTo(uint16_t addrTo, uint8_t* data = nullptr, uint8_t len = 0){ +void IR_Encoder::sendBackTo(uint16_t addrTo, uint8_t* data = nullptr, uint8_t len = 0) { _sendBack(true, addrTo, data, len); } -void IR_Encoder::_sendBack(bool isAdressed ,uint16_t addrTo,uint8_t* data, uint8_t len){ +void IR_Encoder::_sendBack(bool isAdressed, uint16_t addrTo, uint8_t* data, uint8_t len) { if (len > bytePerPack) { return; } memset(sendBuffer, 0x00, dataByteSizeMax); - constexpr uint8_t dataStart = msgBytes + addrBytes; + uint8_t dataStart = msgBytes + addrBytes + (isAdressed ? addrBytes : 0); - uint8_t packSize = msgBytes + addrBytes + len + crcBytes; + uint8_t packSize = msgBytes + addrBytes + (isAdressed ? addrBytes : 0) + min(1, len) + crcBytes; uint8_t msgType = - (IR_MSG_BACK << 5) | (isAdressed << 4U) | ((packSize - crcBytes) & (IR_MASK_MSG_INFO>>1)); + (IR_MSG_BACK << 5) | (isAdressed << 4U) | ((packSize - crcBytes) & (IR_MASK_MSG_INFO >> 1)); // формирование массива // msg_type diff --git a/IR_Encoder.h b/IR_Encoder.h index 2712b3b..b791ffe 100644 --- a/IR_Encoder.h +++ b/IR_Encoder.h @@ -45,7 +45,7 @@ public: void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count); void rawSend(uint8_t* ptr, uint8_t len); void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false); - void sendACK(uint16_t addrTo, uint8_t addInfo = 0, bool forAll = false); + void sendAccept(uint16_t addrTo, uint8_t addInfo = 0, bool forAll = false); void sendRequest(uint16_t addrTo, uint8_t addInfo = 0); void sendBack(uint8_t* data = nullptr, uint8_t len = 0); void sendBackTo(uint16_t addrTo, uint8_t* data = nullptr, uint8_t len = 0);