From 48bad4ea9e6e0b1d690701d3b410441912f3dc46 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Tue, 20 Jan 2026 21:43:16 +0100 Subject: [PATCH] all the functions --- plugin.lua | 19 +++++++++++-------- scripts/0-oda.lua | 4 ++-- scripts/0-rds2_oda.lua | 4 ++-- scripts/99-data.lua | 12 ++++++------ src/lua_rds.c | 20 +++++++++++--------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/plugin.lua b/plugin.lua index 72313c3..597b532 100644 --- a/plugin.lua +++ b/plugin.lua @@ -18,7 +18,7 @@ function dp.crc16(data) end ---Starts the initialization sequence, also calls the on_init function ---@return nil -function dp.set_rds_program_defaults() end +function dp.set_program_defaults() end ---Saves, loads and resets the state of the data, you might as well restart the whole program ---@return nil @@ -29,9 +29,9 @@ function dp.reset_rds() end function dp.force_save() end ---@param program_idx integer 0 to (max_programs - 1) -function dp.set_rds_program(program_idx) end +function dp.set_program(program_idx) end ---@return integer -function dp.get_rds_program() end +function dp.get_program() end ---This function is called by the C core after we reset data, or have no data in general ---It should be defined by the user in the script. @@ -64,6 +64,7 @@ ticks = {} ---@param data string ---@return string function data_handle(data) end + ---This function is called when the group "L" is in the sequence ---Please remember that the core always fills in PTY and TP and PI in C if this is an B group ---It should be defined by the user in the script. @@ -73,6 +74,7 @@ function data_handle(data) end ---@return integer c ---@return integer d function group(group) end + ---This function is called when an RDS2 group is to be generated on mode 3 ---If a was returned 0, PTY and TP will be filled in, along with the PI code in C if needed ---It should be defined by the user in the script. @@ -157,17 +159,18 @@ function rds.set_rds2_mode(mode) end function rds.get_rds2_mode() end ---@param streams integer -function set_rds_streams(streams) end +function rds.set_streams(streams) end ---@return integer -function get_rds_streams() end +function rds.get_streams() end + ---This function returns the absolute number of streams that can be output without restarting the core ---@return integer -function get_available_rds_streams() end +function rds.get_available_streams() end ---@param level number -function set_rds_level(level) end +function rds.set_level(level) end ---@return number -function get_rds_level() end +function rds.get_level() end -- Program & Linking ---@param linkage boolean diff --git a/scripts/0-oda.lua b/scripts/0-oda.lua index e0dc2be..831c2f1 100644 --- a/scripts/0-oda.lua +++ b/scripts/0-oda.lua @@ -92,8 +92,8 @@ local function get_data() local oda = _RDS_ODAs[_RDS_ODA_pointer] if oda ~= false and type(oda.handler) == "function" then - local generated, b, c, d = oda.handler() - if generated then + local ok, generated, b, c, d = pcall(oda.handler()) + if ok and generated then _RDS_ODA_pointer = (_RDS_ODA_pointer % #_RDS_ODAs) + 1 b = b | oda.group << 12 b = b | (oda.group_version and 1 or 0) << 11 diff --git a/scripts/0-rds2_oda.lua b/scripts/0-rds2_oda.lua index 635dafb..6e8b02a 100644 --- a/scripts/0-rds2_oda.lua +++ b/scripts/0-rds2_oda.lua @@ -100,8 +100,8 @@ function rds2_group(stream) local generated = false checked = 0 while generated == false and checked < #_RDS2_ODAs do - local generated, a, b, c, d = oda.handler(stream) - if not generated then + local ok, generated, a, b, c, d = pcall(oda.handler(stream)) + if not (generated and ok) then _RDS2_ODA_pointer = _RDS2_ODA_pointer + 1 if _RDS2_ODA_pointer > #_RDS2_ODAs then _RDS2_ODA_pointer = 1 end oda = _RDS2_ODAs[_RDS2_ODA_pointer] diff --git a/scripts/99-data.lua b/scripts/99-data.lua index 3f25cf2..7b06a7c 100644 --- a/scripts/99-data.lua +++ b/scripts/99-data.lua @@ -40,7 +40,7 @@ function data_handle(data) data = data:lower() if data == "ver" then return string.format("rds95 core v. %s - (C) 2025 radio95 - lua parser\r\n", core_version) elseif data == "init" then - dp.set_rds_program_defaults() + dp.set_program_defaults() return "+\r\n" elseif data == "reset" then dp.reset_rds() @@ -58,8 +58,8 @@ function data_handle(data) elseif data == "ptynen" then return string.format("PTYNEN=%s\r\n", string.format("%d", (rds.get_ptyn_enabled() and 1 or 0))) elseif data == "rttype" then return string.format("RTTYPE=%s\r\n", string.format("%d", rds.get_rt_type())) elseif data == "rds2mod" then return string.format("RDS2MOD=%s\r\n", string.format("%d", rds.get_rds2_mode())) - elseif data == "rdsgen" then return string.format("RDSGEN=%s\r\n", string.format("%d", get_rds_streams())) - elseif data == "level" then return string.format("LEVEL=%s\r\n", string.format("%d", get_rds_level() * 255)) + elseif data == "rdsgen" then return string.format("RDSGEN=%s\r\n", string.format("%d", rds.get_streams())) + elseif data == "level" then return string.format("LEVEL=%s\r\n", string.format("%d", rds.get_level() * 255)) elseif data == "link" then return string.format("LINK=%s\r\n", string.format("%d", (rds.get_link() and 1 or 0))) elseif data == "rtp" then local t1, s1, l1, t2, s2, l2 = rds.ext.get_rtplus_tags(false) @@ -266,7 +266,7 @@ function data_handle(data) elseif cmd == "rdsgen" then local type = tonumber(value) if not type then return "-\r\n" end - set_rds_streams(type) + rds.set_streams(type) return "+\r\n" elseif cmd == "ptyn" then rds.set_ptyn(value) @@ -303,13 +303,13 @@ function data_handle(data) local program = tonumber(value) if not program then return "-\r\n" end if program < 1 or program > dp.max_programs then return "-\r\n" end - dp.set_rds_program(program-1) + dp.set_program(program-1) rds.set_ta(false) return "+\r\n" elseif cmd == "level" then local level = tonumber(value) if not level then return "-\r\n" end - set_rds_level(level/255) + rds.set_level(level/255) return "+\r\n" elseif cmd == "dttmout" then local timeout = tonumber(value) diff --git a/src/lua_rds.c b/src/lua_rds.c index ff2b15b..ce65cce 100644 --- a/src/lua_rds.c +++ b/src/lua_rds.c @@ -51,11 +51,11 @@ void init_lua(RDSModulator* rds_mod) { lua_registertotable(L, "crc16", lua_crc16); lua_registertotable(L, "force_save", lua_force_save); lua_registertotable(L, "reset_rds", lua_reset_rds); - lua_registertotable(L, "set_rds_program_defaults", lua_set_rds_program_defaults); + lua_registertotable(L, "set_program_defaults", lua_set_rds_program_defaults); lua_pushinteger(L, PROGRAMS); lua_setfield(L, -2, "max_programs"); - lua_registertotable(L, "set_rds_program", lua_set_rds_program); - lua_registertotable(L, "get_rds_program", lua_get_rds_program); + lua_registertotable(L, "set_program", lua_set_rds_program); + lua_registertotable(L, "get_program", lua_get_rds_program); lua_setglobal(L, "dp"); lua_newtable(L); @@ -141,14 +141,16 @@ void init_lua(RDSModulator* rds_mod) { lua_registertotable(L, "set_udg", lua_set_rds_udg); lua_registertotable(L, "set_udg2", lua_set_rds_udg2); + lua_registertotable(L, "set_level", lua_set_rds_level); + lua_registertotable(L, "get_level", lua_get_rds_level); + + lua_registertotable(L, "set_streams", lua_set_rds_streams); + lua_registertotable(L, "get_streams", lua_get_rds_streams); + + lua_registertotable(L, "get_available_streams", lua_get_available_rds_streams); + lua_setglobal(L, "rds"); - lua_register(L, "set_rds_streams", lua_set_rds_streams); - lua_register(L, "get_rds_streams", lua_get_rds_streams); - lua_register(L, "get_available_rds_streams", lua_get_available_rds_streams); - - lua_register(L, "set_rds_level", lua_set_rds_level); - lua_register(L, "get_rds_level", lua_get_rds_level); if (luaL_loadfile(L, "/etc/rds95.lua") != LUA_OK) { fprintf(stderr, "Lua error loading file: %s\n", lua_tostring(L, -1));