this code was written by clowns? No it was AI

This commit is contained in:
2026-01-05 15:39:59 +01:00
parent 314aa0a6b5
commit bfe5a41ea3
14 changed files with 153 additions and 441 deletions
+12 -44
View File
@@ -1,47 +1,30 @@
#include "RdsPiBuffer.hpp"
RdsPiBuffer::RdsPiBuffer()
{
RdsPiBuffer::RdsPiBuffer() {
this->clear();
}
RdsPiBuffer::State
RdsPiBuffer::add(uint16_t value,
bool error)
{
RdsPiBuffer::State RdsPiBuffer::add(uint16_t value, bool error) {
this->pos = (this->pos + 1) % BUFF_SIZE;
this->buff[this->pos] = value;
const uint8_t errorPos = this->pos / 8;
const uint8_t errorBitPos = this->pos % 8;
if (error)
{
this->errorBuff[errorPos] |= (1 << errorBitPos);
}
else
{
this->errorBuff[errorPos] &= ~(1 << errorBitPos);
}
if (error) this->errorBuff[errorPos] |= (1 << errorBitPos);
else this->errorBuff[errorPos] &= ~(1 << errorBitPos);
if (this->fill < BUFF_SIZE)
{
this->fill++;
}
if (this->fill < BUFF_SIZE) this->fill++;
return this->getState(value);
}
void
RdsPiBuffer::clear()
{
void RdsPiBuffer::clear(){
this->fill = 0;
this->pos = (uint8_t)-1;
}
RdsPiBuffer::State
RdsPiBuffer::getState(uint16_t value)
{
RdsPiBuffer::State RdsPiBuffer::getState(uint16_t value) {
uint8_t count = 0;
uint8_t correctCount = 0;
@@ -50,29 +33,14 @@ RdsPiBuffer::getState(uint16_t value)
if (this->buff[i] == value)
{
count++;
if ((this->errorBuff[i / 8] & (1 << (i % 8))) == 0)
{
correctCount++;
}
if ((this->errorBuff[i / 8] & (1 << (i % 8))) == 0) correctCount++;
}
}
if (correctCount >= 2)
{
return STATE_CORRECT;
}
else if (count >= 2 && correctCount)
{
return STATE_VERY_LIKELY;
}
else if (count >= 3)
{
return STATE_LIKELY;
}
else if (count == 2 || correctCount)
{
return STATE_UNLIKELY;
}
if (correctCount >= 2) return STATE_CORRECT;
else if (count >= 2 && correctCount) return STATE_VERY_LIKELY;
else if (count >= 3) return STATE_LIKELY;
else if (count == 2 || correctCount) return STATE_UNLIKELY;
return STATE_INVALID;
}