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() void IR_Decoder::_tick()
{ {
IR_DecoderRaw::tick(); IR_DecoderRaw::tick();
if (availableRaw()) if (availableRaw())
{ {
#ifdef IRDEBUG_INFO #ifdef IRDEBUG_INFO
@ -103,3 +104,7 @@ void IR_Decoder::_tick()
isWaitingAcceptSend = false; isWaitingAcceptSend = false;
} }
} }
bool IR_Decoder::isReceive(uint8_t type) {
return (msgTypeReceive & 0b11111000) && ((msgTypeReceive & IR_MASK_MSG_TYPE) == type);
}

View File

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

View File

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

View File

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

View File

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