0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00

more error handling

This commit is contained in:
2025-12-28 17:09:38 +01:00
parent 8c7e233b13
commit 1b64cdf091
8 changed files with 55 additions and 48 deletions

View File

@@ -3,13 +3,16 @@ _Ertp_oda_id = nil
_Rtp_toggle = false
_Ertp_toggle = false
--- Size: 15 bytes
local USERDATA_RTP_OFFSET = 259
local function init_rtp()
if _Rtp_oda_id == nil then
_Rtp_oda_id = register_oda(11, false, 0x4BD7, 0)
set_oda_handler(_Rtp_oda_id, function ()
local b = (_Rtp_toggle and 1 or 0) << 4 | string.byte(get_userdata_offset(259, 1)) << 3
local data_0 = get_userdata_offset(260, 3)
local data_1 = get_userdata_offset(263, 3)
local b = (_Rtp_toggle and 1 or 0) << 4 | string.byte(get_userdata_offset(USERDATA_RTP_OFFSET, 1)) << 3
local data_0 = get_userdata_offset(USERDATA_RTP_OFFSET+1, 3)
local data_1 = get_userdata_offset(USERDATA_RTP_OFFSET+4, 3)
b = b | (string.byte(data_0, 1) & 0xf8) >> 3
local c = (string.byte(data_0, 1) & 0x7) << 13
@@ -30,9 +33,9 @@ local function init_ertp()
if _Ertp_oda_id == nil then
_Ertp_oda_id = register_oda(12, false, 0x4BD8, 0)
set_oda_handler(_Ertp_oda_id, function ()
local b = (_Ertp_toggle and 1 or 0) << 4 | string.byte(get_userdata_offset(266, 1)) << 3
local data_0 = get_userdata_offset(267, 3)
local data_1 = get_userdata_offset(270, 3)
local b = (_Ertp_toggle and 1 or 0) << 4 | string.byte(get_userdata_offset(USERDATA_RTP_OFFSET+7, 1)) << 3
local data_0 = get_userdata_offset(USERDATA_RTP_OFFSET+8, 3)
local data_1 = get_userdata_offset(USERDATA_RTP_OFFSET+11, 3)
b = b | (string.byte(data_0, 1) & 0xf8) >> 3
local c = (string.byte(data_0, 1) & 0x7) << 13
@@ -52,14 +55,14 @@ end
function set_rds_rtp_meta(ertp, running)
if ertp then
if running and _Ertp_oda_id == nil then init_ertp() end
set_userdata_offset(266, 1, string.char(running and 1 or 0))
set_userdata_offset(USERDATA_RTP_OFFSET+7, 1, string.char(running and 1 or 0))
else
if running and _Rtp_oda_id == nil then init_rtp() end
set_userdata_offset(259, 1, string.char(running and 1 or 0))
set_userdata_offset(USERDATA_RTP_OFFSET, 1, string.char(running and 1 or 0))
end
end
function get_rds_rtp_meta(ertp)
local offset = ertp and 266 or 259
local offset = ertp and (USERDATA_RTP_OFFSET+7) or USERDATA_RTP_OFFSET
return string.byte(get_userdata_offset(offset, 1)) ~= 0
end
function toggle_rds_rtp(ertp)
@@ -70,10 +73,10 @@ end
function set_rds_rtplus_tags(ertp, t1, s1, l1, t2, s2, l2)
set_rds_rtp_meta(ertp, true)
toggle_rds_rtp(ertp)
set_userdata_offset(ertp and 267 or 260, 6, string.char(t1, s1, l1, t2, s2, l2))
set_userdata_offset(ertp and (USERDATA_RTP_OFFSET+8) or (USERDATA_RTP_OFFSET+1), 6, string.char(t1, s1, l1, t2, s2, l2))
end
function get_rds_rtplus_tags(ertp)
return string.byte(get_userdata_offset(ertp and 267 or 260, 6), 1, 6)
return string.byte(get_userdata_offset(ertp and (USERDATA_RTP_OFFSET+8) or (USERDATA_RTP_OFFSET+1), 6), 1, 6)
end
local _old_on_state_rtp = on_state