From 2f24be697db9c65ac01f3491c3c661cfe44d33bc Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Thu, 15 Jan 2026 21:51:18 +0100 Subject: [PATCH] segment tracking for rt --- include/TEF6686.h | 3 +- src/TEF6686.cpp | 98 +++++++++++++++++++++-------------------------- src/rds.cpp | 10 +---- 3 files changed, 46 insertions(+), 65 deletions(-) diff --git a/include/TEF6686.h b/include/TEF6686.h index 2bb44f3..d134b37 100644 --- a/include/TEF6686.h +++ b/include/TEF6686.h @@ -598,7 +598,6 @@ class TEF6686 { char eRT_buffer[129]; bool rt_process; char rt_buffer[65]; - char rt_buffer2[65]; char rt_buffer32[33]; char pslong_buffer[33]; char pslong_buffer2[33]; @@ -620,7 +619,7 @@ class TEF6686 { uint16_t currentfreq2; bool togglebit; bool runningbit; - bool initrt; + uint8_t segments_received[16]; bool initab; bool afinit; bool errorfreepi; diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 1f3cb2e..4a1a72b 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -1086,64 +1086,54 @@ void TEF6686::readRDS(byte showrdserrors) { initab = false; } - byte endmarkerRT64 = 64; - for (byte i = 0; i < endmarkerRT64; i++) { - if (rt_buffer[i] == 0x0d) { - endmarkerRT64 = i; - break; - } - } + if (rds.rtAB != rtABold) { + if (rds.rtbuffer) { + char rt_buffer_temp[129]; + strcpy(rt_buffer_temp, rt_buffer); - if (rds.rtAB != rtABold) { - initrt = false; - if (rds.rtbuffer) { - char rt_buffer_temp[129]; - strcpy(rt_buffer_temp, rt_buffer); - - for (int i = 0; i < 129; i++) { - if (rt_buffer_temp[i] == '\r') { - rt_buffer_temp[i] = '\0'; - break; + byte endmarkerRT64 = 64; + for (byte i = 0; i < endmarkerRT64; i++) { + if (rt_buffer_temp[i] == 0x0d) { endmarkerRT64 = i; break; } } + rt_buffer_temp[endmarkerRT64] = '\0'; + + wchar_t RTtext[65] = L""; + RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); + rds.stationText = trimTrailingSpaces(convertToUTF8(RTtext)); } - wchar_t RTtext[65] = L""; - RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); - rds.stationText = convertToUTF8(RTtext); - rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false)); - rds.stationText = trimTrailingSpaces(rds.stationText); + memset(rt_buffer, 0x20, 64); + rt_buffer[64] = '\0'; + memset(segments_received, 3, sizeof(segments_received)); + rtABold = rds.rtAB; } - for (byte i = 0; i < 64; i++) rt_buffer[i] = 0x20; - rt_buffer[64] = '\0'; - rtABold = rds.rtAB; - } + uint8_t segment_address = (rds.rdsB & 0xf); - uint8_t segment = (rds.rdsB & 0xf) * 4; - rt_buffer[segment + 0] = rds.rdsC >> 8; - rt_buffer[segment + 1] = rds.rdsC & 0xff; - rt_buffer[segment + 2] = rds.rdsD >> 8; - rt_buffer[segment + 3] = rds.rdsD & 0xff; + if(segments_received[segment_address] > (rds.rdsCerror + rds.rdsBerror)) { + segments_received[segment_address] = rds.rdsCerror + rds.rdsBerror; - if (initrt || !rds.rtbuffer) { - char rt_buffer_temp[129]; - strcpy(rt_buffer_temp, rt_buffer); + uint8_t offset = segment_address * 4; + rt_buffer[offset + 0] = rds.rdsC >> 8; + rt_buffer[offset + 1] = rds.rdsC & 0xff; + rt_buffer[offset + 2] = rds.rdsD >> 8; + rt_buffer[offset + 3] = rds.rdsD & 0xff; - for (int i = 0; i < 129; i++) { - if (rt_buffer_temp[i] == '\r') { - rt_buffer_temp[i] = '\0'; - break; - } + if (!rds.rtbuffer) { + char rt_buffer_temp[129]; + strcpy(rt_buffer_temp, rt_buffer); + + byte endmarkerRT64 = 64; + for (byte i = 0; i < endmarkerRT64; i++) { + if (rt_buffer_temp[i] == 0x0d) { endmarkerRT64 = i; break; } + } + rt_buffer_temp[endmarkerRT64] = '\0'; + + wchar_t RTtext[65] = L""; + RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); + rds.stationText = trimTrailingSpaces(convertToUTF8(RTtext)); + } } - - wchar_t RTtext[65] = L""; - RDScharConverter(rt_buffer_temp, RTtext, sizeof(RTtext) / sizeof(wchar_t), (underscore > 1 ? true : false)); - rds.stationText = convertToUTF8(RTtext); - rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarkerRT64, (underscore > 1 ? true : false)); - rds.stationText = trimTrailingSpaces(rds.stationText); - } - - for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i]; } } break; @@ -1271,10 +1261,7 @@ void TEF6686::readRDS(byte showrdserrors) { int32_t current_correction = rtc_time - rds_utc_time; rds.clock_correction = current_correction; - if (!NTPupdated) { - time_t corrected_time = rds_utc_time - (current_correction / 2); - set_time(corrected_time); - } + if (!NTPupdated) set_time(rds_utc_time - (current_correction / 2)); } else rds.hasCT = false; lastrdstime = rdstime; lasttimeoffset = timeoffset; @@ -1338,10 +1325,10 @@ void TEF6686::readRDS(byte showrdserrors) { } if (rds.rtAB == rtABold) { - for (int i = 0; i <= length_marker_1; i++)RDSplus1[i] = rt_buffer2[i + start_marker_1]; + for (int i = 0; i <= length_marker_1; i++)RDSplus1[i] = rt_buffer[i + start_marker_1]; RDSplus1[length_marker_1 + 1] = 0; - for (int i = 0; i <= length_marker_2; i++)RDSplus2[i] = rt_buffer2[i + start_marker_2]; + for (int i = 0; i <= length_marker_2; i++)RDSplus2[i] = rt_buffer[i + start_marker_2]; RDSplus2[length_marker_2 + 1] = 0; } @@ -1629,7 +1616,7 @@ void TEF6686::clearRDS(bool fullsearchrds) { rds.hasDynamicPTY = false; af_counter = af_updatecounter = eon_counter = 0; afreset = rds.rdsAerror = rds.rdsBerror = rds.rdsCerror = rds.rdsDerror = true; - initrt = initab = true; + initab = true; rds.rdsplusTag1 = 169; rds.rdsplusTag2 = 169; afinit = afmethodB = errorfreepi = false; @@ -1638,6 +1625,7 @@ void TEF6686::clearRDS(bool fullsearchrds) { rds.aid_counter = af_number = 0; afmethodBprobe = afmethodBtrigger = _hasEnhancedRT = false; rds.ps12error = rds.ps34error = rds.ps56error = rds.ps78error = true; + memset(segments_received, 3, sizeof(segments_received)); } void TEF6686::tone(uint16_t time, int16_t amplitude, uint16_t frequency) { diff --git a/src/rds.cpp b/src/rds.cpp index fcb3625..42f79e7 100644 --- a/src/rds.cpp +++ b/src/rds.cpp @@ -849,15 +849,13 @@ void ShowRDSStatistics() { processed_rdsblocksold[rb] = radio.processed_rdsblocks; } - String HexString; - HexString = String(((radio.rds.rdsA >> 12) & 0xF), HEX) + String(((radio.rds.rdsA >> 8) & 0xF), HEX) + String(((radio.rds.rdsA >> 4) & 0xF), HEX) + String((radio.rds.rdsA & 0xF), HEX); + String HexString = String(((radio.rds.rdsA >> 12) & 0xF), HEX) + String(((radio.rds.rdsA >> 8) & 0xF), HEX) + String(((radio.rds.rdsA >> 4) & 0xF), HEX) + String((radio.rds.rdsA & 0xF), HEX); HexString += " "; HexString += String(((radio.rds.rdsB >> 12) & 0xF), HEX) + String(((radio.rds.rdsB >> 8) & 0xF), HEX) + String(((radio.rds.rdsB >> 4) & 0xF), HEX) + String((radio.rds.rdsB & 0xF), HEX); HexString += " "; HexString += String(((radio.rds.rdsC >> 12) & 0xF), HEX) + String(((radio.rds.rdsC >> 8) & 0xF), HEX) + String(((radio.rds.rdsC >> 4) & 0xF), HEX) + String((radio.rds.rdsC & 0xF), HEX); HexString += " "; HexString += String(((radio.rds.rdsD >> 12) & 0xF), HEX) + String(((radio.rds.rdsD >> 8) & 0xF), HEX) + String(((radio.rds.rdsD >> 4) & 0xF), HEX) + String((radio.rds.rdsD & 0xF), HEX); - HexString.toUpperCase(); if (HexString != HexStringold) { @@ -866,9 +864,7 @@ void ShowRDSStatistics() { } } - // --- Always draw error indicators & BER meter if blocks processed --- if (radio.processed_rdsblocks > 0 && !dropout) { - // Draw A-D error circles (simple error flags) const uint8_t xErr[4] = {86, 124, 162, 200}; const bool errors[4] = {radio.rds.rdsAerror, radio.rds.rdsBerror, radio.rds.rdsCerror, radio.rds.rdsDerror}; @@ -879,12 +875,10 @@ void ShowRDSStatistics() { int errC = ((radio.rds.rdsErr >> 8) & 12) >> 2; int errD = (radio.rds.rdsErr & 3); - // Aggressive weights per error level const int weights[4] = {0, 2, 6, 12}; - // Total estimated error bits in this group int errorBits = weights[errA] + weights[errB] + weights[errC] + weights[errD]; - int totalBits = 4 * 26; // 104 data bits per RDS group + int totalBits = 4 * 26; float ber = (float)errorBits / (float)totalBits;