RDS code cleanup

This commit is contained in:
Sjef Verhoeven PE5PVB
2023-10-17 22:36:05 +02:00
parent 7166fd3ce2
commit 4fe5a936eb
3 changed files with 67 additions and 75 deletions
+65 -73
View File
@@ -526,10 +526,10 @@ void TEF6686::readRDS(byte showrdserrors)
if (!rdsCerrorThreshold) { if (!rdsCerrorThreshold) {
//AF decoder //AF decoder
if (rdsblock == 0 && rds.rdsC != rdsCold) { // Only when in GROUP 0A if (rdsblock == 0 && rds.rdsC != rdsCold) { // Only when in GROUP 0A
if ((rds.rdsC >> 8) > 224 && (rds.rdsC >> 8) < 250 && ((rds.rdsC & 0xFF) * 10 + 8750) == currentfreq) { // Check for AF method B if ((rds.rdsC >> 8) > 224 && (rds.rdsC >> 8) < 250 && ((rds.rdsC & 0xFF) * 10 + 8750) == currentfreq) {
afmethodB = true; afmethodB = true; // Check for AF method B
afmethodBprobe = true; afmethodBprobe = true;
af_updatecounter++; af_updatecounter++;
af_counterb = (rds.rdsC >> 8) - 224; af_counterb = (rds.rdsC >> 8) - 224;
@@ -554,26 +554,22 @@ void TEF6686::readRDS(byte showrdserrors)
if ((rds.rdsC & 0xFF) > 0 && (rds.rdsC & 0xFF) < 205) buffer1 = (rds.rdsC & 0xFF) * 10 + 8750; else buffer1 = 0; if ((rds.rdsC & 0xFF) > 0 && (rds.rdsC & 0xFF) < 205) buffer1 = (rds.rdsC & 0xFF) * 10 + 8750; else buffer1 = 0;
if (buffer0 != 0 || buffer1 != 0) rds.hasAF = true; if (buffer0 != 0 || buffer1 != 0) rds.hasAF = true;
if (afmethodBprobe && af_counterbcheck > af_counterb) afmethodBprobe = false; // If more than counter received disable probe flag if (afmethodBprobe && af_counterbcheck > af_counterb) afmethodBprobe = false; // If more than counter received disable probe flag
if (afmethodBprobe) { // Check for Reg. flags if (afmethodBprobe) { // Check for Reg. flags
if (buffer1 == currentfreq && buffer0 > buffer1) { if (buffer1 == currentfreq && buffer0 > buffer1) {
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer0 && !af[x].regional) { if (af[x].frequency == buffer0 && !af[x].regional) {
if (!af[x].regional) { af[x].regional = true;
af[x].regional = true; af_updatecounter++;
af_updatecounter++;
}
break; break;
} }
} }
} else if (buffer1 == currentfreq && buffer0 < buffer1) { } else if (buffer1 == currentfreq && buffer0 < buffer1) {
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer0 && !af[x].mixed) { if (af[x].frequency == buffer0 && !af[x].same) {
if (!af[x].mixed) { af[x].same = true;
af[x].mixed = true; af_updatecounter++;
af_updatecounter++;
}
break; break;
} }
} }
@@ -582,32 +578,28 @@ void TEF6686::readRDS(byte showrdserrors)
if (buffer0 == currentfreq && buffer0 > buffer1) { if (buffer0 == currentfreq && buffer0 > buffer1) {
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer1 && !af[x].regional) { if (af[x].frequency == buffer1 && !af[x].regional) {
if (!af[x].regional) { af[x].regional = true;
af[x].regional = true; af_updatecounter++;
af_updatecounter++;
}
break; break;
} }
} }
} else if (buffer0 == currentfreq && buffer0 < buffer1) { } else if (buffer0 == currentfreq && buffer0 < buffer1) {
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer1 && !af[x].mixed) { if (af[x].frequency == buffer1 && !af[x].same) {
if (!af[x].mixed) { af[x].same = true;
af[x].mixed = true; af_updatecounter++;
af_updatecounter++;
}
break; break;
} }
} }
} }
} }
if (buffer0 != currentfreq && buffer1 != currentfreq && afmethodB && afmethodBprobe) { // Remove faulty Reg. flags if (buffer0 != currentfreq && buffer1 != currentfreq && afmethodB && afmethodBprobe) {
afmethodBprobe = false; afmethodBprobe = false; // Remove faulty Reg. flags
for (int x = 0; x < af_counter; x++) { for (int x = 0; x < af_counter; x++) {
if (af[x].frequency == buffer0 || af[x].frequency == buffer1) { if (af[x].frequency == buffer0 || af[x].frequency == buffer1) {
if (af[x].mixed) { if (af[x].same) {
af[x].mixed = false; af[x].same = false;
af_updatecounter++; af_updatecounter++;
} }
if (af[x].regional) { if (af[x].regional) {
@@ -620,21 +612,21 @@ void TEF6686::readRDS(byte showrdserrors)
} }
bool isValuePresent = false; bool isValuePresent = false;
for (int i = 0; i < 50; i++) { // Check if already in list for (int i = 0; i < 50; i++) { // Check if already in list
if (rds.sortaf && ((buffer0 == currentfreq) || buffer0 == 0 || af[i].frequency == buffer0)) { if (rds.sortaf && ((buffer0 == currentfreq) || buffer0 == 0 || af[i].frequency == buffer0)) {
isValuePresent = true; isValuePresent = true;
break; break;
} }
} }
if (!isValuePresent) { // Add frequency to list if (!isValuePresent) { // Add frequency to list
af[af_counter].frequency = buffer0; af[af_counter].frequency = buffer0;
if (af_counter < 50) af_counter++; if (af_counter < 50) af_counter++;
af_updatecounter++; af_updatecounter++;
} }
isValuePresent = false; isValuePresent = false;
for (int i = 0; i < 50; i++) { // Check if already in list for (int i = 0; i < 50; i++) { // Check if already in list
if (rds.sortaf && ((buffer1 == currentfreq) || buffer1 == 0 || af[i].frequency == buffer1)) { if (rds.sortaf && ((buffer1 == currentfreq) || buffer1 == 0 || af[i].frequency == buffer1)) {
isValuePresent = true; isValuePresent = true;
break; break;
@@ -642,12 +634,12 @@ void TEF6686::readRDS(byte showrdserrors)
} }
if (!isValuePresent) { if (!isValuePresent) {
af[af_counter].frequency = buffer1; // Add frequency to list af[af_counter].frequency = buffer1; // Add frequency to list
if (af_counter < 50) af_counter++; if (af_counter < 50) af_counter++;
af_updatecounter++; af_updatecounter++;
} }
if (rds.sortaf) { // Sort AF list (low to high) if (rds.sortaf) { // Sort AF list (low to high)
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50 - i; j++) { for (int j = 0; j < 50 - i; j++) {
if (af[j].frequency == 0) continue; if (af[j].frequency == 0) continue;
@@ -657,17 +649,17 @@ void TEF6686::readRDS(byte showrdserrors)
bool temp3 = af[j].afvalid; bool temp3 = af[j].afvalid;
bool temp4 = af[j].checked; bool temp4 = af[j].checked;
bool temp5 = af[j].regional; bool temp5 = af[j].regional;
bool temp6 = af[j].mixed; bool temp6 = af[j].same;
af[j].frequency = af[j + 1].frequency; af[j].frequency = af[j + 1].frequency;
af[j].afvalid = af[j + 1].afvalid; af[j].afvalid = af[j + 1].afvalid;
af[j].checked = af[j + 1].checked; af[j].checked = af[j + 1].checked;
af[j].regional = af[j + 1].regional; af[j].regional = af[j + 1].regional;
af[j].mixed = af[j + 1].mixed; af[j].same = af[j + 1].same;
af[j + 1].frequency = temp; af[j + 1].frequency = temp;
af[j + 1].afvalid = temp3; af[j + 1].afvalid = temp3;
af[j + 1].checked = temp4; af[j + 1].checked = temp4;
af[j + 1].regional = temp5; af[j + 1].regional = temp5;
af[j + 1].mixed = temp6; af[j + 1].same = temp6;
} }
} }
} }
@@ -807,14 +799,14 @@ void TEF6686::readRDS(byte showrdserrors)
rds.aid_counter++; rds.aid_counter++;
} }
if (rds.rdsD == 0xCD46) { // Check for TMC application if (rds.rdsD == 0xCD46) { // Check for TMC application
rds.hasTMC = true; // TMC flag rds.hasTMC = true; // TMC flag
} }
// RT+ init // RT+ init
if (rds.rdsD == 0x4BD7) { // Check for RT+ application if (rds.rdsD == 0x4BD7) { // Check for RT+ application
rds.hasRDSplus = true; // Set flag rds.hasRDSplus = true; // Set flag
rtplusblock = ((rds.rdsB & 0x1F) >> 1) * 2; // Get RT+ Block rtplusblock = ((rds.rdsB & 0x1F) >> 1) * 2; // Get RT+ Block
} }
} }
} break; } break;
@@ -853,15 +845,15 @@ void TEF6686::readRDS(byte showrdserrors)
case RDS_GROUP_10A: { case RDS_GROUP_10A: {
if (!rdsCerrorThreshold && !rdsDerrorThreshold) { if (!rdsCerrorThreshold && !rdsDerrorThreshold) {
// PTYN // PTYN
offset = bitRead(rds.rdsB, 0); // Get char offset offset = bitRead(rds.rdsB, 0); // Get char offset
ptyn_buffer[(offset * 4) + 0] = rds.rdsC >> 8; // Get position 1 and 5 ptyn_buffer[(offset * 4) + 0] = rds.rdsC >> 8; // Get position 1 and 5
ptyn_buffer[(offset * 4) + 1] = rds.rdsC & 0xFF; // Get position 2 and 6 ptyn_buffer[(offset * 4) + 1] = rds.rdsC & 0xFF; // Get position 2 and 6
ptyn_buffer[(offset * 4) + 2] = rds.rdsD >> 8; // Get position 3 and 7 ptyn_buffer[(offset * 4) + 2] = rds.rdsD >> 8; // Get position 3 and 7
ptyn_buffer[(offset * 4) + 3] = rds.rdsD & 0xFF; // Get position 4 and 8 ptyn_buffer[(offset * 4) + 3] = rds.rdsD & 0xFF; // Get position 4 and 8
RDScharConverter(ptyn_buffer, PTYNtext, sizeof(PTYNtext) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(ptyn_buffer, PTYNtext, sizeof(PTYNtext) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII
String utf8String = convertToUTF8(PTYNtext); // Convert RDS characterset to ASCII String utf8String = convertToUTF8(PTYNtext); // Convert RDS characterset to ASCII
rds.PTYN = extractUTF8Substring(utf8String, 0, 8, false); // Make sure text is not longer than 8 chars rds.PTYN = extractUTF8Substring(utf8String, 0, 8, false); // Make sure text is not longer than 8 chars
} }
} break; } break;
@@ -874,8 +866,8 @@ void TEF6686::readRDS(byte showrdserrors)
case RDS_GROUP_12A: case RDS_GROUP_12A:
case RDS_GROUP_13A: { case RDS_GROUP_13A: {
// RT+ decoding // RT+ decoding
if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && rtplusblock == rdsblock && rds.hasRDSplus) { // Are we in the right RT+ block and is all ok to go? if ((!rdsBerrorThreshold && !rdsCerrorThreshold && !rdsDerrorThreshold) && rtplusblock == rdsblock && rds.hasRDSplus) {
rds.rdsplusTag1 = ((rds.rdsB & 0x07) << 3) + (rds.rdsC >> 13); rds.rdsplusTag1 = ((rds.rdsB & 0x07) << 3) + (rds.rdsC >> 13); // Are we in the right RT+ block and is all ok to go?
rds.rdsplusTag2 = ((rds.rdsC & 0x01) << 5) + (rds.rdsD >> 11); rds.rdsplusTag2 = ((rds.rdsC & 0x01) << 5) + (rds.rdsD >> 11);
uint16_t start_marker_1 = (rds.rdsC >> 7) & 0x3F; uint16_t start_marker_1 = (rds.rdsC >> 7) & 0x3F;
uint16_t length_marker_1 = (rds.rdsC >> 1) & 0x3F; uint16_t length_marker_1 = (rds.rdsC >> 1) & 0x3F;
@@ -915,28 +907,28 @@ void TEF6686::readRDS(byte showrdserrors)
RDSplus2[length_marker_2 + 1] = 0; RDSplus2[length_marker_2 + 1] = 0;
} }
wchar_t RTtext1[45] = L""; // Create 16 bit char buffer for Extended ASCII wchar_t RTtext1[45] = L""; // Create 16 bit char buffer for Extended ASCII
RDScharConverter(RDSplus1, RTtext1, sizeof(RTtext1) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(RDSplus1, RTtext1, sizeof(RTtext1) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII
rds.RTContent1 = convertToUTF8(RTtext1); // Convert RDS characterset to ASCII rds.RTContent1 = convertToUTF8(RTtext1); // Convert RDS characterset to ASCII
rds.RTContent1 = extractUTF8Substring(rds.RTContent1, 0, 44, false); // Make sure RT does not exceed 32 characters rds.RTContent1 = extractUTF8Substring(rds.RTContent1, 0, 44, false); // Make sure RT does not exceed 32 characters
wchar_t RTtext2[45] = L""; // Create 16 bit char buffer for Extended ASCII wchar_t RTtext2[45] = L""; // Create 16 bit char buffer for Extended ASCII
RDScharConverter(RDSplus2, RTtext2, sizeof(RTtext2) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(RDSplus2, RTtext2, sizeof(RTtext2) / sizeof(wchar_t), false); // Convert 8 bit ASCII to 16 bit ASCII
rds.RTContent2 = convertToUTF8(RTtext2); // Convert RDS characterset to ASCII rds.RTContent2 = convertToUTF8(RTtext2); // Convert RDS characterset to ASCII
rds.RTContent2 = extractUTF8Substring(rds.RTContent2, 0, 44, false); // Make sure RT does not exceed 32 characters rds.RTContent2 = extractUTF8Substring(rds.RTContent2, 0, 44, false); // Make sure RT does not exceed 32 characters
} }
if (!rdsBerrorThreshold && rdsblock == 16 && (bitRead(rds.rdsB, 15))) rds.hasTMC = true; // TMC flag if (!rdsBerrorThreshold && rdsblock == 16 && (bitRead(rds.rdsB, 15))) rds.hasTMC = true; // TMC flag
} }
break; break;
case RDS_GROUP_14A: { case RDS_GROUP_14A: {
// EON // EON
if (!rdsDerrorThreshold) { if (!rdsDerrorThreshold) {
rds.hasEON = true; // Group is there, so we have EON rds.hasEON = true; // Group is there, so we have EON
bool isValuePresent = false; bool isValuePresent = false;
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
if (eon[i].pi == rds.rdsD) { // Check if EON is already in array if (eon[i].pi == rds.rdsD) { // Check if EON is already in array
isValuePresent = true; isValuePresent = true;
break; break;
} }
@@ -949,32 +941,32 @@ void TEF6686::readRDS(byte showrdserrors)
eon[eon_counter].picode[3] = rds.rdsD & 0xF; eon[eon_counter].picode[3] = rds.rdsD & 0xF;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (eon[eon_counter].picode[i] < 10) { if (eon[eon_counter].picode[i] < 10) {
eon[eon_counter].picode[i] += '0'; // Add ASCII offset for decimal digits eon[eon_counter].picode[i] += '0'; // Add ASCII offset for decimal digits
} else { } else {
eon[eon_counter].picode[i] += 'A' - 10; // Add ASCII offset for hexadecimal letters A-F eon[eon_counter].picode[i] += 'A' - 10; // Add ASCII offset for hexadecimal letters A-F
} }
} }
eon[eon_counter].pi = rds.rdsD; // Store PI on next array eon[eon_counter].pi = rds.rdsD; // Store PI on next array
if (eon_counter < 20) eon_counter++; if (eon_counter < 20) eon_counter++;
} }
offset = rds.rdsB & 0x0F; // Read offset offset = rds.rdsB & 0x0F; // Read offset
if (offset < 9) { if (offset < 9) {
byte position; byte position;
for (position = 0; position < 20; position++) { for (position = 0; position < 20; position++) {
if (eon[position].pi == rds.rdsD) { // Find position in array if (eon[position].pi == rds.rdsD) { // Find position in array
break; break;
} }
} }
if (offset < 4 && eon[position].pi == rds.rdsD) { if (offset < 4 && eon[position].pi == rds.rdsD) {
for (int j = 0; j < 9; j++) EONPStext[position][j] = '\0'; // Clear buffer for (int j = 0; j < 9; j++) EONPStext[position][j] = '\0'; // Clear buffer
eon_buffer[position][(offset * 2) + 0] = rds.rdsC >> 8; // First character of segment eon_buffer[position][(offset * 2) + 0] = rds.rdsC >> 8; // First character of segment
eon_buffer[position][(offset * 2) + 1] = rds.rdsC & 0xFF; // Second character of segment eon_buffer[position][(offset * 2) + 1] = rds.rdsC & 0xFF; // Second character of segment
eon_buffer[position][(offset * 2) + 2] = '\0'; // Endmarker of segment eon_buffer[position][(offset * 2) + 2] = '\0'; // Endmarker of segment
} }
if (offset > 3 && eon[position].pi == rds.rdsD) { // Last chars are received if (offset > 3 && eon[position].pi == rds.rdsD) { // Last chars are received
@@ -985,9 +977,9 @@ void TEF6686::readRDS(byte showrdserrors)
} }
if (offset > 4 && eon[position].pi == rds.rdsD) { if (offset > 4 && eon[position].pi == rds.rdsD) {
if (((rds.rdsC >> 8) * 10 + 8750) == currentfreq) { // Check if mapped frequency belongs to current frequency if (((rds.rdsC >> 8) * 10 + 8750) == currentfreq) { // Check if mapped frequency belongs to current frequency
if (eon[position].mappedfreq == 0) { if (eon[position].mappedfreq == 0) {
eon[position].mappedfreq = ((rds.rdsC & 0xFF) * 10 + 8750); // Add mapped frequency to array eon[position].mappedfreq = ((rds.rdsC & 0xFF) * 10 + 8750); // Add mapped frequency to array
} else { } else {
if (eon[position].mappedfreq2 == 0 && eon[position].mappedfreq != (rds.rdsC & 0xFF) * 10 + 8750) { if (eon[position].mappedfreq2 == 0 && eon[position].mappedfreq != (rds.rdsC & 0xFF) * 10 + 8750) {
eon[position].mappedfreq2 = ((rds.rdsC & 0xFF) * 10 + 8750); eon[position].mappedfreq2 = ((rds.rdsC & 0xFF) * 10 + 8750);
@@ -1042,7 +1034,7 @@ void TEF6686::clearRDS (bool fullsearchrds)
af[i].afvalid = true; af[i].afvalid = true;
af[i].checked = false; af[i].checked = false;
af[i].regional = false; af[i].regional = false;
af[i].mixed = false; af[i].same = false;
} }
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++) {
+1 -1
View File
@@ -583,7 +583,7 @@ typedef struct _af_ {
bool afvalid; bool afvalid;
bool checked; bool checked;
bool regional; bool regional;
bool mixed; bool same;
} af_; } af_;
typedef struct _eon_ { typedef struct _eon_ {
+1 -1
View File
@@ -830,7 +830,7 @@ void ShowAFEON() {
for (byte i = 0; i < radio.af_counter; i++) { for (byte i = 0; i < radio.af_counter; i++) {
byte x = i - (afpagenr == 2 ? 30 : 0); byte x = i - (afpagenr == 2 ? 30 : 0);
if (!screenmute) { if (!screenmute) {
tftPrint(-1, ((radio.afmethodB && !radio.af[i].regional && radio.af[i].mixed) ? "S " : (radio.afmethodB && radio.af[i].regional && radio.af[i].mixed) ? "M " : (radio.afmethodB && radio.af[i].regional && !radio.af[i].mixed) ? "R " : ""), 10 + (x > 9 ? 54 : 0) + (x > 19 ? 54 : 0), 48 + (15 * x) - (x > 9 ? 150 : 0) - (x > 19 ? 150 : 0), ActiveColor, ActiveColorSmooth, 16); tftPrint(-1, (radio.afmethodB && !radio.af[i].regional && radio.af[i].same) ? "S " : (radio.afmethodB && radio.af[i].regional && radio.af[i].same) ? "M " : (radio.afmethodB && radio.af[i].regional && !radio.af[i].same) ? "R " : "", 10 + (x > 9 ? 54 : 0) + (x > 19 ? 54 : 0), 48 + (15 * x) - (x > 9 ? 150 : 0) - (x > 19 ? 150 : 0), ActiveColor, ActiveColorSmooth, 16);
if (radio.af[i].checked) { if (radio.af[i].checked) {
tftPrint(1, String(radio.af[i].frequency / 100) + "." + String((radio.af[i].frequency % 100) / 10), 55 + (x > 9 ? 54 : 0) + (x > 19 ? 54 : 0), 48 + (15 * x) - (x > 9 ? 150 : 0) - (x > 19 ? 150 : 0), InsignificantColor, InsignificantColorSmooth, 16); tftPrint(1, String(radio.af[i].frequency / 100) + "." + String((radio.af[i].frequency % 100) / 10), 55 + (x > 9 ? 54 : 0) + (x > 19 ? 54 : 0), 48 + (15 * x) - (x > 9 ? 150 : 0) - (x > 19 ? 150 : 0), InsignificantColor, InsignificantColorSmooth, 16);
} else if (!radio.af[i].afvalid) { } else if (!radio.af[i].afvalid) {