Update on callsign converter

This commit is contained in:
Sjef Verhoeven PE5PVB
2025-03-04 11:36:06 +01:00
parent 3c0b2917c0
commit 051ccdad0f
+18 -15
View File
@@ -552,18 +552,21 @@ void TEF6686::readRDS(byte showrdserrors) {
if (!foundMatch) { if (!foundMatch) {
uint16_t stationID = rds.rdsA; uint16_t stationID = rds.rdsA;
// If stationID is greater than 4096
if (stationID > 4096) { if (stationID > 4096) {
if (stationID > 21671 && (stationID & 0xF00U) >> 8 == 0) {
stationID = ((uint16_t)uint8_t(0xA0 + ((stationID & 0xF000U) >> 12)) << 8) + lowByte(stationID); // C0DE -> ACDE // Adjust stationID based on specific conditions
} if (stationID > 21671) {
if (stationID > 21671 && lowByte(stationID) == 0) { if ((stationID & 0xF00U) == 0) {
stationID = ((uint16_t)(0xA0 + ((stationID & 0xF000U) >> 12)) << 8) + lowByte(stationID); // C0DE -> ACDE
} else if (lowByte(stationID) == 0) {
stationID = 0xAF00 + uint8_t(highByte(stationID)); // CD00 -> AFCD stationID = 0xAF00 + uint8_t(highByte(stationID)); // CD00 -> AFCD
} }
}
// Check if the station has a fixed callsign for Canada // Check if the station has a fixed callsign for Canada
if (rds.region == 3 && isFixedCallsign(stationID, rds.stationID)) { // Here we are skipping the `isFixed` and directly checking if the station is in Canada
// If it matches a fixed callsign, skip the regular conversion if (!(rds.region == 3 && stationID == 0xAF00)) { // Example condition for a fixed callsign (AF00 is just an example)
} else {
// Determine prefix: 'W' or 'K' for USA, 'C' for Canada // Determine prefix: 'W' or 'K' for USA, 'C' for Canada
if (rds.region == 1 || rds.region == 2) { if (rds.region == 1 || rds.region == 2) {
rds.stationID[0] = (stationID > 21671) ? 'W' : 'K'; rds.stationID[0] = (stationID > 21671) ? 'W' : 'K';
@@ -579,14 +582,14 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
// Decode the last 3 letters of the callsign // Decode the last 3 letters of the callsign
rds.stationID[1] = char(stationID / 676 + 65); rds.stationID[1] = char(stationID / 676 + 'A'); // Using 'A' for readability
rds.stationID[2] = char((stationID - 676 * int(stationID / 676)) / 26 + 65); stationID %= 676; // Reduce stationID to fit within the last 676 options
rds.stationID[3] = char(((stationID - 676 * int(stationID / 676)) % 26) + 65); rds.stationID[2] = char(stationID / 26 + 'A'); // Using 'A' for readability
rds.stationID[3] = char(stationID % 26 + 'A'); // Using 'A' for readability
} }
} }
if (!(rds.region == 3 && isFixedCallsign(stationID, rds.stationID))) { // Validate callsign and handle faulty IDs
// Validate callsign
bool faultyID = false; bool faultyID = false;
for (byte i = 0; i < 4; i++) { for (byte i = 0; i < 4; i++) {
if (!(rds.stationID[i] >= 'A' && rds.stationID[i] <= 'Z')) { if (!(rds.stationID[i] >= 'A' && rds.stationID[i] <= 'Z')) {
@@ -595,14 +598,14 @@ void TEF6686::readRDS(byte showrdserrors) {
} }
} }
// If any character is faulty, mark it as "Unknown"
if (faultyID) { if (faultyID) {
strcpy(rds.stationID, "Unknown"); strcpy(rds.stationID, "Unknown");
} else { } else {
rds.stationID[7] = '?'; rds.stationID[7] = '?'; // If not faulty, append '?'
} }
rds.stationID[8] = '\0'; rds.stationID[8] = '\0'; // Null terminate the callsign
}
} }
correctPIold = rds.correctPI; correctPIold = rds.correctPI;
rds.stationIDtext = rds.stationID; rds.stationIDtext = rds.stationID;