mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-29 16:29:17 +02:00
bug fixes
This commit is contained in:
+2
-2
@@ -62,13 +62,13 @@ hooks.on_start = {}
|
||||
---@type function[]
|
||||
hooks.on_state = {}
|
||||
|
||||
---This function is called every second
|
||||
---This function is called every second (or rather if the second has changed since the last stream 0 group)
|
||||
---It should be defined by the user in the script.
|
||||
---This is a table of functions. Each will be called
|
||||
---@type function[]
|
||||
hooks.tick = {}
|
||||
|
||||
---This function is called every minute
|
||||
---This function is called every minute (or rather if the minute has changed since the last stream 0 group)
|
||||
---It should be defined by the user in the script.
|
||||
---This is a table of functions. Each will be called
|
||||
---@type function[]
|
||||
|
||||
+17
-8
@@ -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
@@ -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)
|
||||
|
||||
|
||||
+4
-1
@@ -7,11 +7,12 @@ lua_State *L = NULL;
|
||||
static pthread_mutex_t lua_mutex;
|
||||
|
||||
#define lua_registertotable(L,n,f) (lua_pushcfunction(L, (f)), lua_setfield(L, -2, (n)))
|
||||
void init_lua(RDSEncoder* _enc) {
|
||||
uint8_t init_lua(RDSEncoder* _enc) {
|
||||
static int mutex_initialized = 0;
|
||||
enc = _enc;
|
||||
L = luaL_newstate();
|
||||
printf("Initializing %s\n", LUA_COPYRIGHT);
|
||||
if(L == NULL) return 0;
|
||||
|
||||
luaL_requiref(L, "_G", luaopen_base, 1);
|
||||
luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1);
|
||||
@@ -162,6 +163,8 @@ void init_lua(RDSEncoder* _enc) {
|
||||
pthread_mutex_init(&lua_mutex, NULL);
|
||||
mutex_initialized = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void run_lua(char *str, size_t str_len, char *cmd_output, size_t *out_len) {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
void init_lua(RDSEncoder* _enc);
|
||||
uint8_t init_lua(RDSEncoder* _enc);
|
||||
void run_lua(char *str, size_t str_len, char *cmd_output, size_t* out_len);
|
||||
int lua_group(RDSGroup* group, const char grp);
|
||||
int lua_rds2_group(RDSGroup* group, int stream);
|
||||
|
||||
@@ -97,16 +97,16 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
|
||||
time(&now);
|
||||
utc = gmtime(&now);
|
||||
|
||||
if(utc->tm_sec != enc->state[enc->program].last_second) {
|
||||
if(utc->tm_sec != enc->state[enc->program].last_second && stream == 0) {
|
||||
enc->state[enc->program].last_second = utc->tm_sec;
|
||||
lua_call_tfunction("tick");
|
||||
}
|
||||
|
||||
if (utc->tm_min != enc->state[enc->program].last_minute) {
|
||||
if (utc->tm_min != enc->state[enc->program].last_minute && stream == 0) {
|
||||
enc->state[enc->program].last_minute = utc->tm_min;
|
||||
lua_call_tfunction("minute_tick");
|
||||
|
||||
if(enc->data[enc->program].ct && stream == 0) {
|
||||
if(enc->data[enc->program].ct) {
|
||||
get_rdsp_ct_group(group, now);
|
||||
goto group_coded;
|
||||
}
|
||||
|
||||
+4
-1
@@ -169,7 +169,10 @@ int main(int argc, char **argv) {
|
||||
RDSModulator rdsModulator = {0};
|
||||
|
||||
RDSEncoder rdsEncoder = {0};
|
||||
init_lua(&rdsEncoder);
|
||||
if(init_lua(&rdsEncoder) == 1) {
|
||||
fprintf(stderr, "Could not create lua state - not enough memory\n");
|
||||
goto exit;
|
||||
}
|
||||
init_rds_modulator(&rdsModulator, &rdsEncoder, config.num_streams);
|
||||
init_rds_encoder(&rdsEncoder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user