diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 316dfe1..fd7645b 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -560,39 +560,49 @@ void TEF6686::readRDS(byte showrdserrors) { stationID = 0xAF00 + uint8_t(highByte(stationID)); // CD00 -> AFCD } - // Determine prefix: 'W' or 'K' for USA, 'C' for Canada - if (rds.region == 1 || rds.region == 2) { - rds.stationID[0] = (stationID > 21671) ? 'W' : 'K'; - } else if (rds.region == 3) { - rds.stationID[0] = 'C'; - } - - if (stationID < 39247) { - stationID -= (stationID > 21671) ? 21672 : 4096; + // Check if the station has a fixed callsign for Canada + if (rds.region == 3 && isFixedCallsign(stationID, rds.stationID)) { + // If it matches a fixed callsign, skip the regular conversion } else { - stationID -= 4835; - } + // Determine prefix: 'W' or 'K' for USA, 'C' for Canada + if (rds.region == 1 || rds.region == 2) { + rds.stationID[0] = (stationID > 21671) ? 'W' : 'K'; + } else if (rds.region == 3) { + rds.stationID[0] = 'C'; // Canadian stations start with 'C' + } - rds.stationID[1] = char(stationID / 676 + 65); - rds.stationID[2] = char((stationID - 676 * int(stationID / 676)) / 26 + 65); - rds.stationID[3] = char(((stationID - 676 * int(stationID / 676)) % 26) + 65); - } + // Adjust stationID based on the region and PI code + if (stationID < 39247) { + stationID -= (stationID > 21671) ? 21672 : 4096; + } else { + stationID -= 4835; + } - // Validate callsign - bool faultyID = false; - for (byte i = 0; i < 4; i++) { - if (!(rds.stationID[i] >= 'A' && rds.stationID[i] <= 'Z')) { - faultyID = true; - break; + // Decode the last 3 letters of the callsign + rds.stationID[1] = char(stationID / 676 + 65); + rds.stationID[2] = char((stationID - 676 * int(stationID / 676)) / 26 + 65); + rds.stationID[3] = char(((stationID - 676 * int(stationID / 676)) % 26) + 65); } } - if (faultyID) { - strcpy(rds.stationID, "Unknown"); - } else { - rds.stationID[7] = '?'; + if (!(rds.region == 3 && isFixedCallsign(stationID, rds.stationID))) { + // Validate callsign + bool faultyID = false; + for (byte i = 0; i < 4; i++) { + if (!(rds.stationID[i] >= 'A' && rds.stationID[i] <= 'Z')) { + faultyID = true; + break; + } + } + + if (faultyID) { + strcpy(rds.stationID, "Unknown"); + } else { + rds.stationID[7] = '?'; + } + + rds.stationID[8] = '\0'; } - rds.stationID[8] = '\0'; } correctPIold = rds.correctPI; rds.stationIDtext = rds.stationID; @@ -2107,4 +2117,14 @@ String TEF6686::ucs2ToUtf8(const char* ucs2Input) { } } return utf8Output; +} + +bool TEF6686::isFixedCallsign(uint16_t stationID, char* stationIDStr) { + for (int i = 0; i < sizeof(fixedPI) / sizeof(fixedPI[0]); i++) { + if (stationID == fixedPI[i]) { + strcpy(stationIDStr, fixedCalls[i]); // Assign fixed callsign + return true; + } + } + return false; } \ No newline at end of file diff --git a/src/TEF6686.h b/src/TEF6686.h index 368dbf4..2588417 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -91,6 +91,10 @@ static const char* const PTY_USA[] { " " }; +// Fixed PI/callsign combinations for Canada +inline const uint16_t fixedPI[] = {0x4C10, 0x4C11, 0x4C12}; +inline const char* fixedCalls[] = {"CBLA", "CBFM", "CBOT"}; + static const uint16_t oda_app_ids[] { 0x0000, 0x0093, 0x0BCB, 0x0C24, 0x0CC1, 0x0D45, 0x0D8B, 0x0E2C, 0x0E31, 0x0F87, 0x125F, 0x1BDA, 0x1C5E, 0x1C68, 0x1CB1, 0x1D47, 0x1DC2, 0x1DC5, 0x1E8F, 0x4400, @@ -733,8 +737,8 @@ class TEF6686 { void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under); String convertToUTF8(const wchar_t* input); String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under); - String eRTconverter(const wchar_t* input); String ucs2ToUtf8(const char* ucs2Input); + bool isFixedCallsign(uint16_t stationID, char* stationIDStr); String PSLongtext; char ps_buffer[9]; char ps_buffer2[9]; @@ -789,4 +793,4 @@ class TEF6686 { time_t lastrdstime; int32_t lasttimeoffset; }; -#endif +#endif \ No newline at end of file