From 7d98606917e01b8bad7f157ac4db391a2eee2301 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sun, 28 Dec 2025 12:03:53 +0100 Subject: [PATCH] rft tests --- scripts/0-rds2_oda.lua | 4 +-- scripts/1-af.lua | 2 ++ scripts/1-ert.lua | 2 ++ scripts/1-rft.lua | 62 ++++++++++++++++++++++++++++++++++++++++++ scripts/1-rtp.lua | 2 ++ scripts/2-state.lua | 6 ---- 6 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 scripts/1-rft.lua delete mode 100644 scripts/2-state.lua diff --git a/scripts/0-rds2_oda.lua b/scripts/0-rds2_oda.lua index 8b0f668..129d3f5 100644 --- a/scripts/0-rds2_oda.lua +++ b/scripts/0-rds2_oda.lua @@ -52,7 +52,7 @@ function rds2_group(stream) if _RDS2_ODA_aid == 0 then _RDS2_ODA_aid = 1 - local block1_base = (2 << 14) | (0 << 8) | channel + local block1_base = (2 << 14) | channel if next_oda and oda.data > 0 and oda.data <= 0xFFFF and next_oda.data == 0 then _RDS2_ODA_pointer = _RDS2_ODA_pointer + 1 @@ -72,7 +72,7 @@ function rds2_group(stream) return true, block1_base, oda.aid, (oda.data >> 16) & 0xffff, oda.data & 0xffff else _RDS2_ODA_aid = _RDS2_ODA_aid + 1 - if _RDS2_ODA_aid > 2 then _RDS2_ODA_aid = 0 end + if _RDS2_ODA_aid > 8 then _RDS2_ODA_aid = 0 end if oda.handler then local generated, a, b, c, d = oda.handler(stream) return generated, (1 << 14) | (channel << 8) | a, b, c, d diff --git a/scripts/1-af.lua b/scripts/1-af.lua index 8f05712..f615e8c 100644 --- a/scripts/1-af.lua +++ b/scripts/1-af.lua @@ -111,7 +111,9 @@ function set_rds_af_oda(afs) save_af_to_userdata(afs) end +local _old_on_state_af = on_state function on_state() load_af_from_userdata() if _Af_Oda_len ~= 0 then init_af_oda() end + if type(_old_on_state_af) == "function" then _old_on_state_af() end end \ No newline at end of file diff --git a/scripts/1-ert.lua b/scripts/1-ert.lua index c990b58..f462394 100644 --- a/scripts/1-ert.lua +++ b/scripts/1-ert.lua @@ -68,6 +68,8 @@ function get_rds_ert() return data:match("^(.-)[\r%z]*") or "" end +local _old_on_state_ert = on_state function on_state() if string.byte(get_userdata_offset(257, 1)) ~= 0 then init_ert() end + if type(_old_on_state_ert) == "function" then _old_on_state_ert() end end \ No newline at end of file diff --git a/scripts/1-rft.lua b/scripts/1-rft.lua new file mode 100644 index 0000000..e8836b2 --- /dev/null +++ b/scripts/1-rft.lua @@ -0,0 +1,62 @@ +_Rft_oda_id = nil +_Rft_file = "" +_Rft_file_segment = 0 +_Rft_toggle = false + +local function start_rft() + if _Rft_oda_id == nil then + _Rft_oda_id = register_oda_rds2(0xFF7F, 0, true) + set_oda_handler_rds2(_Rft_oda_id, function () + if #_Rft_file == 0 then + return false, 0, 0, 0, 0 + end + + local total_segments = math.ceil(#_Rft_file / 5) + local seg = _Rft_file_segment + local base = seg * 5 + 1 + + local function b(i) + return string.byte(_Rft_file, base + i) or 0 + end + + local word1 = + (((_Rft_toggle and 1 or 0) << 7) | + ((seg >> 8) & 0x7F)) + + local word2 = + ((seg & 0xFF) << 8) | b(0) + + local word3 = + (b(1) << 8) | b(2) + + local word4 = + (b(3) << 8) | b(4) + + _Rft_file_segment = seg + 1 + if _Rft_file_segment >= total_segments then + _Rft_file_segment = 0 + _Rft_toggle = not _Rft_toggle + end + + return true, word1, word2, word3, word4 + end) + set_rds2_mode(3) + end +end + +function load_rft_file() + local file = io.open("/tmp/rft_test", "rb") + if not file then error("Could not open file") end + _Rft_file = file:read("*a") + file:close() + if #_Rft_file > 262143 then error("The file is too large", 2) end + if _Rft_oda_id == nil then start_rft() end +---@diagnostic disable-next-line: param-type-mismatch + set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | 48 << 18) --- 48 for testing, change to 0 or something else in the future +end + +-- local _old_on_state_rft = on_state +-- function on_state() +-- start_rft() +-- if type(_old_on_state_rft) == "function" then _old_on_state_rft() end +-- end \ No newline at end of file diff --git a/scripts/1-rtp.lua b/scripts/1-rtp.lua index 1398043..b9887bd 100644 --- a/scripts/1-rtp.lua +++ b/scripts/1-rtp.lua @@ -76,7 +76,9 @@ function get_rds_rtplus_tags(ertp) return string.byte(get_userdata_offset(ertp and 267 or 260, 6), 1, 6) end +local _old_on_state_rtp = on_state function on_state() if get_rds_rtp_meta(false) then init_rtp() end if get_rds_rtp_meta(true) then init_ertp() end + if type(_old_on_state_rtp) == "function" then _old_on_state_rtp() end end \ No newline at end of file diff --git a/scripts/2-state.lua b/scripts/2-state.lua deleted file mode 100644 index 3bd7424..0000000 --- a/scripts/2-state.lua +++ /dev/null @@ -1,6 +0,0 @@ ----@diagnostic disable: undefined-global -function on_state() - if get_rds_rtp_meta(false) then init_rtp() end - if get_rds_rtp_meta(true) then init_ertp() end - if string.byte(get_userdata_offset(257, 1)) ~= 0 then init_ert() end -end \ No newline at end of file