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) { // первый
|
||||
|
||||
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,7 +103,7 @@ void IR_Decoder::tick() {
|
||||
int8_t allCount = 0;
|
||||
bool invertErr = false;
|
||||
|
||||
|
||||
if (!isPreamb) {
|
||||
if (risePeriod < IR_timeout && !isBufferOverflow && risePeriod > riseTimeMin && !isWrongPack) {
|
||||
// Мы в пределах таймаута и буффер не переполнен и fix дроблёных единиц
|
||||
|
||||
@ -129,7 +128,7 @@ void IR_Decoder::tick() {
|
||||
|
||||
if (highCount == 0 && highTime > riseTime / 3) { // fix короткой единицы (?)после пропуска нулей(?)
|
||||
highCount++;
|
||||
errorCounter++;
|
||||
errors.other++;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 2);
|
||||
#endif
|
||||
@ -138,11 +137,13 @@ void IR_Decoder::tick() {
|
||||
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
|
||||
@ -151,12 +152,21 @@ void IR_Decoder::tick() {
|
||||
// TODO: Отловить проверить
|
||||
} else if (lowCount == highCount) {
|
||||
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
|
||||
errPulse(errOut, 1);
|
||||
#endif
|
||||
@ -196,12 +206,12 @@ void IR_Decoder::tick() {
|
||||
digitalWrite(wrLow, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
if (risePeriod > riseTimeMax / 2 || highCount || lowCount) { // комплексный фикс рваной единицы
|
||||
prevPrevRise = prevRise;
|
||||
prevRise = currentFront.time;
|
||||
} else {
|
||||
errorCounter++;
|
||||
errors.other++;
|
||||
#ifdef IRDEBUG
|
||||
errPulse(errOut, 5);
|
||||
#endif
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
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 {
|
||||
friend IR_Decoder;
|
||||
protected:
|
||||
@ -62,13 +77,13 @@ public:
|
||||
uint8_t _dataRawSize = 0;
|
||||
uint16_t _crcPackVal = 0;
|
||||
uint16_t _crcCalcVal = 0;
|
||||
uint16_t _errCount = 0;
|
||||
ErrorsStruct _err;
|
||||
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;
|
||||
_dataRawSize = len;
|
||||
_errCount = err;
|
||||
_err = err;
|
||||
_bitPeriod = rTime;
|
||||
if (_data != nullptr) { delete _data; _data = nullptr; }
|
||||
_data = new uint8_t[len];
|
||||
@ -86,7 +101,10 @@ public:
|
||||
uint8_t msgInfo() { return _msgType & IR_MASK_MSG_INFO; };
|
||||
uint8_t msgType() { return (_msgType >> 5) & IR_MASK_MSG_TYPE; };
|
||||
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 crcCALC() { return _crcCalcVal; };
|
||||
uint16_t tunerTime() { return _bitPeriod; };
|
||||
@ -174,6 +192,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
const uint8_t isrPin; // Пин прерывания
|
||||
|
||||
IR_Encoder* encoder; // Указатель на парный передатчик
|
||||
|
@ -120,7 +120,6 @@ void IR_Encoder::setDecoder_isSending() {
|
||||
if (decodersCount) {
|
||||
for (uint8_t i = 0; i < decodersCount; i++) {
|
||||
blindDecoders[i]->isPairSending ^= id;
|
||||
digitalToggle(9); digitalToggle(9);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user