0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 12:32:05 +01:00

all the functions

This commit is contained in:
2026-01-20 21:43:16 +01:00
parent 53c9169330
commit 48bad4ea9e
5 changed files with 32 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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

View File

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