mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 15:20:16 +00:00
add packToOutClass func
This commit is contained in:
parent
4a8195e561
commit
a143dcf80d
@ -1,7 +1,7 @@
|
|||||||
#include "IR_Decoder.h"
|
#include "IR_Decoder.h"
|
||||||
#include "IR_Encoder.h"
|
#include "IR_Encoder.h"
|
||||||
|
|
||||||
// #define IRDEBUG_INFO
|
#define IRDEBUG_INFO
|
||||||
|
|
||||||
#define checkAddr(h, l) (\
|
#define checkAddr(h, l) (\
|
||||||
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
|
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
|
||||||
@ -326,10 +326,13 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
i_syncBit++;
|
i_syncBit++;
|
||||||
}
|
}
|
||||||
////////////////////// Проверка наличия битов синхранизации //////////////////////
|
////////////////////// Проверка наличия битов синхранизации //////////////////////
|
||||||
isWrongPack = (err_syncBit >= syncBits);
|
if (isWrongPack = (err_syncBit >= syncBits)) {
|
||||||
#ifdef IRDEBUG_INFO
|
start_RX();
|
||||||
if (isWrongPack) Serial.print("****************");
|
#ifdef IRDEBUG_INFO
|
||||||
#endif
|
Serial.print("****************");
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
}//**************************************************************************************************//
|
}//**************************************************************************************************//
|
||||||
|
|
||||||
// Serial.print(bit);
|
// Serial.print(bit);
|
||||||
@ -348,54 +351,38 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
if (i_dataBuffer == ((dataBuffer[0] & IR_MASK_MSG_INFO) * bitPerByte)) { Serial.print(" <-"); }
|
if (i_dataBuffer == ((dataBuffer[0] & IR_MASK_MSG_INFO) * bitPerByte)) { Serial.print(" <-"); }
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((i_dataBuffer >= (8 * msgBytes)) && !isCrcCorrect) {
|
if ((i_dataBuffer >= (8 * msgBytes)) && !isCrcCorrect) {
|
||||||
uint16_t crcValue;
|
uint16_t crcValue;
|
||||||
switch ((dataBuffer[0] >> 5) & IR_MASK_MSG_TYPE) {
|
switch ((dataBuffer[0] >> 5) & IR_MASK_MSG_TYPE) {
|
||||||
case IR_MSG_ACCEPT:
|
case IR_MSG_ACCEPT:
|
||||||
if (i_dataBuffer >= ((msgBytes + addrBytes + crcBytes) * bitPerByte)) {
|
packToOutClass(
|
||||||
constexpr uint8_t dataSize = msgBytes + addrBytes;
|
((msgBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
|
||||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
(msgBytes + addrBytes), // bytesToCheck
|
||||||
if (isCrcCorrect && checkAddr(1, 2)) {
|
1, // addressForCheckOffset
|
||||||
gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errors, riseSyncTime);
|
&gotAccept // objFine
|
||||||
gotAccept._isAvaliable = true;
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IR_MSG_REQUEST:
|
case IR_MSG_REQUEST:
|
||||||
if (i_dataBuffer >= ((msgBytes + addrBytes + addrBytes + crcBytes) * bitPerByte)) {
|
packToOutClass(
|
||||||
constexpr uint8_t dataSize = msgBytes + addrBytes + addrBytes;
|
((msgBytes + addrBytes + addrBytes + crcBytes) * bitPerByte), // endBitOffset
|
||||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
(msgBytes + addrBytes + addrBytes), // bytesToCheck
|
||||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
3, // addressForCheckOffset
|
||||||
gotRequest._isAvaliable = true;
|
&gotRequest // objFine
|
||||||
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errors, riseSyncTime);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case IR_MSG_DATA_ACCEPT:
|
case IR_MSG_DATA_ACCEPT:
|
||||||
case IR_MSG_DATA_NOACCEPT:
|
case IR_MSG_DATA_NOACCEPT:
|
||||||
if (i_dataBuffer >= ((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes) * bitPerByte) {
|
packToOutClass(
|
||||||
#ifdef IRDEBUG_INFO
|
(((dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes) * bitPerByte), // endBitOffset
|
||||||
Serial.print(" IN ");
|
(dataBuffer[0] & IR_MASK_MSG_INFO), // bytesToCheck
|
||||||
#endif
|
3, // addressForCheckOffset
|
||||||
const uint8_t dataSize = (dataBuffer[0] & IR_MASK_MSG_INFO);
|
&gotData, // objFine
|
||||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
&gotRawData // objWrong
|
||||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
);
|
||||||
#ifdef IRDEBUG_INFO
|
|
||||||
Serial.println(" OK ");
|
|
||||||
#endif
|
|
||||||
gotData._isAvaliable = true;
|
|
||||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
|
||||||
} else {
|
|
||||||
gotRawData._isAvaliable = true;
|
|
||||||
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
|
||||||
#ifdef IRDEBUG_INFO
|
|
||||||
Serial.println(" NOT OK ");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -405,6 +392,34 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IR_Decoder::packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint8_t addressForCheckOffset, InputData* objFine, InputData* objWrong = nullptr) {
|
||||||
|
uint16_t crcValue;
|
||||||
|
InputData* objResult = nullptr;
|
||||||
|
if (i_dataBuffer >= endBitOffset) {
|
||||||
|
#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;
|
||||||
|
} else {
|
||||||
|
objResult = objWrong;
|
||||||
|
#ifdef IRDEBUG_INFO
|
||||||
|
Serial.println(" NOT OK ");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (objWrong != nullptr) {
|
||||||
|
objResult->_isAvaliable = true;
|
||||||
|
objResult->_set(dataBuffer, bytesToCheck + crcBytes, crcValue, errors, riseSyncTime);
|
||||||
|
}
|
||||||
|
isRecive = false;
|
||||||
|
start_RX();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool IR_Decoder::crcCheck(uint8_t len, crc_t& crc) {
|
bool IR_Decoder::crcCheck(uint8_t len, crc_t& crc) {
|
||||||
|
@ -257,11 +257,13 @@ private:
|
|||||||
/// @brief Запиь бита в буффер, а так же проверка битов синхранизации и их фильтрация
|
/// @brief Запиь бита в буффер, а так же проверка битов синхранизации и их фильтрация
|
||||||
/// @param Бит данных
|
/// @param Бит данных
|
||||||
void writeToBuffer(bool);
|
void writeToBuffer(bool);
|
||||||
|
void packToOutClass(uint8_t endBitOffset, uint8_t bytesToCheck, uint8_t addressForCheckOffset, InputData* objFine, InputData* objWrong = nullptr);
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// @brief Установка и сброс начальных значений и флагов в готовность к приёму данных
|
/// @brief Установка и сброс начальных значений и флагов в готовность к приёму данных
|
||||||
void start_RX();
|
void start_RX();
|
||||||
|
|
||||||
|
|
||||||
/// @brief Целочисленное деление с округлением вверх
|
/// @brief Целочисленное деление с округлением вверх
|
||||||
/// @param val Значение
|
/// @param val Значение
|
||||||
/// @param divider Делитель
|
/// @param divider Делитель
|
||||||
|
Loading…
x
Reference in New Issue
Block a user