From 7727d15ba51567c8fa27c55bd27f8ca251f3543f Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 29 Dec 2025 10:34:28 +0100 Subject: [PATCH] better scheduling of oda --- scripts/0-oda.lua | 10 ++++++---- scripts/0-rds2_oda.lua | 34 +++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/scripts/0-oda.lua b/scripts/0-oda.lua index 56998ad..a1714d2 100644 --- a/scripts/0-oda.lua +++ b/scripts/0-oda.lua @@ -93,10 +93,12 @@ local function get_data() if oda ~= false and type(oda.handler) == "function" then local generated, b, c, d = oda.handler() - _RDS_ODA_pointer = (_RDS_ODA_pointer % #_RDS_ODAs) + 1 - b = b | oda.group << 12 - b = b | (oda.group_version and 1 or 0) << 11 - return generated, b, c, d + if 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 + return generated, b, c, d + end end _RDS_ODA_pointer = (_RDS_ODA_pointer % #_RDS_ODAs) + 1 diff --git a/scripts/0-rds2_oda.lua b/scripts/0-rds2_oda.lua index 9a0e8e0..4177714 100644 --- a/scripts/0-rds2_oda.lua +++ b/scripts/0-rds2_oda.lua @@ -102,17 +102,29 @@ function 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, a, b, c, d = oda.handler(stream) - local channel_bitshift = 8 - local fid = (a & 0xC000) >> 14 - local fn_msb = (a >> 13) & 1 - if fid == 0 and fn_msb == 0 then - warn("RDS2 ODA is tunneling (A or B) over C") - return true, 0, b, c, d -- Tunnel, not sure why but sure - --FID = 1 means a normal ODA group - --FID = 2 means a RFT file - elseif fid == 2 and fn_msb == 0 then channel_bitshift = 0 end -- This is AID - return generated, (channel << channel_bitshift) | a, b, c, d + 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 + _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] + checked = checked + 1 + else + local channel_bitshift = 8 + local fid = (a & 0xC000) >> 14 + local fn_msb = (a >> 13) & 1 + if fid == 0 and fn_msb == 0 then + warn("RDS2 ODA is tunneling (A or B) over C") + return true, 0, b, c, d -- Tunnel, not sure why but sure + --FID = 1 means a normal ODA group + --FID = 2 means a RFT file + elseif fid == 2 and fn_msb == 0 then channel_bitshift = 0 end -- This is AID + return generated, (channel << channel_bitshift) | a, b, c, d + end + end + if checked == #_RDS2_ODAs then return false, 0, 0, 0, 0 end end return true, (2 << 14) | channel, oda.aid, (oda.data >> 16) & 0xffff, oda.data & 0xffff end