add rds program type name decoding

This commit is contained in:
AlexandreRouma
2024-01-29 21:00:23 +01:00
parent 05ab17add3
commit 120745de19
2 changed files with 65 additions and 1 deletions

View File

@ -156,7 +156,7 @@ namespace rds {
// Acquire lock
std::lock_guard<std::mutex> lck(blockBMtx);
// If it didn't decode properly return
// If it didn't decode properly return (TODO: Make sure this is not needed)
if (!blockAvail[BLOCK_TYPE_B]) { return; }
// Decode group type and version
@ -240,6 +240,48 @@ namespace rds {
group2LastUpdate = std::chrono::high_resolution_clock::now();
}
void Decoder::decodeGroup10() {
// Acquire lock
std::lock_guard<std::mutex> lck(group10Mtx);
// Check if the text needs to be cleared
bool ab = (blocks[BLOCK_TYPE_B] >> 14) & 1;
if (ab != ptnAB) {
programTypeName = " ";
}
ptnAB = ab;
// Decode segment address
bool addr = (blocks[BLOCK_TYPE_B] >> 10) & 1;
// Save text depending on address
if (addr) {
if (blockAvail[BLOCK_TYPE_C]) {
programTypeName[4] = (blocks[BLOCK_TYPE_C] >> 18) & 0xFF;
programTypeName[5] = (blocks[BLOCK_TYPE_C] >> 10) & 0xFF;
}
if (blockAvail[BLOCK_TYPE_D]) {
programTypeName[6] = (blocks[BLOCK_TYPE_D] >> 18) & 0xFF;
programTypeName[7] = (blocks[BLOCK_TYPE_D] >> 10) & 0xFF;
}
}
else {
if (blockAvail[BLOCK_TYPE_C]) {
programTypeName[0] = (blocks[BLOCK_TYPE_C] >> 18) & 0xFF;
programTypeName[1] = (blocks[BLOCK_TYPE_C] >> 10) & 0xFF;
}
if (blockAvail[BLOCK_TYPE_D]) {
programTypeName[2] = (blocks[BLOCK_TYPE_D] >> 18) & 0xFF;
programTypeName[3] = (blocks[BLOCK_TYPE_D] >> 10) & 0xFF;
}
}
flog::debug("PTN: '{}'", programTypeName);
// Update timeout
group10LastUpdate = std::chrono::high_resolution_clock::now();
}
void Decoder::decodeGroup() {
// Make sure blocks B is available
if (!blockAvail[BLOCK_TYPE_B]) { return; }
@ -247,6 +289,8 @@ namespace rds {
// Decode block B
decodeBlockB();
//flog::debug("RDS Group {}{}", groupType, (groupVer == GROUP_VER_A) ? 'A':'B');
// Decode depending on group type
switch (groupType) {
case 0:
@ -255,6 +299,9 @@ namespace rds {
case 2:
decodeGroup2();
break;
case 10:
decodeGroup10();
break;
default:
break;
}
@ -298,4 +345,9 @@ namespace rds {
auto now = std::chrono::high_resolution_clock::now();
return (std::chrono::duration_cast<std::chrono::milliseconds>(now - group2LastUpdate)).count() < RDS_GROUP_2_TIMEOUT_MS;
}
bool Decoder::group10Valid() {
auto now = std::chrono::high_resolution_clock::now();
return (std::chrono::duration_cast<std::chrono::milliseconds>(now - group10LastUpdate)).count() < RDS_GROUP_10_TIMEOUT_MS;
}
}