4 Commits

Author SHA1 Message Date
bc9563fbb5 isReceive type 2025-05-23 11:43:51 +03:00
021e1e290d fix isRX flag 2025-05-22 12:08:22 +03:00
89d14919c9 fix isRecive 2025-03-12 16:15:35 +03:00
403b8e6850 isRecive fix 2025-03-12 15:38:33 +03:00
5 changed files with 66 additions and 10 deletions

View File

@ -61,6 +61,7 @@ void IR_Decoder::tick()
void IR_Decoder::_tick()
{
IR_DecoderRaw::tick();
if (availableRaw())
{
#ifdef IRDEBUG_INFO
@ -102,4 +103,8 @@ void IR_Decoder::_tick()
encoder->sendAccept(addrAcceptSendTo, acceptCustomByte);
isWaitingAcceptSend = false;
}
}
}
bool IR_Decoder::isReceive(uint8_t type) {
return (msgTypeReceive & 0b11111000) && ((msgTypeReceive & IR_MASK_MSG_TYPE) == type);
}

View File

@ -31,6 +31,8 @@ public:
void enable();
void disable();
bool isReceive(uint8_t type);
~IR_Decoder();

View File

@ -112,16 +112,37 @@ void IR_DecoderRaw::firstRX()
void IR_DecoderRaw::listenStart()
{
if (isRecive && ((micros() - prevRise) > IR_timeout * 2))
if (isReciveRaw && ((micros() - prevRise) > IR_timeout * 2))
{
// Serial.print("\nlis>");
isRecive = false;
isReciveRaw = false;
firstRX();
}
}
// ---- быстрая проверка конца пакета ---------------------------------
inline void IR_DecoderRaw::checkTimeout()
{
if (!isRecive) return; // уже не принимаем нечего проверять
if (micros() - lastEdgeTime > IR_timeout * 2U)
{
isRecive = false; // приём завершён
msgTypeReceive = 0;
// firstRX(); // подготовка к новому пакету
lastEdgeTime = micros(); // защита от повторного срабатывания
}
}
// ====================================================================
void IR_DecoderRaw::tick()
{
// FrontStorage *currentFrontPtr;
// noInterrupts();
// currentFrontPtr = subBuffer.pop();
// interrupts();
FrontStorage currentFront;
noInterrupts();
listenStart();
@ -130,12 +151,24 @@ void IR_DecoderRaw::tick()
if (currentFrontPtr == nullptr)
{
isSubBufferOverflow = false;
checkTimeout(); // <--- новое место проверки
interrupts();
return;
} // Если данных нет - ничего не делаем
currentFront = *currentFrontPtr;
interrupts();
// ---------- буфер пуст: фронтов нет, проверяем тайм-аут ----------
// if (currentFrontPtr == nullptr)
// {
// isSubBufferOverflow = false;
// return;
// }
// // ---------- есть фронт: продолжаем обработку ----------
// FrontStorage currentFront = *currentFrontPtr;
lastEdgeTime = currentFront.time; // запоминаем любой фронт
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (currentFront.dir)
@ -197,7 +230,7 @@ void IR_DecoderRaw::tick()
digitalWrite(errOut, currentFront.dir);
#endif
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isRecive)
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isReciveRaw)
{ // первый
#ifdef IRDEBUG
errPulse(up, 50);
@ -209,6 +242,7 @@ void IR_DecoderRaw::tick()
isPreamb = true;
isRecive = true;
isReciveRaw = true;
isWrongPack = false;
}
@ -441,6 +475,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
if (isBufferOverflow || isPreamb || isWrongPack)
{
isRecive = false;
isReciveRaw = false;
msgTypeReceive = 0;
return;
}
@ -564,6 +600,8 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
packInfo.rTime = riseSyncTime;
isRecive = false;
isReciveRaw = false;
msgTypeReceive = 0;
isAvailable = crcCheck(packSize - crcBytes, crcValue);
#ifdef BRUTEFORCE_CHECK
@ -594,6 +632,12 @@ void IR_DecoderRaw::writeToBuffer(bool bit)
OUT_BRUTEFORCE:;
#endif
}
if (packSize && (i_dataBuffer == 8)) {
msgTypeReceive = (dataBuffer[0]>>5) | 0b11111000;
// SerialUSB.println(msgTypeReceive & IR_MASK_MSG_TYPE);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -31,9 +31,10 @@ class IR_DecoderRaw : virtual public IR_FOX
friend IR_Encoder;
protected:
PackInfo packInfo;
IR_Encoder *encoder; // Указатель на парный передатчик
bool availableRaw();
PackInfo packInfo;
uint8_t msgTypeReceive = 0;
IR_Encoder *encoder; // Указатель на парный передатчик
bool availableRaw();
public:
//////////////////////////////////////////////////////////////////////////
@ -48,7 +49,7 @@ public:
inline bool isOverflow() { return isBufferOverflow; }; // Буффер переполнился
bool isSubOverflow();
inline bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
volatile inline bool isReciving() { return isRecive; }; // Возвращает true, если происходит приём пакета
//////////////////////////////////////////////////////////////////////////
private:
@ -65,6 +66,8 @@ private:
uint16_t riseSyncTime = bitTime; // Подстраиваемое время бита в мкс
volatile uint32_t lastEdgeTime = 0; // время последнего фронта
////////////////////////////////////////////////////////////////////////
volatile uint32_t currentSubBufferIndex; // Счетчик текущей позиции во вспомогательном буфере фронтов/спадов
@ -100,7 +103,9 @@ private:
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
private:
void listenStart(); // @brief Слушатель для работы isReciving()
bool isReciveRaw;
void listenStart();
void checkTimeout(); //
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
/// @param len Длина в байтах проверяемых данных

View File

@ -122,7 +122,7 @@ typedef uint16_t crc_t;
#endif
#ifndef subBufferSize
#define subBufferSize 50 // Буфер для складирования фронтов, пока их не обработают (передатчик)
#define subBufferSize 250 // Буфер для складирования фронтов, пока их не обработают (передатчик)
#endif
#define preambPulse 3