bug fixes

This commit is contained in:
2026-04-28 15:40:26 +02:00
parent 381069925f
commit 8c7a4d3e31
7 changed files with 36 additions and 21 deletions
+17 -8
View File
@@ -1,7 +1,8 @@
_RDS2_ODA = { aid = 0, data = 0, handler = false, file_related = false }
_RDS2_ODA = { aid = 0, data = 0, handler = false, file_related = false, channel = 0 }
_RDS2_next_channel = { normal = 16, file = 0 }
function _RDS2_ODA.new(aid, data, handler, file_related)
local instance = { aid = aid or 0, data = data or 0, handler = handler or false, file_related = file_related or false }
function _RDS2_ODA.new(aid, data, handler, file_related, channel)
local instance = { aid = aid or 0, data = data or 0, handler = handler or false, file_related = file_related or false, channel = channel or 0 }
setmetatable(instance, { __index = _RDS2_ODA })
return instance
end
@@ -15,7 +16,16 @@ _RDS2_ODA_pointer = 1
---@param file_related boolean
---@return integer oda_id
function ext.register_oda_rds2(aid, data, file_related)
local oda = _RDS2_ODA.new(aid, data, false, file_related)
local channel
if file_related then
channel = _RDS2_next_channel.file
_RDS2_next_channel.file = _RDS2_next_channel.file + 1
else
channel = _RDS2_next_channel.normal
_RDS2_next_channel.normal = _RDS2_next_channel.normal + 1
end
local oda = _RDS2_ODA.new(aid, data, false, file_related, channel)
for i = 1, #_RDS2_ODAs do
if _RDS2_ODAs[i] == false then
_RDS2_ODAs[i] = oda
@@ -64,8 +74,7 @@ function hooks.rds2_group(stream)
if checked == #_RDS2_ODAs then return false, 0, 0, 0, 0 end
local oda = _RDS2_ODAs[_RDS2_ODA_pointer]
local channel_offset = 16 * ((not oda.file_related) and 1 or 0) -- Channels 0-15 are reserved for file related things
local channel = ((_RDS2_ODA_pointer - 1 + channel_offset) & 0x3F)
local channel = oda.channel
if oda.file_related then channel = channel & 0xF end
_RDS2_ODA_pointer = _RDS2_ODA_pointer + 1
@@ -97,10 +106,10 @@ function hooks.rds2_group(stream)
_RDS2_ODA_aid = _RDS2_ODA_aid + 1
if _RDS2_ODA_aid > 8 then _RDS2_ODA_aid = 0 end
if oda.handler then
local generated = false
generated = false
checked = 0
while generated == false and checked < #_RDS2_ODAs do
local ok, generated, a, b, c, d = pcall(oda.handler, stream)
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
+5 -5
View File
@@ -9,7 +9,7 @@ end
local _RDS_ODAs = {}
local _RDS_ODA_pointer = 1
---Registers an ODA to be used in the O of the group sequence. ODAs are stored as state data, thus running reset_rds will clear it
---Registers an ODA to be used in the '\x06' of the group sequence. ODAs are stored as state data, thus running reset_rds will clear it
---Groups 14, 15, 2, 0 cannot be registered either version, groups 10, 4, 1 can be only registered as B, any other is free to take
---Group 3A will mean that there will be no group handler for this ODA, meaning it can only be interacted with via the 3A AID group, handler set is not possible with such groups
---@param group integer
@@ -52,7 +52,7 @@ function ext.set_oda_id_data(oda_id, data)
end
---Sets a function to handle the ODA data generation.
---The handler is called when the group sequence 'K' slot is processed.
---The handler is called when the group sequence '\xff' slot is processed.
---The function must return 3 integers representing RDS Blocks B, C, and D.
---Please note that you do not need to compute the block A to indentify the group and group version, that will be done for you and EVERY SINGLE group has PTY and TP inserted (and also PI if its a B)
---You are asked to set groups B last 5 bits, leave rest 0
@@ -74,9 +74,8 @@ local function get_aid()
local b = 3 << 12 | oda.group << 1 | (oda.group_version and 1 or 0)
local data, aid = oda.data, oda.aid
_RDS_ODA_pointer = (_RDS_ODA_pointer % #_RDS_ODAs) + 1
if oda.temp then _RDS_ODAs[_RDS_ODA_pointer] = false end
_RDS_ODA_pointer = (_RDS_ODA_pointer % #_RDS_ODAs) + 1
return true, b, data, aid
end
@@ -117,7 +116,8 @@ local function group_handler(group_type)
if _RDS_ODA_pointer > #_RDS_ODAs or _RDS_ODA_pointer < 1 then _RDS_ODA_pointer = 1 end
if group_type == "\x06" then return get_aid()
elseif group_type == "\xff" then return get_data() end
elseif group_type == "\xff" then return get_data()
else return false, 0, 0, 0 end
end
rds.ext.register_group("\x06\xff", group_handler)