From 9516fdc95c0ae8d6427561e82cad022b5d0660f8 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 24 Mar 2025 21:31:57 +0100 Subject: [PATCH] correct the offset words for rds2, group c always has the same offsets, but groups a and b have diffrent and can be sent via group c, so --- doc.md | 4 ++++ src/lib.c | 38 ++++++++++++++++---------------------- src/lib.h | 2 +- src/rds.c | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/doc.md b/doc.md index eaada87..7f05319 100644 --- a/doc.md +++ b/doc.md @@ -12,6 +12,10 @@ The newer standard which is the IEC one, removes these features: - PIN - LIC - DI (partially, only dynamic pty is left) +- EWS (now ODA) +- IH (now ODA) +- RP +- TDC (now ODA) ## Unique features diff --git a/src/lib.c b/src/lib.c index 42f57bb..327eab6 100644 --- a/src/lib.c +++ b/src/lib.c @@ -12,8 +12,7 @@ void msleep(unsigned long ms) { int _strnlen(const char *s, int maxlen) { int len = 0; - while (s[len] != 0 && len < maxlen) - len++; + while (s[len] != 0 && len < maxlen) len++; return len; } @@ -25,24 +24,23 @@ static uint16_t offset_words[] = { 0x350 /* C' */ }; -void add_checkwords(uint16_t *blocks, uint8_t *bits) +void add_checkwords(uint16_t *blocks, uint8_t *bits, uint8_t stream) { - uint8_t i, j, bit, msb; - uint16_t block, block_crc, check, offset_word; - bool group_type_b = false; - if (IS_TYPE_B(blocks)) - group_type_b = true; + uint16_t offset_word; + bool group_type_b = IS_TYPE_B(blocks); + bool rds2_tunneling = (blocks[0] & 0xFE00) && (stream != 0); - for (i = 0; i < GROUP_LENGTH; i++) { - if (i == 2 && group_type_b) { + for (uint8_t i = 0; i < GROUP_LENGTH; i++) { + offset_word = offset_words[i]; + if ((i == 2 && group_type_b && stream == 0) || + (i == 2 && group_type_b && rds2_tunneling)) { offset_word = offset_words[4]; - } else { - offset_word = offset_words[i]; } - block = blocks[i]; + uint16_t block = blocks[i]; - block_crc = 0; + uint16_t block_crc = 0; + uint8_t j, bit, msb; for (j = 0; j < BLOCK_SIZE; j++) { bit = (block & (0x8000 >> j)) != 0; msb = (block_crc >> (POLY_DEG - 1)) & 1; @@ -50,7 +48,7 @@ void add_checkwords(uint16_t *blocks, uint8_t *bits) if (msb ^ bit) block_crc ^= POLY; *bits++ = bit; } - check = block_crc ^ offset_word; + uint16_t check = block_crc ^ offset_word; for (j = 0; j < POLY_DEG; j++) { *bits++ = (check & ((1 << (POLY_DEG - 1)) >> j)) != 0; } @@ -59,15 +57,11 @@ void add_checkwords(uint16_t *blocks, uint8_t *bits) uint8_t add_rds_af(RDSAFs *af_list, float freq) { uint16_t af; + uint8_t entries_reqd = 1; + if (freq < 87.6f || freq > 107.9f) entries_reqd = 2; - if (freq < 87.6f || freq > 107.9f) { - entries_reqd = 2; - } - - if (af_list->num_afs + entries_reqd > MAX_AFS) { - return 1; - } + if (af_list->num_afs + entries_reqd > MAX_AFS) return 1; if (freq >= 87.6f && freq <= 107.9f) { af = (uint16_t)(freq * 10.0f) - 875; diff --git a/src/lib.h b/src/lib.h index c135736..4d74bd5 100644 --- a/src/lib.h +++ b/src/lib.h @@ -2,6 +2,6 @@ extern void msleep(unsigned long ms); extern int _strnlen(const char *s, int maxlen); -extern void add_checkwords(uint16_t *blocks, uint8_t *bits); +extern void add_checkwords(uint16_t *blocks, uint8_t *bits, uint8_t stream); extern uint8_t add_rds_af(RDSAFs *af_list, float freq); extern char *xlat(char *str); \ No newline at end of file diff --git a/src/rds.c b/src/rds.c index b89f430..06ecf36 100644 --- a/src/rds.c +++ b/src/rds.c @@ -659,7 +659,7 @@ group_coded: void get_rds_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream) { static uint16_t out_blocks[GROUP_LENGTH]; get_rds_group(enc, out_blocks, stream); - add_checkwords(out_blocks, bits); + add_checkwords(out_blocks, bits, stream); } static void init_rtplus(RDSEncoder* enc, uint8_t group, uint8_t program) {