mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-27 20:59:37 +00:00
ErrorFix
This commit is contained in:
218
IR_Decoder.cpp
218
IR_Decoder.cpp
@ -19,7 +19,7 @@ IR_Decoder::~IR_Decoder() {
|
||||
|
||||
//////////////////////////////////// isr ///////////////////////////////////////////
|
||||
|
||||
void IR_Decoder::isr() {
|
||||
void IR_Decoder::isr() {
|
||||
if (isPairSending) return;
|
||||
|
||||
subBuffer[currentSubBufferIndex].next = nullptr;
|
||||
@ -62,8 +62,7 @@ void IR_Decoder::tick() {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (currentFront.time - prevRise > IR_timeout) { // первый
|
||||
|
||||
errorCounter = 0;
|
||||
errors.reset();
|
||||
isRecive = true;
|
||||
isPreamb = true;
|
||||
|
||||
@ -79,7 +78,7 @@ void IR_Decoder::tick() {
|
||||
|
||||
if (risePeriod < riseTimeMin << 1) { // fix рваной единицы
|
||||
preambFrontCounter += 2;
|
||||
errorCounter++;
|
||||
errors.other++;
|
||||
} else {
|
||||
if (freeFrec) { riseSyncTime = (riseSyncTime + risePeriod / 2) / 2; } // tuner
|
||||
}
|
||||
@ -104,107 +103,118 @@ void IR_Decoder::tick() {
|
||||
int8_t allCount = 0;
|
||||
bool invertErr = false;
|
||||
|
||||
if (!isPreamb) {
|
||||
if (risePeriod < IR_timeout && !isBufferOverflow && risePeriod > riseTimeMin && !isWrongPack) {
|
||||
// Мы в пределах таймаута и буффер не переполнен и fix дроблёных единиц
|
||||
|
||||
if (risePeriod < IR_timeout && !isBufferOverflow && risePeriod > riseTimeMin && !isWrongPack) {
|
||||
// Мы в пределах таймаута и буффер не переполнен и fix дроблёных единиц
|
||||
if (aroundRise(risePeriod)) { // тактирование есть, сигнал хороший - без ошибок(?)
|
||||
|
||||
if (aroundRise(risePeriod)) { // тактирование есть, сигнал хороший - без ошибок(?)
|
||||
|
||||
if (highTime > riseTimeMin >> 1) { // 1
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrHigh, 1);
|
||||
#endif
|
||||
writeToBuffer(HIGH);
|
||||
} else { // 0
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
writeToBuffer(LOW);
|
||||
}
|
||||
|
||||
} else { // пропущены такты! сигнал средний // ошибка пропуска
|
||||
highCount = ceil_div(highTime, riseTime); // предполагаемое колличество HIGH битов
|
||||
lowCount = ceil_div(lowTime, riseTime); // предполагаемое колличество LOW битов
|
||||
allCount = ceil_div(risePeriod, riseTime); // предполагаемое колличество всего битов
|
||||
|
||||
if (highCount == 0 && highTime > riseTime / 3) { // fix короткой единицы (?)после пропуска нулей(?)
|
||||
highCount++;
|
||||
errorCounter++;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (lowCount + highCount > allCount) { // fix ошибочных сдвигов
|
||||
if (lowCount > highCount) { // Лишние нули
|
||||
lowCount = allCount - highCount;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 3);
|
||||
#endif
|
||||
} else if (lowCount < highCount) { // Лишние единицы
|
||||
highCount = allCount - lowCount;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 4);
|
||||
#endif
|
||||
// неизвестный случай Инверсит след бит или соседние
|
||||
// Очень редко
|
||||
// TODO: Отловить проверить
|
||||
} else if (lowCount == highCount) {
|
||||
invertErr = true;
|
||||
Serial.print("...");
|
||||
}
|
||||
errorCounter += allCount;
|
||||
}
|
||||
|
||||
errorCounter += allCount;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 1);
|
||||
#endif
|
||||
|
||||
for (int8_t i = 0; i < lowCount && 8 - i; i++) { // отправка LOW битов, если есть
|
||||
if (i == lowCount - 1 && invertErr) {
|
||||
invertErr = false;
|
||||
writeToBuffer(!LOW);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
} else {
|
||||
writeToBuffer(LOW);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
for (int8_t i = 0; i < highCount && 8 - i; i++) { // отправка HIGH битов, если есть
|
||||
if (i == highCount - 1 && invertErr) {
|
||||
invertErr = false;
|
||||
writeToBuffer(!HIGH);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
} else {
|
||||
writeToBuffer(HIGH);
|
||||
#ifdef IRDEBUG
|
||||
if (highTime > riseTimeMin >> 1) { // 1
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrHigh, 1);
|
||||
#endif
|
||||
writeToBuffer(HIGH);
|
||||
} else { // 0
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
writeToBuffer(LOW);
|
||||
}
|
||||
|
||||
} else { // пропущены такты! сигнал средний // ошибка пропуска
|
||||
highCount = ceil_div(highTime, riseTime); // предполагаемое колличество HIGH битов
|
||||
lowCount = ceil_div(lowTime, riseTime); // предполагаемое колличество LOW битов
|
||||
allCount = ceil_div(risePeriod, riseTime); // предполагаемое колличество всего битов
|
||||
|
||||
if (highCount == 0 && highTime > riseTime / 3) { // fix короткой единицы (?)после пропуска нулей(?)
|
||||
highCount++;
|
||||
errors.other++;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (lowCount + highCount > allCount) { // fix ошибочных сдвигов
|
||||
if (lowCount > highCount) { // Лишние нули
|
||||
lowCount = allCount - highCount;
|
||||
errors.lowSignal += lowCount;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 3);
|
||||
#endif
|
||||
} else if (lowCount < highCount) { // Лишние единицы
|
||||
highCount = allCount - lowCount;
|
||||
errors.highSignal += highCount;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 4);
|
||||
#endif
|
||||
// неизвестный случай Инверсит след бит или соседние
|
||||
// Очень редко
|
||||
// TODO: Отловить проверить
|
||||
} else if (lowCount == highCount) {
|
||||
invertErr = true;
|
||||
// Serial.print("...");
|
||||
errors.other += allCount;
|
||||
}
|
||||
// errorCounter += allCount;
|
||||
|
||||
}
|
||||
|
||||
// errorCounter += allCount;
|
||||
// errors.other+=allCount;
|
||||
if (lowCount < highCount) {
|
||||
errors.highSignal += highCount;
|
||||
} else {
|
||||
errors.lowSignal += lowCount;
|
||||
}
|
||||
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 1);
|
||||
#endif
|
||||
|
||||
for (int8_t i = 0; i < lowCount && 8 - i; i++) { // отправка LOW битов, если есть
|
||||
if (i == lowCount - 1 && invertErr) {
|
||||
invertErr = false;
|
||||
writeToBuffer(!LOW);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
} else {
|
||||
writeToBuffer(LOW);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
for (int8_t i = 0; i < highCount && 8 - i; i++) { // отправка HIGH битов, если есть
|
||||
if (i == highCount - 1 && invertErr) {
|
||||
invertErr = false;
|
||||
writeToBuffer(!HIGH);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrLow, 1);
|
||||
#endif
|
||||
} else {
|
||||
writeToBuffer(HIGH);
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrHigh, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrHigh, 0);
|
||||
digitalWrite(wrLow, 0);
|
||||
#endif
|
||||
}
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(wrHigh, 0);
|
||||
digitalWrite(wrLow, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (risePeriod > riseTimeMax / 2 || highCount || lowCount) { // комплексный фикс рваной единицы
|
||||
prevPrevRise = prevRise;
|
||||
prevRise = currentFront.time;
|
||||
} else {
|
||||
errorCounter++;
|
||||
#ifdef IRDEBUG
|
||||
errors.other++;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 5);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
} else { // Если ```\__ ↓
|
||||
@ -213,9 +223,9 @@ void IR_Decoder::tick() {
|
||||
prevPrevFall = prevFall;
|
||||
prevFall = currentFront.time;
|
||||
} else {
|
||||
#ifdef IRDEBUG
|
||||
#ifdef IRDEBUG
|
||||
//errPulse(errOut, 5);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,9 +233,9 @@ void IR_Decoder::tick() {
|
||||
prevRise = currentFront.time + riseTime;
|
||||
}
|
||||
|
||||
#ifdef IRDEBUG
|
||||
#ifdef IRDEBUG
|
||||
digitalWrite(writeOp, isPreamb);
|
||||
#endif
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
firstUnHandledFront = firstUnHandledFront->next; //переместить флаг на следующий элемент для обработки (next or nullptr)
|
||||
}
|
||||
@ -290,7 +300,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
i_syncBit++;
|
||||
} else {
|
||||
i_syncBit = 0;
|
||||
errorCounter++;
|
||||
errors.other++;
|
||||
// Serial.print("E");
|
||||
err_syncBit++;
|
||||
// Serial.print("bit: "); Serial.println(bit);
|
||||
@ -307,9 +317,9 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
}//**************************************************************************************************//
|
||||
|
||||
// Serial.print(bit);
|
||||
#ifdef IRDEBUG
|
||||
#ifdef IRDEBUG
|
||||
bit ? infoPulse(writeOp, 2) : infoPulse(writeOp, 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -322,7 +332,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
const uint8_t dataSize = msgBytes + addrBytes;
|
||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
||||
if (isCrcCorrect && checkAddr(1, 2)) {
|
||||
gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errors, riseSyncTime);
|
||||
gotAccept._isAvaliable = true;
|
||||
}
|
||||
}
|
||||
@ -334,7 +344,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
isCrcCorrect = (crcCheck(dataSize, crcValue));
|
||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
||||
gotRequest._isAvaliable = true;
|
||||
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errors, riseSyncTime);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -348,10 +358,10 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
||||
gotData._isAvaliable = true;
|
||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
||||
} else {
|
||||
gotRawData._isAvaliable = true;
|
||||
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -363,7 +373,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
bool IR_Decoder::crcCheck(uint8_t len, crc_t &crc) {
|
||||
bool IR_Decoder::crcCheck(uint8_t len, crc_t& crc) {
|
||||
bool crcOK = false;
|
||||
|
||||
crc = 0;
|
||||
|
Reference in New Issue
Block a user