This commit is contained in:
2024-02-20 15:00:00 +03:00
parent e4aa7b47c5
commit 27dd448cb0
4 changed files with 192 additions and 136 deletions

View File

@ -9,10 +9,8 @@
)
IR_Decoder::IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : isrPin(isrPin), id(addr), encoder(encPair) {
// rawBuffer = new uint8_t[bufferRawSize] { 0 };
dataBuffer = new uint8_t[dataByteSizeMax] { 0 };
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
// start_RX();
}
IR_Decoder::~IR_Decoder() {
@ -35,7 +33,7 @@ void IR_Decoder::isr() {
firstUnHandledFront = firstUnHandledFront->next;
#ifdef IRDEBUG_INFO
// Serial.println();
// Serial.println("ERROR");
Serial.println(" ISR BUFFER OVERFLOW ");
// Serial.println();
#endif
}
@ -124,7 +122,7 @@ void IR_Decoder::tick() {
// Serial.print("preambFrontCounter: "); Serial.println(preambFrontCounter);
} else {
if (isPreamb) {// первый фронт после
gotTune.set(dataBuffer, 1, 0, errors, riseSyncTime);
gotTune.set(riseSyncTime);
}
isPreamb = false;
}
@ -350,7 +348,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//const auto testval = bufferBitSizeMax;
#ifdef IRDEBUG_INFO
if (isData) {
if (i_dataBuffer == ((msgBytes)*bitPerByte)) { Serial.print(" -> "); Serial.print(dataBuffer[0] & IR_MASK_MSG_INFO); Serial.print(" ->"); }
@ -363,21 +361,46 @@ void IR_Decoder::writeToBuffer(bool bit) {
if ((i_dataBuffer >= (8 * msgBytes)) && !isCrcCorrect) {
uint16_t crcValue;
switch ((dataBuffer[0] >> 5) & IR_MASK_MSG_TYPE) {
case IR_MSG_BACK:
packToOutClass(
(((dataBuffer[0] & (IR_MASK_MSG_INFO >> 1)) + crcBytes)), // packSize
gotData, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
NULL, // addrToOffset
3, // dataOffset
NULL // crcOffset
}
);
break;
case IR_MSG_ACCEPT:
packToOutClass(
((msgBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
(msgBytes + addrBytes), // bytesToCheck
1, // addressForCheck_Offset
&gotAccept // objFine
((msgBytes + addrBytes + crcBytes)), // packSize
gotAccept, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
NULL, // addrToOffset
NULL, // dataOffset
3 // crcOffset
}
);
break;
case IR_MSG_REQUEST:
packToOutClass(
((msgBytes + addrBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
(msgBytes + addrBytes + addrBytes), // bytesToCheck
3, // addressForCheck_Offset
&gotRequest // objFine
((msgBytes + addrBytes + addrBytes + crcBytes)), // packSize
gotRequest, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
3, // addrToOffset
NULL, // dataOffset
5 // crcOffset
}
);
break;
@ -385,11 +408,15 @@ void IR_Decoder::writeToBuffer(bool bit) {
case IR_MSG_DATA_ACCEPT:
case IR_MSG_DATA_NOACCEPT:
packToOutClass(
(((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes) * bitPerByte), // endBitOffset
(dataBuffer[0] & IR_MASK_MSG_INFO), // bytesToCheck
3, // addressForCheck_Offset
&gotData, // objFine
&gotRawData // objWrong
(((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes)), // packSize
gotData, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
3, // addrToOffset
5, // dataOffset
NULL // crcOffset
}
);
break;
@ -400,29 +427,39 @@ void IR_Decoder::writeToBuffer(bool bit) {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void IR_Decoder::packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint8_t addressForCheckOffset, IDataPack* objFine, IDataPack* objWrong = nullptr) {
uint16_t crcValue;
IDataPack* objResult = nullptr;
if (i_dataBuffer == endBitOffset) {
void IR_Decoder::packToOutClass(uint8_t packSize, IDataPack& obj, PackOffsets offsets) {
if (i_dataBuffer == packSize * bitPerByte) {
PackOutInfo packInfo;
#ifdef IRDEBUG_INFO
Serial.print(" IN ");
#endif
isCrcCorrect = crcCheck(bytesToCheck, crcValue);
if (isCrcCorrect && checkAddr(addressForCheckOffset, addressForCheckOffset + 1)) {
#ifdef IRDEBUG_INFO
Serial.println(" OK ");
#endif
objResult = objFine;
isCrcCorrect = crcCheck(packSize - crcBytes, packInfo.crc);
if (isCrcCorrect) {
// if ((addressForCheckOffset >= 0 ? checkAddr(addressForCheckOffset, addressForCheckOffset + 1) : 1)) {// адрес верен
// #ifdef IRDEBUG_INFO
// Serial.println(" OK ");
// #endif
// } else { // адресс не верен
// #ifdef IRDEBUG_INFO
// Serial.println(" NOT MY ");
// #endif
// }
packInfo.ptr = dataBuffer;
packInfo.packSize = packSize;
packInfo.offsets = offsets;
packInfo.offsets.crcOffset = packInfo.packSize - crcBytes;
packInfo.err = errors;
packInfo.rTime = riseSyncTime;
obj.set(packInfo);
} else {
objResult = objWrong;
#ifdef IRDEBUG_INFO
Serial.println(" NOT OK ");
Serial.println(" CRC WRONG ");
#endif
}
if (objWrong != nullptr) {
objResult->isAvaliable = true;
objResult->set(dataBuffer, bytesToCheck + crcBytes, crcValue, errors, riseSyncTime);
}
isRecive = false;
}
}