0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00
This commit is contained in:
2025-12-28 22:48:49 +01:00
parent cd7dbff03b
commit 51645c9798
7 changed files with 47 additions and 13 deletions

View File

@@ -44,6 +44,7 @@ function rds2_group(stream)
local oda = _RDS2_ODAs[_RDS2_ODA_pointer]
local channel_offset = 16 * ((not oda.file_related) and 1 or 0)
local channel = ((_RDS2_ODA_pointer - 1 + channel_offset) & 0x3F)
if oda.file_related then channel = channel & 0xF end
_RDS2_ODA_pointer = _RDS2_ODA_pointer + 1
@@ -78,9 +79,11 @@ function rds2_group(stream)
local channel_bitshift = 8
local fid = (a & 0xC000) >> 14
local fn_msb = (a >> 13) & 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
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

View File

@@ -3,11 +3,15 @@ _Rft_file = ""
_Rft_file_segment = 0
_Rft_toggle = false
_Rft_last_id = -1
_Rft_version = 0 -- TODO
_Rft_version = 0
_Rft_crc_mode = -1
_Rft_crc_state = 0
_Rft_crc_sent = false
_Rft_aid = 0xFF7F
local function start_rft()
if _Rft_oda_id == nil then
_Rft_oda_id = register_oda_rds2(0xFF7F, 0, true)
_Rft_oda_id = register_oda_rds2(_Rft_aid, 0, true)
set_oda_handler_rds2(_Rft_oda_id, function ()
if #_Rft_file == 0 then return false, 0, 0, 0, 0 end
@@ -15,6 +19,14 @@ local function start_rft()
local seg = _Rft_file_segment
local base = seg * 5 + 1
if not _Rft_crc_sent and _Rft_crc_mode ~= -1 then
--- TODO: warn that if we have over 511 segments, we can't have CRC if we want per-segment crc
_Rft_crc_sent = true
if _Rft_crc_mode ~= 0 then warn("rft: No other crc than mode 0 is supported as of now") end
_Rft_crc_mode = 0
return true, (2 << 14), _Rft_aid, (1 << 28) | (_Rft_crc_mode & 7) << 25 | (seg & 511), crc16(_Rft_file)
end
local function b(i) return string.byte(_Rft_file, base + i) or 0 end
local word1 = (((_Rft_toggle and 1 or 0) << 7) | ((seg >> 8) & 0x7F))
@@ -23,9 +35,7 @@ local function start_rft()
local word4 = (b(3) << 8) | b(4)
_Rft_file_segment = seg + 1
if _Rft_file_segment >= total_segments then
_Rft_file_segment = 0
end
if _Rft_file_segment >= total_segments then _Rft_file_segment = 0 end
return true, (2 << 12) | word1, word2, word3, word4
end)
@@ -36,7 +46,8 @@ 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_station_logo(path, id)
---@param crc boolean
function load_station_logo(path, id, crc)
local file = io.open(path, "rb")
if not file then error("Could not open file") end
_Rft_file = file:read("*a")
@@ -44,13 +55,21 @@ function load_station_logo(path, id)
if id == _Rft_last_id then
_Rft_toggle = not _Rft_toggle
_Rft_crc_state = 0
_Rft_crc_sent = false
_Rft_version = _Rft_version + 1
if _Rft_version > 7 then _Rft_version = 0 end
end
if crc then
_Rft_crc_mode = 0
else
_Rft_crc_mode = -1
end
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 & 63) << 18 | (_Rft_version & 7) << 24 | 0 << 27)
set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | (id & 63) << 18 | (_Rft_version & 7) << 24 | ((_Rft_crc_mode ~= -1) and 1 or 0) << 27)
_Rft_last_id = id
end