addr check flag added

This commit is contained in:
2024-02-20 16:35:02 +03:00
parent 2afb7cff23
commit 024888e841
4 changed files with 105 additions and 74 deletions

View File

@ -1,7 +1,7 @@
#include "IR_Decoder.h"
#include "IR_Encoder.h"
#define IRDEBUG_INFO
#define checkAddr(h, l) (\
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == id) || \
@ -360,26 +360,49 @@ void IR_Decoder::writeToBuffer(bool bit) {
if ((i_dataBuffer >= (8 * msgBytes)) && !isCrcCorrect) {
uint16_t crcValue;
uint8_t packSize;
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
}
);
packSize = (dataBuffer[0] & (IR_MASK_MSG_INFO >> 1)) + crcBytes;
if (i_dataBuffer != packSize * bitPerByte) break;
if ((dataBuffer[0] & 0b00010000)) { // С адресацией
packToOutClass(
packSize, // packSize
gotData, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
3, // addrToOffset
5, // dataOffset
NULL // crcOffset
},
true
);
} else { // Без адресации
packToOutClass(
packSize, // packSize
gotData, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
3, // addrToOffset
3, // dataOffset
NULL // crcOffset
},
false
);
}
break;
case IR_MSG_ACCEPT:
packSize = msgBytes + addrBytes + crcBytes;
if (i_dataBuffer != packSize * bitPerByte) break;
packToOutClass(
((msgBytes + addrBytes + crcBytes)), // packSize
gotAccept, // obj
packSize, // packSize
gotAccept, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
@ -391,9 +414,12 @@ void IR_Decoder::writeToBuffer(bool bit) {
break;
case IR_MSG_REQUEST:
packSize = msgBytes + addrBytes + addrBytes + crcBytes;
if (i_dataBuffer != packSize * bitPerByte) break;
packToOutClass(
((msgBytes + addrBytes + addrBytes + crcBytes)), // packSize
gotRequest, // obj
packSize, // packSize
gotRequest, // obj
PackOffsets {
0, // msgOffset
1, // addrFromOffset
@ -407,8 +433,11 @@ void IR_Decoder::writeToBuffer(bool bit) {
case IR_MSG_DATA_ACCEPT:
case IR_MSG_DATA_NOACCEPT:
packSize = (dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes;
if (i_dataBuffer != packSize * bitPerByte) break;
packToOutClass(
(((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes)), // packSize
packSize, // packSize
gotData, // obj
PackOffsets {
0, // msgOffset
@ -427,41 +456,27 @@ void IR_Decoder::writeToBuffer(bool bit) {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void IR_Decoder::packToOutClass(uint8_t packSize, IDataPack& obj, PackOffsets offsets) {
if (i_dataBuffer == packSize * bitPerByte) {
PackOutInfo packInfo;
void IR_Decoder::packToOutClass(uint8_t packSize, IDataPack& obj, PackOffsets offsets, bool isNeedAddressCheck = true) {
PackOutInfo packInfo;
#ifdef IRDEBUG_INFO
Serial.print(" IN ");
#endif
isCrcCorrect = crcCheck(packSize - crcBytes, packInfo.crc);
if (isCrcCorrect) {
packInfo.ptr = dataBuffer;
packInfo.packSize = packSize;
packInfo.offsets = offsets;
packInfo.offsets.crcOffset = packInfo.packSize - crcBytes;
packInfo.err = errors;
packInfo.rTime = riseSyncTime;
obj.set(packInfo, isNeedAddressCheck);
} else {
#ifdef IRDEBUG_INFO
Serial.print(" IN ");
Serial.println(" CRC WRONG ");
#endif
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 {
#ifdef IRDEBUG_INFO
Serial.println(" CRC WRONG ");
#endif
}
isRecive = false;
}
isRecive = false;
}