0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00

rft tests

This commit is contained in:
2025-12-28 12:03:53 +01:00
parent ec4d9a8440
commit 7d98606917
6 changed files with 70 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

62
scripts/1-rft.lua Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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