mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-27 04:43:52 +01:00
total control over rds2 in lua
This commit is contained in:
19
plugin.lua
19
plugin.lua
@@ -44,16 +44,23 @@ function tick() end
|
|||||||
---@return string
|
---@return string
|
||||||
function data_handle(data) end
|
function data_handle(data) end
|
||||||
---This function is called when the group "L" is in the sequence
|
---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.
|
---It should be defined by the user in the script.
|
||||||
---@param group string group this was called in from the group sequence
|
---@param group string group this was called in from the group sequence
|
||||||
---@param b integer
|
|
||||||
---@param c integer
|
|
||||||
---@param d integer
|
|
||||||
---@return boolean generated
|
---@return boolean generated
|
||||||
---@return integer b
|
---@return integer b
|
||||||
---@return integer c
|
---@return integer c
|
||||||
---@return integer d
|
---@return integer d
|
||||||
function group(group, b, c, d) end
|
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.
|
||||||
|
---@param stream integer
|
||||||
|
---@return integer a
|
||||||
|
---@return integer b
|
||||||
|
---@return integer c
|
||||||
|
---@return integer d
|
||||||
|
function rds2_group(stream) end
|
||||||
|
|
||||||
---@param pi integer
|
---@param pi integer
|
||||||
function set_rds_pi(pi) end
|
function set_rds_pi(pi) end
|
||||||
@@ -117,9 +124,9 @@ function set_rds_rt_type(rt_type) end
|
|||||||
function get_rds_rt_type() end
|
function get_rds_rt_type() end
|
||||||
|
|
||||||
-- Modulation & Generation
|
-- Modulation & Generation
|
||||||
---@param mode boolean
|
---@param mode integer
|
||||||
function set_rds2_mode(mode) end
|
function set_rds2_mode(mode) end
|
||||||
---@return boolean
|
---@return integer
|
||||||
function get_rds2_mode() end
|
function get_rds2_mode() end
|
||||||
|
|
||||||
---@param streams integer
|
---@param streams integer
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
---@diagnostic disable: undefined-global
|
||||||
function on_state()
|
function on_state()
|
||||||
if get_rds_rtp_meta(false) then init_rtp() end
|
if get_rds_rtp_meta(false) then init_rtp() end
|
||||||
if get_rds_rtp_meta(true) then init_ertp() end
|
if get_rds_rtp_meta(true) then init_ertp() end
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ function data_handle(data)
|
|||||||
end
|
end
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
data = data:lower()
|
data = data:lower()
|
||||||
if data == "ver" then return string.format("rds95 v. %s - (C) 2025 radio95 - lua parser", core_version)
|
if data == "ver" then return string.format("rds95 core v. %s - (C) 2025 radio95 - lua parser\r\n", core_version)
|
||||||
elseif data == "init" then
|
elseif data == "init" then
|
||||||
set_rds_program_defaults()
|
set_rds_program_defaults()
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif data == "reset" then
|
elseif data == "reset" then
|
||||||
reset_rds()
|
reset_rds()
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif data == "pi" then return string.format("PI=%s\r\n", string.format("%x", get_rds_pi()))
|
elseif data == "pi" then return string.format("PI=%s\r\n", string.format("%x", get_rds_pi()))
|
||||||
elseif data == "pty" then return string.format("PTY=%s\r\n", string.format("%d", get_rds_pty()))
|
elseif data == "pty" then return string.format("PTY=%s\r\n", string.format("%d", get_rds_pty()))
|
||||||
elseif data == "ecc" then return string.format("ECC=%s\r\n", string.format("%x", get_rds_ecc()))
|
elseif data == "ecc" then return string.format("ECC=%s\r\n", string.format("%x", get_rds_ecc()))
|
||||||
@@ -25,7 +25,7 @@ function data_handle(data)
|
|||||||
elseif data == "rt2en" then return string.format("RT2EN=%s\r\n", string.format("%d", (get_rds_rt2_enabled() and 1 or 0)))
|
elseif data == "rt2en" then return string.format("RT2EN=%s\r\n", string.format("%d", (get_rds_rt2_enabled() and 1 or 0)))
|
||||||
elseif data == "ptynen" then return string.format("PTYNEN=%s\r\n", string.format("%d", (get_rds_ptyn_enabled() and 1 or 0)))
|
elseif data == "ptynen" then return string.format("PTYNEN=%s\r\n", string.format("%d", (get_rds_ptyn_enabled() and 1 or 0)))
|
||||||
elseif data == "rttype" then return string.format("RTTYPE=%s\r\n", string.format("%d", get_rds_rt_type()))
|
elseif data == "rttype" then return string.format("RTTYPE=%s\r\n", string.format("%d", get_rds_rt_type()))
|
||||||
elseif data == "rds2mod" then return string.format("RDS2MOD=%s\r\n", string.format("%d", (get_rds2_mode() and 1 or 0)))
|
elseif data == "rds2mod" then return string.format("RDS2MOD=%s\r\n", string.format("%d", get_rds2_mode()))
|
||||||
elseif data == "rdsgen" then return string.format("RDSGEN=%s\r\n", string.format("%d", get_rds_streams()))
|
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 == "level" then return string.format("LEVEL=%s\r\n", string.format("%d", get_rds_level() * 255))
|
||||||
elseif data == "link" then return string.format("LINK=%s\r\n", string.format("%d", (get_rds_link() and 1 or 0)))
|
elseif data == "link" then return string.format("LINK=%s\r\n", string.format("%d", (get_rds_link() and 1 or 0)))
|
||||||
@@ -51,7 +51,7 @@ function data_handle(data)
|
|||||||
local eon_cmd, eon_num = data:match("^eon(%d+)([a-z]+)$")
|
local eon_cmd, eon_num = data:match("^eon(%d+)([a-z]+)$")
|
||||||
if eon_cmd then
|
if eon_cmd then
|
||||||
local eon_idx = tonumber(eon_cmd)
|
local eon_idx = tonumber(eon_cmd)
|
||||||
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then return "?" end
|
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then return "?\r\n" end
|
||||||
eon_idx = eon_idx - 1
|
eon_idx = eon_idx - 1
|
||||||
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ function data_handle(data)
|
|||||||
elseif eon_num == "dt" then return string.format("EON%dDT=%x\r\n", eon_idx + 1, data_val)
|
elseif eon_num == "dt" then return string.format("EON%dDT=%x\r\n", eon_idx + 1, data_val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return "?"
|
return "?\r\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -74,64 +74,64 @@ function data_handle(data)
|
|||||||
local eon_num, eon_type = cmd:match("^eon(%d+)([a-z]+)$")
|
local eon_num, eon_type = cmd:match("^eon(%d+)([a-z]+)$")
|
||||||
if eon_num then
|
if eon_num then
|
||||||
local eon_idx = tonumber(eon_num)
|
local eon_idx = tonumber(eon_num)
|
||||||
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then return "?" end
|
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then return "?\r\n" end
|
||||||
eon_idx = eon_idx - 1
|
eon_idx = eon_idx - 1
|
||||||
|
|
||||||
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
||||||
if eon_type == "en" then
|
if eon_type == "en" then
|
||||||
local en_val = tonumber(value)
|
local en_val = tonumber(value)
|
||||||
if not en_val then return "-" end
|
if not en_val then return "-\r\n" end
|
||||||
enabled = (en_val ~= 0)
|
enabled = (en_val ~= 0)
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "pi" then
|
elseif eon_type == "pi" then
|
||||||
local pi_val = tonumber(value, 16)
|
local pi_val = tonumber(value, 16)
|
||||||
if not pi_val then return "-" end
|
if not pi_val then return "-\r\n" end
|
||||||
set_rds_eon(eon_idx, enabled, pi_val, tp, ta, pty, ps, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi_val, tp, ta, pty, ps, afs, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "ps" then
|
elseif eon_type == "ps" then
|
||||||
local ps_val = value:sub(1, 24)
|
local ps_val = value:sub(1, 24)
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps_val, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps_val, afs, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "pty" then
|
elseif eon_type == "pty" then
|
||||||
local pty_val = tonumber(value)
|
local pty_val = tonumber(value)
|
||||||
if not pty_val then return "-" end
|
if not pty_val then return "-\r\n" end
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty_val, ps, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty_val, ps, afs, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "ta" then
|
elseif eon_type == "ta" then
|
||||||
if not enabled or not tp then return "-" end
|
if not enabled or not tp then return "-\r\n" end
|
||||||
local ta_val = tonumber(value)
|
local ta_val = tonumber(value)
|
||||||
if not ta_val then return "-" end
|
if not ta_val then return "-\r\n" end
|
||||||
ta = (ta_val ~= 0)
|
ta = (ta_val ~= 0)
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||||
if ta then set_rds_ta(true) end
|
if ta then set_rds_ta(true) end
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "tp" then
|
elseif eon_type == "tp" then
|
||||||
local tp_val = tonumber(value)
|
local tp_val = tonumber(value)
|
||||||
if not tp_val then return "-" end
|
if not tp_val then return "-\r\n" end
|
||||||
tp = (tp_val ~= 0)
|
tp = (tp_val ~= 0)
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "af" then
|
elseif eon_type == "af" then
|
||||||
local af_table = {}
|
local af_table = {}
|
||||||
if value == "" or value == "0" then
|
if value == "" or value == "0" then
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, {}, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, {}, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
for freq_str in value:gmatch("([^,]+)") do
|
for freq_str in value:gmatch("([^,]+)") do
|
||||||
local f = tonumber(freq_str)
|
local f = tonumber(freq_str)
|
||||||
if f then table.insert(af_table, f)
|
if f then table.insert(af_table, f)
|
||||||
else return "-" end
|
else return "-\r\n" end
|
||||||
end
|
end
|
||||||
if #af_table > 25 then return "-" end
|
if #af_table > 25 then return "-\r\n" end
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, af_table, data_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, af_table, data_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif eon_type == "dt" then
|
elseif eon_type == "dt" then
|
||||||
local dt_val = tonumber(value, 16)
|
local dt_val = tonumber(value, 16)
|
||||||
if not dt_val then return "-" end
|
if not dt_val then return "-\r\n" end
|
||||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, dt_val)
|
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, dt_val)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
else return "?" end
|
else return "?\r\n" end
|
||||||
end
|
end
|
||||||
|
|
||||||
local udg_num = cmd:match("^udg([12])$")
|
local udg_num = cmd:match("^udg([12])$")
|
||||||
@@ -142,13 +142,13 @@ function data_handle(data)
|
|||||||
|
|
||||||
for segment in value:gmatch("([^,]+)") do
|
for segment in value:gmatch("([^,]+)") do
|
||||||
local b, c, d = segment:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
local b, c, d = segment:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
||||||
if not (b and c and d) then return "-" end
|
if not (b and c and d) then return "-\r\n" end
|
||||||
table.insert(groups, {tonumber(b, 16), tonumber(c, 16), tonumber(d, 16)})
|
table.insert(groups, {tonumber(b, 16), tonumber(c, 16), tonumber(d, 16)})
|
||||||
end
|
end
|
||||||
|
|
||||||
if #groups > 8 or #groups == 0 then return "-" end
|
if #groups > 8 or #groups == 0 then return "-\r\n" end
|
||||||
set_rds_udg(xy, groups)
|
set_rds_udg(xy, groups)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
if udg2_num then
|
if udg2_num then
|
||||||
local xy = (udg2_num == "1")
|
local xy = (udg2_num == "1")
|
||||||
@@ -162,164 +162,164 @@ function data_handle(data)
|
|||||||
|
|
||||||
if #groups > 8 or #groups == 0 then return "-" end
|
if #groups > 8 or #groups == 0 then return "-" end
|
||||||
set_rds_udg2(xy, groups)
|
set_rds_udg2(xy, groups)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmd == "pi" then
|
if cmd == "pi" then
|
||||||
local pi = tonumber(value, 16)
|
local pi = tonumber(value, 16)
|
||||||
if not pi then return "-" end
|
if not pi then return "-\r\n" end
|
||||||
if (pi & 0xF000) == 0 then return "-" end
|
if (pi & 0xF000) == 0 then return "-\r\n" end
|
||||||
set_rds_pi(pi)
|
set_rds_pi(pi)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ecc" then
|
elseif cmd == "ecc" then
|
||||||
local ecc = tonumber(value, 16)
|
local ecc = tonumber(value, 16)
|
||||||
if not ecc then return "-" end
|
if not ecc then return "-\r\n" end
|
||||||
set_rds_ecc(ecc)
|
set_rds_ecc(ecc)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "pty" then
|
elseif cmd == "pty" then
|
||||||
local pty = tonumber(value)
|
local pty = tonumber(value)
|
||||||
if not pty then return "-" end
|
if not pty then return "-\r\n" end
|
||||||
set_rds_pty(pty)
|
set_rds_pty(pty)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "slcd" then
|
elseif cmd == "slcd" then
|
||||||
local slc_data = tonumber(value, 16)
|
local slc_data = tonumber(value, 16)
|
||||||
if not slc_data then return "-" end
|
if not slc_data then return "-\r\n" end
|
||||||
set_rds_slc_data(slc_data)
|
set_rds_slc_data(slc_data)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ct" then
|
elseif cmd == "ct" then
|
||||||
local ct = tonumber(value)
|
local ct = tonumber(value)
|
||||||
if not ct then return "-" end
|
if not ct then return "-\r\n" end
|
||||||
set_rds_ct(ct ~= 0)
|
set_rds_ct(ct ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "dpty" then
|
elseif cmd == "dpty" then
|
||||||
local dpty = tonumber(value)
|
local dpty = tonumber(value)
|
||||||
if not dpty then return "-" end
|
if not dpty then return "-\r\n" end
|
||||||
set_rds_dpty(dpty ~= 0)
|
set_rds_dpty(dpty ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "tp" then
|
elseif cmd == "tp" then
|
||||||
local tp = tonumber(value)
|
local tp = tonumber(value)
|
||||||
if not tp then return "-" end
|
if not tp then return "-\r\n" end
|
||||||
set_rds_tp(tp ~= 0)
|
set_rds_tp(tp ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ta" then
|
elseif cmd == "ta" then
|
||||||
local ta = tonumber(value)
|
local ta = tonumber(value)
|
||||||
if not ta then return "-" end
|
if not ta then return "-\r\n" end
|
||||||
set_rds_ta(ta ~= 0)
|
set_rds_ta(ta ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rt1en" then
|
elseif cmd == "rt1en" then
|
||||||
local en = tonumber(value)
|
local en = tonumber(value)
|
||||||
if not en then return "-" end
|
if not en then return "-\r\n" end
|
||||||
set_rds_rt1_enabled(en ~= 0)
|
set_rds_rt1_enabled(en ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rt2en" then
|
elseif cmd == "rt2en" then
|
||||||
local en = tonumber(value)
|
local en = tonumber(value)
|
||||||
if not en then return "-" end
|
if not en then return "-\r\n" end
|
||||||
set_rds_rt2_enabled(en ~= 0)
|
set_rds_rt2_enabled(en ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ptynen" then
|
elseif cmd == "ptynen" then
|
||||||
local en = tonumber(value)
|
local en = tonumber(value)
|
||||||
if not en then return "-" end
|
if not en then return "-\r\n" end
|
||||||
set_rds_ptyn_enabled(en ~= 0)
|
set_rds_ptyn_enabled(en ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rttype" then
|
elseif cmd == "rttype" then
|
||||||
local type = tonumber(value)
|
local type = tonumber(value)
|
||||||
if not type then return "-" end
|
if not type then return "-\r\n" end
|
||||||
set_rds_rt_type(type)
|
set_rds_rt_type(type)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rds2mod" then
|
elseif cmd == "rds2mod" then
|
||||||
local type = tonumber(value)
|
local type = tonumber(value)
|
||||||
if not type then return "-" end
|
if not type then return "-\r\n" end
|
||||||
set_rds2_mode(type ~= 0)
|
set_rds2_mode(type)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rdsgen" then
|
elseif cmd == "rdsgen" then
|
||||||
local type = tonumber(value)
|
local type = tonumber(value)
|
||||||
if not type then return "-" end
|
if not type then return "-\r\n" end
|
||||||
set_rds_streams(type)
|
set_rds_streams(type)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ptyn" then
|
elseif cmd == "ptyn" then
|
||||||
set_rds_ptyn(value)
|
set_rds_ptyn(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ps" then
|
elseif cmd == "ps" then
|
||||||
set_rds_ps(value)
|
set_rds_ps(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "tps" then
|
elseif cmd == "tps" then
|
||||||
set_rds_tps(value)
|
set_rds_tps(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rt1" or cmd == "text" then
|
elseif cmd == "rt1" or cmd == "text" then
|
||||||
set_rds_rt1(value)
|
set_rds_rt1(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rt2" then
|
elseif cmd == "rt2" then
|
||||||
set_rds_rt2(value)
|
set_rds_rt2(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "lps" then
|
elseif cmd == "lps" then
|
||||||
set_rds_lps(value)
|
set_rds_lps(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "ert" then
|
elseif cmd == "ert" then
|
||||||
set_rds_ert(value)
|
set_rds_ert(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "link" then
|
elseif cmd == "link" then
|
||||||
local link = tonumber(value)
|
local link = tonumber(value)
|
||||||
if not link then return "-" end
|
if not link then return "-\r\n" end
|
||||||
set_rds_link(link ~= 0)
|
set_rds_link(link ~= 0)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rtper" then
|
elseif cmd == "rtper" then
|
||||||
local period = tonumber(value)
|
local period = tonumber(value)
|
||||||
if not period then return "-" end
|
if not period then return "-\r\n" end
|
||||||
set_rds_rt_switching_period(period*60)
|
set_rds_rt_switching_period(period*60)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "program" then
|
elseif cmd == "program" then
|
||||||
local program = tonumber(value)
|
local program = tonumber(value)
|
||||||
if not program then return "-" end
|
if not program then return "-\r\n" end
|
||||||
if program < 1 or program > max_programs then return "-" end
|
if program < 1 or program > max_programs then return "-\r\n" end
|
||||||
set_rds_program(program-1)
|
set_rds_program(program-1)
|
||||||
set_rds_ta(false)
|
set_rds_ta(false)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "level" then
|
elseif cmd == "level" then
|
||||||
local level = tonumber(value)
|
local level = tonumber(value)
|
||||||
if not level then return "-" end
|
if not level then return "-\r\n" end
|
||||||
set_rds_level(level/255)
|
set_rds_level(level/255)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "dttmout" then
|
elseif cmd == "dttmout" then
|
||||||
local timeout = tonumber(value)
|
local timeout = tonumber(value)
|
||||||
if not timeout then return "-" end
|
if not timeout then return "-\r\n" end
|
||||||
set_rds_rt_text_timeout(timeout*60)
|
set_rds_rt_text_timeout(timeout*60)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "grpseq" then
|
elseif cmd == "grpseq" then
|
||||||
set_rds_grpseq(value)
|
set_rds_grpseq(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "grpseq2" then
|
elseif cmd == "grpseq2" then
|
||||||
set_rds_grpseq2(value)
|
set_rds_grpseq2(value)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "rtp" or cmd == "ertp" then
|
elseif cmd == "rtp" or cmd == "ertp" then
|
||||||
local is_ertp = (cmd == "ertp")
|
local is_ertp = (cmd == "ertp")
|
||||||
local t1, s1, l1, t2, s2, l2 = value:match("(%d+),(%d+),(%d+),(%d+),(%d+),(%d+)")
|
local t1, s1, l1, t2, s2, l2 = value:match("(%d+),(%d+),(%d+),(%d+),(%d+),(%d+)")
|
||||||
|
|
||||||
if not l2 then return "-" end
|
if not l2 then return "-\r\n" end
|
||||||
set_rds_rtplus_tags(
|
set_rds_rtplus_tags(
|
||||||
is_ertp,
|
is_ertp,
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
tonumber(t1), tonumber(s1), tonumber(l1), tonumber(t2), tonumber(s2), tonumber(l2)
|
tonumber(t1), tonumber(s1), tonumber(l1), tonumber(t2), tonumber(s2), tonumber(l2)
|
||||||
)
|
)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "g" then
|
elseif cmd == "g" then
|
||||||
local a, b, c, d = value:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
local a, b, c, d = value:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
||||||
if a and b and c and d then
|
if a and b and c and d then
|
||||||
put_rds2_custom_group(tonumber(a, 16), tonumber(b, 16), tonumber(c, 16), tonumber(d, 16))
|
put_rds2_custom_group(tonumber(a, 16), tonumber(b, 16), tonumber(c, 16), tonumber(d, 16))
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
local b1, c1, d1 = value:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
local b1, c1, d1 = value:match("^(%x%x%x%x)(%x%x%x%x)(%x%x%x%x)$")
|
||||||
if b1 and c1 and d1 then
|
if b1 and c1 and d1 then
|
||||||
put_rds_custom_group(tonumber(b1, 16), tonumber(c1, 16), tonumber(d1, 16))
|
put_rds_custom_group(tonumber(b1, 16), tonumber(c1, 16), tonumber(d1, 16))
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
return "-"
|
return "-\r\n"
|
||||||
elseif cmd == "rtprun" or cmd == "ertprun" then
|
elseif cmd == "rtprun" or cmd == "ertprun" then
|
||||||
local is_ertp = (cmd == "ertprun")
|
local is_ertp = (cmd == "ertprun")
|
||||||
|
|
||||||
local f1_str, f2_str = value:match("([^,]+),?([^,]*)")
|
local f1_str, f2_str = value:match("([^,]+),?([^,]*)")
|
||||||
if not f1_str then return "-" end
|
if not f1_str then return "-\r\n" end
|
||||||
|
|
||||||
local f1 = tonumber(f1_str) or 0
|
local f1 = tonumber(f1_str) or 0
|
||||||
local f2 = tonumber(f2_str) or 0
|
local f2 = tonumber(f2_str) or 0
|
||||||
@@ -327,44 +327,44 @@ function data_handle(data)
|
|||||||
|
|
||||||
set_rds_rtp_meta(is_ertp, running)
|
set_rds_rtp_meta(is_ertp, running)
|
||||||
if f2 ~= 0 then toggle_rds_rtp(is_ertp) end
|
if f2 ~= 0 then toggle_rds_rtp(is_ertp) end
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "af" then
|
elseif cmd == "af" then
|
||||||
local af_table = {}
|
local af_table = {}
|
||||||
|
|
||||||
if value == "" or value == "0" then
|
if value == "" or value == "0" then
|
||||||
set_rds_af_group0({})
|
set_rds_af_group0({})
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
for freq_str in value:gmatch("([^,]+)") do
|
for freq_str in value:gmatch("([^,]+)") do
|
||||||
local f = tonumber(freq_str)
|
local f = tonumber(freq_str)
|
||||||
if f then table.insert(af_table, f)
|
if f then table.insert(af_table, f)
|
||||||
else return "-" end
|
else return "-\r\n" end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #af_table > 25 then return "-" end
|
if #af_table > 25 then return "-\r\n" end
|
||||||
|
|
||||||
set_rds_af_group0(af_table)
|
set_rds_af_group0(af_table)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
elseif cmd == "afo" then
|
elseif cmd == "afo" then
|
||||||
local af_table = {}
|
local af_table = {}
|
||||||
|
|
||||||
if value == "" or value == "0" then
|
if value == "" or value == "0" then
|
||||||
set_rds_af_oda({})
|
set_rds_af_oda({})
|
||||||
return "+"
|
return "+\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
for freq_str in value:gmatch("([^,]+)") do
|
for freq_str in value:gmatch("([^,]+)") do
|
||||||
local f = tonumber(freq_str)
|
local f = tonumber(freq_str)
|
||||||
if f then table.insert(af_table, f)
|
if f then table.insert(af_table, f)
|
||||||
else return "-" end
|
else return "-\r\n" end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #af_table > 25 then return "-" end
|
if #af_table > 25 then return "-\r\n" end
|
||||||
|
|
||||||
set_rds_af_oda(af_table)
|
set_rds_af_oda(af_table)
|
||||||
return "+"
|
return "+\r\n"
|
||||||
else
|
else
|
||||||
return "?"
|
return "?\r\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -177,12 +177,11 @@ INT_SETTER(rt_type)
|
|||||||
INT_GETTER(rt_type)
|
INT_GETTER(rt_type)
|
||||||
|
|
||||||
int lua_set_rds2_mode(lua_State *localL) {
|
int lua_set_rds2_mode(lua_State *localL) {
|
||||||
if (!lua_isboolean(localL, 1)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 1));
|
mod->enc->encoder_data.rds2_mode = luaL_checkinteger(localL, 1);
|
||||||
mod->enc->encoder_data.rds2_mode = lua_toboolean(localL, 1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int lua_get_rds2_mode(lua_State *localL) {
|
int lua_get_rds2_mode(lua_State *localL) {
|
||||||
lua_pushboolean(localL, mod->enc->encoder_data.rds2_mode);
|
lua_pushinteger(localL, mod->enc->encoder_data.rds2_mode);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int lua_set_rds_streams(lua_State *localL) {
|
int lua_set_rds_streams(lua_State *localL) {
|
||||||
@@ -601,10 +600,7 @@ int lua_group(RDSGroup* group, const char grp) {
|
|||||||
|
|
||||||
if (lua_isfunction(L, -1)) {
|
if (lua_isfunction(L, -1)) {
|
||||||
lua_pushstring(L, &grp);
|
lua_pushstring(L, &grp);
|
||||||
lua_pushinteger(L, group->b);
|
if (lua_pcall(L, 1, 4, 0) == LUA_OK) {
|
||||||
lua_pushinteger(L, group->c);
|
|
||||||
lua_pushinteger(L, group->d);
|
|
||||||
if (lua_pcall(L, 4, 4, 0) == LUA_OK) {
|
|
||||||
if (!lua_isboolean(L, -1)) {
|
if (!lua_isboolean(L, -1)) {
|
||||||
pthread_mutex_unlock(&lua_mutex);
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -636,6 +632,41 @@ int lua_group(RDSGroup* group, const char grp) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lua_rds2_group(RDSGroup* group, int stream) {
|
||||||
|
pthread_mutex_lock(&lua_mutex);
|
||||||
|
lua_getglobal(L, "rds2_group");
|
||||||
|
|
||||||
|
if (lua_isfunction(L, -1)) {
|
||||||
|
lua_pushinteger(L, stream);
|
||||||
|
if (lua_pcall(L, 1, 4, 0) == LUA_OK) {
|
||||||
|
if (!lua_isinteger(L, -1)) {
|
||||||
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!lua_isinteger(L, -2)) {
|
||||||
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!lua_isinteger(L, -3)) {
|
||||||
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!lua_isinteger(L, -4)) {
|
||||||
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
group->d = luaL_checkinteger(L, -1);
|
||||||
|
group->c = luaL_checkinteger(L, -2);
|
||||||
|
group->b = luaL_checkinteger(L, -3);
|
||||||
|
group->a = luaL_checkinteger(L, -4);
|
||||||
|
lua_pop(L, 3);
|
||||||
|
} else fprintf(stderr, "Lua error: %s at 'rds2_group'\n", lua_tostring(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
} else lua_pop(L, 1);
|
||||||
|
pthread_mutex_unlock(&lua_mutex);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void lua_group_ref(RDSGroup* group, int ref) {
|
void lua_group_ref(RDSGroup* group, int ref) {
|
||||||
pthread_mutex_lock(&lua_mutex);
|
pthread_mutex_lock(&lua_mutex);
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
void init_lua(RDSModulator* rds_mod);
|
void init_lua(RDSModulator* rds_mod);
|
||||||
void run_lua(char *str, char *cmd_output);
|
void run_lua(char *str, char *cmd_output);
|
||||||
int lua_group(RDSGroup* group, const char grp);
|
int lua_group(RDSGroup* group, const char grp);
|
||||||
|
int lua_rds2_group(RDSGroup* group, int stream);
|
||||||
void lua_call_function_nolock(const char* function);
|
void lua_call_function_nolock(const char* function);
|
||||||
void lua_call_function(const char* function);
|
void lua_call_function(const char* function);
|
||||||
void lua_group_ref(RDSGroup* group, int ref);
|
void lua_group_ref(RDSGroup* group, int ref);
|
||||||
|
|||||||
@@ -245,6 +245,10 @@ static void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
|
|||||||
|
|
||||||
get_rds_sequence_group(enc, group, &grp, stream);
|
get_rds_sequence_group(enc, group, &grp, stream);
|
||||||
|
|
||||||
|
goto group_coded_rds2;
|
||||||
|
} else if(enc->encoder_data.rds2_mode == 2) {
|
||||||
|
lua_rds2_group(group, stream);
|
||||||
|
if(group->a == 0) group->is_type_b = (IS_TYPE_B(group->b) != 0);
|
||||||
goto group_coded_rds2;
|
goto group_coded_rds2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#define LUA_USER_DATA 1024
|
#define LUA_USER_DATA 1280
|
||||||
|
|
||||||
/* The RDS error-detection code generator polynomial is
|
/* The RDS error-detection code generator polynomial is
|
||||||
* x^10 + x^8 + x^7 + x^5 + x^4 + x^3 + x^0
|
* x^10 + x^8 + x^7 + x^5 + x^4 + x^3 + x^0
|
||||||
@@ -183,8 +183,7 @@ typedef struct {
|
|||||||
} RDSState;
|
} RDSState;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t special_features;
|
uint8_t rds2_mode : 2;
|
||||||
uint8_t rds2_mode : 1;
|
|
||||||
// uint8_t rds2_buffer[16384];
|
// uint8_t rds2_buffer[16384];
|
||||||
} RDSEncoderData;
|
} RDSEncoderData;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user