fix forever loop ?

This commit is contained in:
DashyFox 2024-02-26 15:42:27 +03:00
parent 1dc702f05d
commit 1f62eb8c0a
2 changed files with 22 additions and 16 deletions

View File

@ -46,7 +46,7 @@ void IR_DecoderRaw::isr() {
void IR_DecoderRaw::firstRX() {
#ifdef IRDEBUG_INFO
Serial.print("\n>");
Serial.print("\nRX>");
#endif
errors.reset();
@ -67,8 +67,9 @@ void IR_DecoderRaw::firstRX() {
memset(dataBuffer, 0x00, dataByteSizeMax);
}
void IR_DecoderRaw::listenEnd() {
void IR_DecoderRaw::listenStart() {
if (isRecive && ((micros() - prevRise) > IR_timeout * 2)) {
Serial.print("\nlis>");
isRecive = false;
firstRX();
}
@ -77,10 +78,11 @@ void IR_DecoderRaw::listenEnd() {
void IR_DecoderRaw::tick() {
FrontStorage currentFront;
noInterrupts();
listenEnd();
listenStart();
if (firstUnHandledFront == nullptr) { interrupts(); return; } //Если данных нет - ничего не делаем
currentFront = *((FrontStorage*)firstUnHandledFront); //найти следующий необработанный фронт/спад
interrupts();
if (currentFront.next == nullptr) { isRecive = false; return; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (currentFront.time > prevRise && currentFront.time - prevRise > IR_timeout * 2 && !isRecive) { // первый
@ -101,7 +103,7 @@ void IR_DecoderRaw::tick() {
}
if (preambFrontCounter > 0) { // в преамбуле
uint32_t risePeriod = currentFront.time - prevRise;
risePeriod = currentFront.time - prevRise;
if (currentFront.dir && risePeriod < IR_timeout) { // __/``` ↑ и мы в внутри пакета
if (risePeriod < riseTimeMin << 1) { // fix рваной единицы
@ -276,7 +278,10 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
#endif
isBufferOverflow = true;
}
if (isBufferOverflow || isPreamb || isWrongPack) return;
if (isBufferOverflow || isPreamb || isWrongPack) {
isRecive = false;
return;
}
// Переключение флага, data или syncBit
if (bufBitPos == nextControlBit) {
@ -327,7 +332,7 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
#ifdef IRDEBUG_INFO
Serial.print("****************");
#endif
isRecive = false;
};
}//**************************************************************************************************//
@ -349,7 +354,7 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
}
#endif
if (!isAvailable && isData) {
if (!isAvailable && isData && !isWrongPack) {
if (i_dataBuffer == 8 * msgBytes) {// Ппервый байт
packSize = dataBuffer[0] & IR_MASK_MSG_INFO;
Serial.print(" ["); Serial.print(packSize); Serial.print("] ");

View File

@ -23,7 +23,7 @@
class IR_Encoder;
class IR_DecoderRaw : public IR_FOX {
class IR_DecoderRaw : virtual public IR_FOX {
friend IR_Encoder;
public:
const uint8_t isrPin; // Пин прерывания
@ -44,9 +44,9 @@ public:
//////////////////////////////////////////////////////////////////////////
protected:
PackInfo packInfo;
uint16_t id;
private:
ErrorsStruct errors;
uint16_t id;
bool isAvailable = false;
uint16_t packSize;
uint16_t crcValue;
@ -73,12 +73,13 @@ private:
////////////////////////////////////////////////////////////////////////
uint8_t dataBuffer[dataByteSizeMax] { 0 }; // Буффер данных
uint32_t prevRise, prevPrevRise, prevFall, prevPrevFall; // Время предыдущих фронтов/спадов
uint32_t risePeriod;
uint16_t errorCounter = 0; // Счётчик ошибок
int8_t preambFrontCounter = 0; // Счётчик __/``` ↑ преамбулы
int16_t bufBitPos = 0; // Позиция для записи бита в буффер
private:
void listenEnd(); // @brief Слушатель для работы isReciving()
void listenStart(); // @brief Слушатель для работы isReciving()
/// @brief Проверка CRC. Проверяет len байт со значением crc, пришедшим в пакете
/// @param len Длина в байтах проверяемых данных