Trim spaces at the end of RT when transmitter is not using 0x0d as end command

This commit is contained in:
Sjef Verhoeven PE5PVB
2024-05-21 13:06:43 +02:00
parent 19aa516890
commit 5e1c2af819
2 changed files with 10 additions and 0 deletions

View File

@@ -1167,6 +1167,7 @@ void TEF6686::readRDS(byte showrdserrors) {
RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII
rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII
rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters
rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end
} }
for (byte i = 0; i < 64; i++) { for (byte i = 0; i < 64; i++) {
@@ -1188,6 +1189,7 @@ void TEF6686::readRDS(byte showrdserrors) {
RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII
rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII
rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters rds.stationText = extractUTF8Substring(rds.stationText, 0, endmarker, true); // Make sure RT does not exceed 64 characters
rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end
} }
for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i]; for (int i = 0; i < 64; i++) rt_buffer2[i] = rt_buffer[i];
@@ -1224,6 +1226,7 @@ void TEF6686::readRDS(byte showrdserrors) {
RDScharConverter(rt_buffer32, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII RDScharConverter(rt_buffer32, RTtext, sizeof(RTtext) / sizeof(wchar_t), true); // Convert 8 bit ASCII to 16 bit ASCII
rds.stationText32 = convertToUTF8(RTtext); // Convert RDS characterset to ASCII rds.stationText32 = convertToUTF8(RTtext); // Convert RDS characterset to ASCII
rds.stationText32 = extractUTF8Substring(rds.stationText32, 0, endmarker, true); // Make sure RT does not exceed 32 characters rds.stationText32 = extractUTF8Substring(rds.stationText32, 0, endmarker, true); // Make sure RT does not exceed 32 characters
rds.stationText = trimTrailingSpaces(rds.stationText); // Trim empty spaces at the end
} }
} break; } break;
@@ -1925,4 +1928,10 @@ void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size,
} }
} }
output[size - 1] = L'\0'; output[size - 1] = L'\0';
}
String TEF6686::trimTrailingSpaces(String str) {
int end = str.length() - 1;
while (end >= 0 && isspace(str[end])) end--;
return str.substring(0, end + 1);
} }

View File

@@ -718,6 +718,7 @@ class TEF6686 {
void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under); void RDScharConverter(const char* input, wchar_t* output, size_t size, bool under);
String convertToUTF8(const wchar_t* input); String convertToUTF8(const wchar_t* input);
String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under); String extractUTF8Substring(const String& utf8String, size_t start, size_t length, bool under);
String trimTrailingSpaces(String str);
char ps_buffer[9]; char ps_buffer[9];
char ps_buffer2[9]; char ps_buffer2[9];
char ptyn_buffer[9]; char ptyn_buffer[9];