diff --git a/decoder_modules/radio/src/rds.cpp b/decoder_modules/radio/src/rds.cpp index 354cfddf..d8f1e9ee 100644 --- a/decoder_modules/radio/src/rds.cpp +++ b/decoder_modules/radio/src/rds.cpp @@ -156,7 +156,7 @@ namespace rds { // Acquire lock std::lock_guard 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 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(now - group2LastUpdate)).count() < RDS_GROUP_2_TIMEOUT_MS; } + + bool Decoder::group10Valid() { + auto now = std::chrono::high_resolution_clock::now(); + return (std::chrono::duration_cast(now - group10LastUpdate)).count() < RDS_GROUP_10_TIMEOUT_MS; + } } \ No newline at end of file diff --git a/decoder_modules/radio/src/rds.h b/decoder_modules/radio/src/rds.h index 8f075f85..5b6b851e 100644 --- a/decoder_modules/radio/src/rds.h +++ b/decoder_modules/radio/src/rds.h @@ -8,6 +8,7 @@ #define RDS_BLOCK_B_TIMEOUT_MS 5000.0 #define RDS_GROUP_0_TIMEOUT_MS 5000.0 #define RDS_GROUP_2_TIMEOUT_MS 5000.0 +#define RDS_GROUP_10_TIMEOUT_MS 5000.0 namespace rds { enum BlockType { @@ -232,6 +233,9 @@ namespace rds { bool radioTextValid() { std::lock_guard lck(group2Mtx); return group2Valid(); } std::string getRadioText() { std::lock_guard lck(group2Mtx); return radioText; } + bool programTypeNameValid() { std::lock_guard lck(group10Mtx); return group10Valid(); } + std::string getProgramTypeName() { std::lock_guard lck(group10Mtx); return programTypeName; } + private: static uint16_t calcSyndrome(uint32_t block); static uint32_t correctErrors(uint32_t block, BlockType type, bool& recovered); @@ -239,6 +243,7 @@ namespace rds { void decodeBlockB(); void decodeGroup0(); void decodeGroup2(); + void decodeGroup10(); void decodeGroup(); void decodeCallsign(); @@ -247,6 +252,7 @@ namespace rds { bool blockBValid(); bool group0Valid(); bool group2Valid(); + bool group10Valid(); // State machine uint32_t shiftReg = 0; @@ -289,5 +295,11 @@ namespace rds { bool rtAB = false; std::string radioText = " "; + // Group type 10 + std::mutex group10Mtx; + std::chrono::time_point group10LastUpdate{}; // 1970-01-01 + bool ptnAB = false; + std::string programTypeName = " "; + }; } \ No newline at end of file