From 5bf3a2694875c52e9af429033ebc682dbc544c68 Mon Sep 17 00:00:00 2001 From: DashyFox Date: Thu, 25 Jan 2024 15:46:11 +0300 Subject: [PATCH] dataPack changes done --- IR_Decoder.cpp | 113 +++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/IR_Decoder.cpp b/IR_Decoder.cpp index bfc6cbf..293312b 100644 --- a/IR_Decoder.cpp +++ b/IR_Decoder.cpp @@ -75,76 +75,57 @@ void IR_Decoder::writeToBuffer(bool bit) { #endif - - - - - - - - - - - - - - - - - - - /* -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //const auto testval = bufferBitSizeMax; - if ((bufBitPos >= (8 * msgBytes) - syncBits) && !isMsgAvaliable) { - switch ((rawBuffer[0] >> 5) & IR_MASK_MSG_TYPE) { - case IR_MSG_ACCEPT: - if (bufBitPos >= ((msgBytes + addrBytes + crcBytes) * (8 + 3)) - syncBits) { - const uint8_t dataSize = msgBytes + addrBytes; - isRawAvaliable = true; - isMsgAvaliable = crcCheck(dataSize); - if (isMsgAvaliable && checkAddr(1, 2)) { - gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime); - gotAccept._isAvaliable = true; - } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //const auto testval = bufferBitSizeMax; + if ((i_dataBuffer >= (8 * msgBytes)) && !isMsgAvaliable) { + switch ((dataBuffer[0] >> 5) & IR_MASK_MSG_TYPE) { + case IR_MSG_ACCEPT: + if (i_dataBuffer >= ((msgBytes + addrBytes + crcBytes) * bitPerByte)) { + const uint8_t dataSize = msgBytes + addrBytes; + isRawAvaliable = true; + isMsgAvaliable = crcCheck(dataSize); + if (isMsgAvaliable && checkAddr(1, 2)) { + gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime); + gotAccept._isAvaliable = true; } - break; + } + break; - case IR_MSG_REQUEST: - if (bufBitPos >= ((msgBytes + addrBytes + addrBytes + crcBytes) * (8 + 3)) - syncBits) { - const uint8_t dataSize = msgBytes + addrBytes + addrBytes; - isRawAvaliable = true; - isMsgAvaliable = (crcCheck(dataSize)); - if (isMsgAvaliable && checkAddr(3, 4)) { - gotRequest._isAvaliable = true; - gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime); - } + case IR_MSG_REQUEST: + if (i_dataBuffer >= ((msgBytes + addrBytes + addrBytes + crcBytes) * bitPerByte)) { + const uint8_t dataSize = msgBytes + addrBytes + addrBytes; + isRawAvaliable = true; + isMsgAvaliable = (crcCheck(dataSize)); + if (isMsgAvaliable && checkAddr(3, 4)) { + gotRequest._isAvaliable = true; + gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime); } - break; + } + break; - case IR_MSG_DATA_ACCEPT: - case IR_MSG_DATA_NOACCEPT: - if (bufBitPos >= ((bitPerByte + syncBits) * ((rawBuffer[0] & IR_MASK_MSG_INFO) + crcBytes)) - syncBits) { - const uint8_t dataSize = (rawBuffer[0] & IR_MASK_MSG_INFO); - isRawAvaliable = true; - isMsgAvaliable = crcCheck(dataSize); - if (isMsgAvaliable && checkAddr(3, 4)) { - gotData._isAvaliable = true; - gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime); - } else { - gotRawData._isAvaliable = true; - gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime); - } + case IR_MSG_DATA_ACCEPT: + case IR_MSG_DATA_NOACCEPT: + if (i_dataBuffer >= ((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes) * bitPerByte) { + // Serial.println("OK"); + const uint8_t dataSize = (dataBuffer[0] & IR_MASK_MSG_INFO); + isRawAvaliable = true; + isMsgAvaliable = crcCheck(dataSize); + if (isMsgAvaliable && checkAddr(3, 4)) { + gotData._isAvaliable = true; + gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime); + } else { + gotRawData._isAvaliable = true; + gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime); } - break; - - default: - break; - } - }/**/ - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + } + break; + default: + break; + } + }/**/ + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } // uint8_t* IR_Decoder::getDataBuffer(bool reset = false) { @@ -186,12 +167,6 @@ void IR_Decoder::writeToBuffer(bool bit) { bool IR_Decoder::crcCheck(uint8_t len) { bool crcOK = false; - // получить буффер, если нет - if (!isFilterBufferAvaliable) getDataBuffer(); - if (dataBuffer == nullptr) { - - return false; - } crcValue = 0; crcValue = (crc8(dataBuffer, 0, len, poly1) << 8) & ~((crc_t)0xFF);