From 1ed47ea0771690a96da71172c90920f1aadbaeba Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sun, 28 Dec 2025 23:30:37 +0100 Subject: [PATCH] maybe my receiver is bugged? (rds spy) --- scripts/1-rft.lua | 5 ++--- src/lib.c | 12 +++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/1-rft.lua b/scripts/1-rft.lua index 82e46cf..fe8398e 100644 --- a/scripts/1-rft.lua +++ b/scripts/1-rft.lua @@ -5,7 +5,6 @@ _Rft_toggle = false _Rft_last_id = -1 _Rft_version = 0 _Rft_crc_mode = -1 -_Rft_crc_state = 0 _Rft_crc_sent = false _Rft_aid = 0xFF7F @@ -24,7 +23,7 @@ local function start_rft() _Rft_crc_sent = true if _Rft_crc_mode ~= 0 then warn("rft: No other crc than mode 0 is supported as of now") end _Rft_crc_mode = 0 - return true, (2 << 14), _Rft_aid, (1 << 12) | (_Rft_crc_mode & 7) << 9 | (seg & 511), crc16(_Rft_file) + return true, (2 << 14), _Rft_aid, (1 << 12) | (0 & 7) << 9 | (0 & 0x1ff), crc16(_Rft_file) else _Rft_crc_sent = false end @@ -59,7 +58,7 @@ function load_station_logo(path, id, crc) if id == _Rft_last_id then _Rft_toggle = not _Rft_toggle - _Rft_crc_state = 0 + _Rft_crc_sent = 0 _Rft_version = _Rft_version + 1 if _Rft_version > 7 then _Rft_version = 0 end end diff --git a/src/lib.c b/src/lib.c index fa1b2f5..5bfe5b5 100644 --- a/src/lib.c +++ b/src/lib.c @@ -26,15 +26,17 @@ inline int _strncpy(char *dest, const char *src, int n) { return i; } uint16_t crc16_ccitt(const char* data, uint16_t len) { - uint16_t i, crc=0xFFFF; - for (i=0; i < len; i++ ) { - crc = (unsigned char)(crc >> 8) | (crc << 8); + uint16_t crc = 0xffff; + + for (size_t i = 0; i < len; i++) { + crc = (crc >> 8) | (crc << 8); crc ^= data[i]; - crc ^= (unsigned char)(crc & 0xff) >> 4; + crc ^= (crc & 0xff) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xff) << 4) << 1; } - return ((crc ^= 0xFFFF) & 0xFFFF); + + return crc ^ 0xffff; } inline uint16_t get_block_from_group(RDSGroup *group, uint8_t block) {