mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
ErrorFix
This commit is contained in:
parent
1ee3386c31
commit
d065c7a037
@ -62,8 +62,7 @@ void IR_Decoder::tick() {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (currentFront.time - prevRise > IR_timeout) { // первый
|
if (currentFront.time - prevRise > IR_timeout) { // первый
|
||||||
|
errors.reset();
|
||||||
errorCounter = 0;
|
|
||||||
isRecive = true;
|
isRecive = true;
|
||||||
isPreamb = true;
|
isPreamb = true;
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ void IR_Decoder::tick() {
|
|||||||
|
|
||||||
if (risePeriod < riseTimeMin << 1) { // fix рваной единицы
|
if (risePeriod < riseTimeMin << 1) { // fix рваной единицы
|
||||||
preambFrontCounter += 2;
|
preambFrontCounter += 2;
|
||||||
errorCounter++;
|
errors.other++;
|
||||||
} else {
|
} else {
|
||||||
if (freeFrec) { riseSyncTime = (riseSyncTime + risePeriod / 2) / 2; } // tuner
|
if (freeFrec) { riseSyncTime = (riseSyncTime + risePeriod / 2) / 2; } // tuner
|
||||||
}
|
}
|
||||||
@ -104,7 +103,7 @@ void IR_Decoder::tick() {
|
|||||||
int8_t allCount = 0;
|
int8_t allCount = 0;
|
||||||
bool invertErr = false;
|
bool invertErr = false;
|
||||||
|
|
||||||
|
if (!isPreamb) {
|
||||||
if (risePeriod < IR_timeout && !isBufferOverflow && risePeriod > riseTimeMin && !isWrongPack) {
|
if (risePeriod < IR_timeout && !isBufferOverflow && risePeriod > riseTimeMin && !isWrongPack) {
|
||||||
// Мы в пределах таймаута и буффер не переполнен и fix дроблёных единиц
|
// Мы в пределах таймаута и буффер не переполнен и fix дроблёных единиц
|
||||||
|
|
||||||
@ -129,7 +128,7 @@ void IR_Decoder::tick() {
|
|||||||
|
|
||||||
if (highCount == 0 && highTime > riseTime / 3) { // fix короткой единицы (?)после пропуска нулей(?)
|
if (highCount == 0 && highTime > riseTime / 3) { // fix короткой единицы (?)после пропуска нулей(?)
|
||||||
highCount++;
|
highCount++;
|
||||||
errorCounter++;
|
errors.other++;
|
||||||
#ifdef IRDEBUG
|
#ifdef IRDEBUG
|
||||||
errPulse(errOut, 2);
|
errPulse(errOut, 2);
|
||||||
#endif
|
#endif
|
||||||
@ -138,11 +137,13 @@ void IR_Decoder::tick() {
|
|||||||
if (lowCount + highCount > allCount) { // fix ошибочных сдвигов
|
if (lowCount + highCount > allCount) { // fix ошибочных сдвигов
|
||||||
if (lowCount > highCount) { // Лишние нули
|
if (lowCount > highCount) { // Лишние нули
|
||||||
lowCount = allCount - highCount;
|
lowCount = allCount - highCount;
|
||||||
|
errors.lowSignal += lowCount;
|
||||||
#ifdef IRDEBUG
|
#ifdef IRDEBUG
|
||||||
errPulse(errOut, 3);
|
errPulse(errOut, 3);
|
||||||
#endif
|
#endif
|
||||||
} else if (lowCount < highCount) { // Лишние единицы
|
} else if (lowCount < highCount) { // Лишние единицы
|
||||||
highCount = allCount - lowCount;
|
highCount = allCount - lowCount;
|
||||||
|
errors.highSignal += highCount;
|
||||||
#ifdef IRDEBUG
|
#ifdef IRDEBUG
|
||||||
errPulse(errOut, 4);
|
errPulse(errOut, 4);
|
||||||
#endif
|
#endif
|
||||||
@ -151,12 +152,21 @@ void IR_Decoder::tick() {
|
|||||||
// TODO: Отловить проверить
|
// TODO: Отловить проверить
|
||||||
} else if (lowCount == highCount) {
|
} else if (lowCount == highCount) {
|
||||||
invertErr = true;
|
invertErr = true;
|
||||||
Serial.print("...");
|
// Serial.print("...");
|
||||||
|
errors.other += allCount;
|
||||||
}
|
}
|
||||||
errorCounter += allCount;
|
// errorCounter += allCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// errorCounter += allCount;
|
||||||
|
// errors.other+=allCount;
|
||||||
|
if (lowCount < highCount) {
|
||||||
|
errors.highSignal += highCount;
|
||||||
|
} else {
|
||||||
|
errors.lowSignal += lowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorCounter += allCount;
|
|
||||||
#ifdef IRDEBUG
|
#ifdef IRDEBUG
|
||||||
errPulse(errOut, 1);
|
errPulse(errOut, 1);
|
||||||
#endif
|
#endif
|
||||||
@ -196,12 +206,12 @@ void IR_Decoder::tick() {
|
|||||||
digitalWrite(wrLow, 0);
|
digitalWrite(wrLow, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (risePeriod > riseTimeMax / 2 || highCount || lowCount) { // комплексный фикс рваной единицы
|
if (risePeriod > riseTimeMax / 2 || highCount || lowCount) { // комплексный фикс рваной единицы
|
||||||
prevPrevRise = prevRise;
|
prevPrevRise = prevRise;
|
||||||
prevRise = currentFront.time;
|
prevRise = currentFront.time;
|
||||||
} else {
|
} else {
|
||||||
errorCounter++;
|
errors.other++;
|
||||||
#ifdef IRDEBUG
|
#ifdef IRDEBUG
|
||||||
errPulse(errOut, 5);
|
errPulse(errOut, 5);
|
||||||
#endif
|
#endif
|
||||||
@ -290,7 +300,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
i_syncBit++;
|
i_syncBit++;
|
||||||
} else {
|
} else {
|
||||||
i_syncBit = 0;
|
i_syncBit = 0;
|
||||||
errorCounter++;
|
errors.other++;
|
||||||
// Serial.print("E");
|
// Serial.print("E");
|
||||||
err_syncBit++;
|
err_syncBit++;
|
||||||
// Serial.print("bit: "); Serial.println(bit);
|
// Serial.print("bit: "); Serial.println(bit);
|
||||||
@ -322,7 +332,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
const uint8_t dataSize = msgBytes + addrBytes;
|
const uint8_t dataSize = msgBytes + addrBytes;
|
||||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
isCrcCorrect = crcCheck(dataSize, crcValue);
|
||||||
if (isCrcCorrect && checkAddr(1, 2)) {
|
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;
|
gotAccept._isAvaliable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,7 +344,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
isCrcCorrect = (crcCheck(dataSize, crcValue));
|
isCrcCorrect = (crcCheck(dataSize, crcValue));
|
||||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
if (isCrcCorrect && checkAddr(3, 4)) {
|
||||||
gotRequest._isAvaliable = true;
|
gotRequest._isAvaliable = true;
|
||||||
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter, riseSyncTime);
|
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errors, riseSyncTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -348,10 +358,10 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
isCrcCorrect = crcCheck(dataSize, crcValue);
|
isCrcCorrect = crcCheck(dataSize, crcValue);
|
||||||
if (isCrcCorrect && checkAddr(3, 4)) {
|
if (isCrcCorrect && checkAddr(3, 4)) {
|
||||||
gotData._isAvaliable = true;
|
gotData._isAvaliable = true;
|
||||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
||||||
} else {
|
} else {
|
||||||
gotRawData._isAvaliable = true;
|
gotRawData._isAvaliable = true;
|
||||||
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errors, riseSyncTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
27
IR_Decoder.h
27
IR_Decoder.h
@ -51,6 +51,21 @@ public:
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct ErrorsStruct {
|
||||||
|
uint8_t lowSignal;
|
||||||
|
uint8_t highSignal;
|
||||||
|
uint8_t other;
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
lowSignal = 0;
|
||||||
|
highSignal = 0;
|
||||||
|
other = 0;
|
||||||
|
}
|
||||||
|
uint16_t all() { return lowSignal + highSignal + other; }
|
||||||
|
|
||||||
|
} errors;
|
||||||
|
|
||||||
|
public:
|
||||||
class InputData : protected IR_FOX {
|
class InputData : protected IR_FOX {
|
||||||
friend IR_Decoder;
|
friend IR_Decoder;
|
||||||
protected:
|
protected:
|
||||||
@ -62,13 +77,13 @@ public:
|
|||||||
uint8_t _dataRawSize = 0;
|
uint8_t _dataRawSize = 0;
|
||||||
uint16_t _crcPackVal = 0;
|
uint16_t _crcPackVal = 0;
|
||||||
uint16_t _crcCalcVal = 0;
|
uint16_t _crcCalcVal = 0;
|
||||||
uint16_t _errCount = 0;
|
ErrorsStruct _err;
|
||||||
uint16_t _bitPeriod = 0;
|
uint16_t _bitPeriod = 0;
|
||||||
|
|
||||||
void _set(uint8_t* ptr, uint8_t len, uint16_t crc, uint16_t err, uint16_t rTime) {
|
void _set(uint8_t* ptr, uint8_t len, uint16_t crc, ErrorsStruct err, uint16_t rTime) {
|
||||||
_crcCalcVal = crc;
|
_crcCalcVal = crc;
|
||||||
_dataRawSize = len;
|
_dataRawSize = len;
|
||||||
_errCount = err;
|
_err = err;
|
||||||
_bitPeriod = rTime;
|
_bitPeriod = rTime;
|
||||||
if (_data != nullptr) { delete _data; _data = nullptr; }
|
if (_data != nullptr) { delete _data; _data = nullptr; }
|
||||||
_data = new uint8_t[len];
|
_data = new uint8_t[len];
|
||||||
@ -86,7 +101,10 @@ public:
|
|||||||
uint8_t msgInfo() { return _msgType & IR_MASK_MSG_INFO; };
|
uint8_t msgInfo() { return _msgType & IR_MASK_MSG_INFO; };
|
||||||
uint8_t msgType() { return (_msgType >> 5) & IR_MASK_MSG_TYPE; };
|
uint8_t msgType() { return (_msgType >> 5) & IR_MASK_MSG_TYPE; };
|
||||||
uint8_t msgRAW() { return _msgType; };
|
uint8_t msgRAW() { return _msgType; };
|
||||||
uint16_t errorCount() { return _errCount; };
|
uint16_t errorCount() { return _err.all(); };
|
||||||
|
uint8_t errorLowSignal() { return _err.lowSignal; };
|
||||||
|
uint8_t errorHighSignal() { return _err.highSignal; };
|
||||||
|
uint8_t errorOther() { return _err.other; };
|
||||||
uint16_t crcIN() { return _crcPackVal; };
|
uint16_t crcIN() { return _crcPackVal; };
|
||||||
uint16_t crcCALC() { return _crcCalcVal; };
|
uint16_t crcCALC() { return _crcCalcVal; };
|
||||||
uint16_t tunerTime() { return _bitPeriod; };
|
uint16_t tunerTime() { return _bitPeriod; };
|
||||||
@ -174,6 +192,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const uint8_t isrPin; // Пин прерывания
|
const uint8_t isrPin; // Пин прерывания
|
||||||
|
|
||||||
IR_Encoder* encoder; // Указатель на парный передатчик
|
IR_Encoder* encoder; // Указатель на парный передатчик
|
||||||
|
@ -120,7 +120,6 @@ void IR_Encoder::setDecoder_isSending() {
|
|||||||
if (decodersCount) {
|
if (decodersCount) {
|
||||||
for (uint8_t i = 0; i < decodersCount; i++) {
|
for (uint8_t i = 0; i < decodersCount; i++) {
|
||||||
blindDecoders[i]->isPairSending ^= id;
|
blindDecoders[i]->isPairSending ^= id;
|
||||||
digitalToggle(9); digitalToggle(9);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user