mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
some adjustments and smart detections
This commit is contained in:
@@ -42,6 +42,7 @@ end
|
||||
---@param fun ODAHandler
|
||||
function set_oda_handler(oda_id, fun)
|
||||
if oda_id > #_RDS_ODAs then return end
|
||||
if _RDS_ODAs.group == 3 then error("3A ODAs cannot have handlers.") end
|
||||
_RDS_ODAs[oda_id].handler = fun
|
||||
end
|
||||
|
||||
@@ -90,4 +91,11 @@ function group(group_type)
|
||||
end
|
||||
end
|
||||
return false, 0, 0, 0
|
||||
end
|
||||
|
||||
local _old_on_state_oda = on_state
|
||||
function on_state()
|
||||
_RDS_ODAs = {}
|
||||
_RDS_ODA_pointer = 1
|
||||
if type(_old_on_state_oda) == "function" then _old_on_state_oda() end
|
||||
end
|
||||
@@ -75,8 +75,23 @@ function rds2_group(stream)
|
||||
if _RDS2_ODA_aid > 8 then _RDS2_ODA_aid = 0 end
|
||||
if oda.handler then
|
||||
local generated, a, b, c, d = oda.handler(stream)
|
||||
return generated, (channel << 8) | a, b, c, d
|
||||
local channel_bitshift = 8
|
||||
local fid = (a & 0xC000) >> 14
|
||||
local fn_msb = (a >> 15) & 1
|
||||
if fid == 0 and fn_msb == 0 then return true, 0, b, c, d
|
||||
elseif fid == 0 and fn_msb == 1 then channel = channel & 0xF
|
||||
--FID = 1 means a normal ODA group
|
||||
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
|
||||
return true, (2 << 14) | channel, oda.aid, (oda.data >> 16) & 0xffff, oda.data & 0xffff
|
||||
end
|
||||
end
|
||||
|
||||
local _old_on_state_oda_rds2 = on_state
|
||||
function on_state()
|
||||
_RDS2_ODAs = {}
|
||||
_RDS2_ODA_aid = 0
|
||||
_RDS2_ODA_pointer = 1
|
||||
if type(_old_on_state_oda_rds2) == "function" then _old_on_state_oda_rds2() end
|
||||
end
|
||||
@@ -2,6 +2,8 @@ _Rft_oda_id = nil
|
||||
_Rft_file = ""
|
||||
_Rft_file_segment = 0
|
||||
_Rft_toggle = false
|
||||
_Rft_last_id = -1
|
||||
_Rft_version = 0 -- TODO
|
||||
|
||||
local function start_rft()
|
||||
if _Rft_oda_id == nil then
|
||||
@@ -23,7 +25,6 @@ local function start_rft()
|
||||
_Rft_file_segment = seg + 1
|
||||
if _Rft_file_segment >= total_segments then
|
||||
_Rft_file_segment = 0
|
||||
_Rft_toggle = not _Rft_toggle
|
||||
end
|
||||
|
||||
return true, (2 << 12) | word1, word2, word3, word4
|
||||
@@ -35,7 +36,12 @@ end
|
||||
---Loads the file into RFT and initializes it if needed, note that this needs RDR2 mode 2
|
||||
---@param path string
|
||||
---@param id integer
|
||||
function load_rft_file(path, id)
|
||||
function load_station_logo(path, id)
|
||||
if id == _Rft_last_id then
|
||||
_Rft_toggle = not _Rft_toggle
|
||||
_Rft_version = _Rft_version + 1
|
||||
if _Rft_version > 7 then _Rft_version = 0 end
|
||||
end
|
||||
local file = io.open(path, "rb")
|
||||
if not file then error("Could not open file") end
|
||||
_Rft_file = file:read("*a")
|
||||
@@ -44,5 +50,6 @@ function load_rft_file(path, id)
|
||||
if #_Rft_file > 262143 then error("The file is too large", 2) end
|
||||
if _Rft_oda_id == nil then start_rft() end
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | id << 18)
|
||||
set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | (id & 63) << 18 | (_Rft_version & 7) << 24 | 0 << 27)
|
||||
_Rft_last_id = id
|
||||
end
|
||||
Reference in New Issue
Block a user