Skip to content

Commit 120745d

Browse files
add rds program type name decoding
1 parent 05ab17a commit 120745d

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

decoder_modules/radio/src/rds.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace rds {
156156
// Acquire lock
157157
std::lock_guard<std::mutex> lck(blockBMtx);
158158

159-
// If it didn't decode properly return
159+
// If it didn't decode properly return (TODO: Make sure this is not needed)
160160
if (!blockAvail[BLOCK_TYPE_B]) { return; }
161161

162162
// Decode group type and version
@@ -240,13 +240,57 @@ namespace rds {
240240
group2LastUpdate = std::chrono::high_resolution_clock::now();
241241
}
242242

243+
void Decoder::decodeGroup10() {
244+
// Acquire lock
245+
std::lock_guard<std::mutex> lck(group10Mtx);
246+
247+
// Check if the text needs to be cleared
248+
bool ab = (blocks[BLOCK_TYPE_B] >> 14) & 1;
249+
if (ab != ptnAB) {
250+
programTypeName = " ";
251+
}
252+
ptnAB = ab;
253+
254+
// Decode segment address
255+
bool addr = (blocks[BLOCK_TYPE_B] >> 10) & 1;
256+
257+
// Save text depending on address
258+
if (addr) {
259+
if (blockAvail[BLOCK_TYPE_C]) {
260+
programTypeName[4] = (blocks[BLOCK_TYPE_C] >> 18) & 0xFF;
261+
programTypeName[5] = (blocks[BLOCK_TYPE_C] >> 10) & 0xFF;
262+
}
263+
if (blockAvail[BLOCK_TYPE_D]) {
264+
programTypeName[6] = (blocks[BLOCK_TYPE_D] >> 18) & 0xFF;
265+
programTypeName[7] = (blocks[BLOCK_TYPE_D] >> 10) & 0xFF;
266+
}
267+
}
268+
else {
269+
if (blockAvail[BLOCK_TYPE_C]) {
270+
programTypeName[0] = (blocks[BLOCK_TYPE_C] >> 18) & 0xFF;
271+
programTypeName[1] = (blocks[BLOCK_TYPE_C] >> 10) & 0xFF;
272+
}
273+
if (blockAvail[BLOCK_TYPE_D]) {
274+
programTypeName[2] = (blocks[BLOCK_TYPE_D] >> 18) & 0xFF;
275+
programTypeName[3] = (blocks[BLOCK_TYPE_D] >> 10) & 0xFF;
276+
}
277+
}
278+
279+
flog::debug("PTN: '{}'", programTypeName);
280+
281+
// Update timeout
282+
group10LastUpdate = std::chrono::high_resolution_clock::now();
283+
}
284+
243285
void Decoder::decodeGroup() {
244286
// Make sure blocks B is available
245287
if (!blockAvail[BLOCK_TYPE_B]) { return; }
246288

247289
// Decode block B
248290
decodeBlockB();
249291

292+
//flog::debug("RDS Group {}{}", groupType, (groupVer == GROUP_VER_A) ? 'A':'B');
293+
250294
// Decode depending on group type
251295
switch (groupType) {
252296
case 0:
@@ -255,6 +299,9 @@ namespace rds {
255299
case 2:
256300
decodeGroup2();
257301
break;
302+
case 10:
303+
decodeGroup10();
304+
break;
258305
default:
259306
break;
260307
}
@@ -298,4 +345,9 @@ namespace rds {
298345
auto now = std::chrono::high_resolution_clock::now();
299346
return (std::chrono::duration_cast<std::chrono::milliseconds>(now - group2LastUpdate)).count() < RDS_GROUP_2_TIMEOUT_MS;
300347
}
348+
349+
bool Decoder::group10Valid() {
350+
auto now = std::chrono::high_resolution_clock::now();
351+
return (std::chrono::duration_cast<std::chrono::milliseconds>(now - group10LastUpdate)).count() < RDS_GROUP_10_TIMEOUT_MS;
352+
}
301353
}

decoder_modules/radio/src/rds.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define RDS_BLOCK_B_TIMEOUT_MS 5000.0
99
#define RDS_GROUP_0_TIMEOUT_MS 5000.0
1010
#define RDS_GROUP_2_TIMEOUT_MS 5000.0
11+
#define RDS_GROUP_10_TIMEOUT_MS 5000.0
1112

1213
namespace rds {
1314
enum BlockType {
@@ -232,13 +233,17 @@ namespace rds {
232233
bool radioTextValid() { std::lock_guard<std::mutex> lck(group2Mtx); return group2Valid(); }
233234
std::string getRadioText() { std::lock_guard<std::mutex> lck(group2Mtx); return radioText; }
234235

236+
bool programTypeNameValid() { std::lock_guard<std::mutex> lck(group10Mtx); return group10Valid(); }
237+
std::string getProgramTypeName() { std::lock_guard<std::mutex> lck(group10Mtx); return programTypeName; }
238+
235239
private:
236240
static uint16_t calcSyndrome(uint32_t block);
237241
static uint32_t correctErrors(uint32_t block, BlockType type, bool& recovered);
238242
void decodeBlockA();
239243
void decodeBlockB();
240244
void decodeGroup0();
241245
void decodeGroup2();
246+
void decodeGroup10();
242247
void decodeGroup();
243248

244249
void decodeCallsign();
@@ -247,6 +252,7 @@ namespace rds {
247252
bool blockBValid();
248253
bool group0Valid();
249254
bool group2Valid();
255+
bool group10Valid();
250256

251257
// State machine
252258
uint32_t shiftReg = 0;
@@ -289,5 +295,11 @@ namespace rds {
289295
bool rtAB = false;
290296
std::string radioText = " ";
291297

298+
// Group type 10
299+
std::mutex group10Mtx;
300+
std::chrono::time_point<std::chrono::high_resolution_clock> group10LastUpdate{}; // 1970-01-01
301+
bool ptnAB = false;
302+
std::string programTypeName = " ";
303+
292304
};
293305
}

0 commit comments

Comments
 (0)