mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
af is in lua now
This commit is contained in:
@@ -193,4 +193,11 @@ function set_rds_rtp_meta(ertp, enabled, running) end
|
||||
---Gets the metadata of RTP and ERTP
|
||||
---@param ertp boolean
|
||||
---@return boolean enabled, boolean running
|
||||
function get_rds_rtp_meta(ertp) end
|
||||
function get_rds_rtp_meta(ertp) end
|
||||
|
||||
---Sets the AFs included in group 0
|
||||
---@param afs table
|
||||
function set_rds_af_group0(afs) end
|
||||
---Sets the AFs included in the ODA
|
||||
---@param afs table
|
||||
function set_rds_af_oda(afs) end
|
||||
@@ -12,45 +12,6 @@ typedef struct {
|
||||
void (*handler)(char *arg, char *pattern, RDSModulator* mod, char* output);
|
||||
} pattern_command_handler_t;
|
||||
|
||||
#define AF_HANDLER(name, af_struct, af_entry, add_func) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
if (arg[0] == 0) { \
|
||||
memset(&(mod->enc->data[mod->enc->program].af_entry), 0, sizeof(mod->enc->data[mod->enc->program].af_entry)); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
uint8_t arg_count; \
|
||||
af_struct new_af; \
|
||||
float af[MAX_AFS], *af_iter; \
|
||||
\
|
||||
arg_count = sscanf(arg, \
|
||||
"%f,%f,%f,%f,%f," \
|
||||
"%f,%f,%f,%f,%f," \
|
||||
"%f,%f,%f,%f,%f," \
|
||||
"%f,%f,%f,%f,%f," \
|
||||
"%f,%f,%f,%f,%f", \
|
||||
&af[0], &af[1], &af[2], &af[3], &af[4], \
|
||||
&af[5], &af[6], &af[7], &af[8], &af[9], \
|
||||
&af[10], &af[11], &af[12], &af[13], &af[14], \
|
||||
&af[15], &af[16], &af[17], &af[18], &af[19], \
|
||||
&af[20], &af[21], &af[22], &af[23], &af[24]); \
|
||||
\
|
||||
if (arg_count <= 0 || arg_count > MAX_AFS) { \
|
||||
strcpy(output, "-"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
memset(&new_af, 0, sizeof(af_struct)); \
|
||||
af_iter = af; \
|
||||
while (arg_count-- != 0) add_func(&new_af, *af_iter++); \
|
||||
\
|
||||
memcpy(&(mod->enc->data[mod->enc->program].af_entry), &new_af, sizeof(new_af)); \
|
||||
strcpy(output, "+"); \
|
||||
}
|
||||
|
||||
AF_HANDLER(af, RDSAFs, af, add_rds_af)
|
||||
AF_HANDLER(afo, RDSAFsODA, af_oda, add_rds_af_oda)
|
||||
|
||||
static void handle_udg(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
uint8_t all_scanned = 1, bad_format = 0;
|
||||
uint16_t blocks[8][3];
|
||||
@@ -226,12 +187,7 @@ static void handle_eondt(char *arg, char *pattern, RDSModulator* mod, char* outp
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static const command_handler_t commands_eq3[] = {
|
||||
{"AF", handle_af, 2}
|
||||
};
|
||||
|
||||
static const command_handler_t commands_eq4[] = {
|
||||
{"AFO", handle_afo, 3},
|
||||
{"ADR", handle_adr, 3}
|
||||
};
|
||||
|
||||
@@ -340,10 +296,6 @@ void process_ascii_cmd(RDSModulator* mod, char *str, char *cmd_output) {
|
||||
size_t table_size = 0;
|
||||
|
||||
switch (eq_pos) {
|
||||
case 2:
|
||||
table = commands_eq3;
|
||||
table_size = sizeof(commands_eq3) / sizeof(command_handler_t);
|
||||
break;
|
||||
case 3:
|
||||
table = commands_eq4;
|
||||
table_size = sizeof(commands_eq4) / sizeof(command_handler_t);
|
||||
|
||||
@@ -207,6 +207,42 @@ if type(data) == "string" and data ~= nil then
|
||||
set_rds_rtp_meta(is_ertp, enabled, running)
|
||||
if f2 ~= 0 then toggle_rds_rtp(is_ertp) end
|
||||
return "+"
|
||||
elseif cmd == "af" then
|
||||
local af_table = {}
|
||||
|
||||
if value == "" or value == "0" then
|
||||
set_rds_af_group0({})
|
||||
return "+"
|
||||
end
|
||||
|
||||
for freq_str in value:gmatch("([^,]+)") do
|
||||
local f = tonumber(freq_str)
|
||||
if f then table.insert(af_table, f)
|
||||
else return "-" end
|
||||
end
|
||||
|
||||
if #af_table > 25 then return "-" end
|
||||
|
||||
set_rds_af_group0(af_table)
|
||||
return "+"
|
||||
elseif cmd == "afo" then
|
||||
local af_table = {}
|
||||
|
||||
if value == "" or value == "0" then
|
||||
set_rds_af_oda({})
|
||||
return "+"
|
||||
end
|
||||
|
||||
for freq_str in value:gmatch("([^,]+)") do
|
||||
local f = tonumber(freq_str)
|
||||
if f then table.insert(af_table, f)
|
||||
else return "-" end
|
||||
end
|
||||
|
||||
if #af_table > 25 then return "-" end
|
||||
|
||||
set_rds_af_oda(af_table)
|
||||
return "+"
|
||||
else
|
||||
return "?"
|
||||
end
|
||||
|
||||
@@ -263,6 +263,51 @@ int lua_get_rds_grpseq(lua_State *localL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_set_rds_af_group0(lua_State *localL) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
|
||||
int n = lua_rawlen(L, 1);
|
||||
if (n == 0) {
|
||||
memset(&(mod->enc->data[mod->enc->program].af), 0, sizeof(RDSAFs));
|
||||
return 0;
|
||||
}
|
||||
if(n > 25) return luaL_error(L, "table length over 25");
|
||||
|
||||
RDSAFs new_af;
|
||||
memset(&new_af, 0, sizeof(RDSAFs));
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
lua_rawgeti(L, 1, i);
|
||||
if (lua_isnumber(L, -1)) add_rds_af(&new_af, lua_tonumber(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
memcpy(&(mod->enc->data[mod->enc->program].af), &new_af, sizeof(new_af));
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_set_rds_af_oda(lua_State *localL) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
|
||||
int n = lua_rawlen(L, 1);
|
||||
if (n == 0) {
|
||||
memset(&(mod->enc->data[mod->enc->program].af_oda), 0, sizeof(RDSAFsODA));
|
||||
return 0;
|
||||
}
|
||||
if(n > 25) return luaL_error(L, "table length over 25");
|
||||
|
||||
RDSAFsODA new_af;
|
||||
memset(&new_af, 0, sizeof(RDSAFsODA));
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
lua_rawgeti(L, 1, i);
|
||||
if (lua_isnumber(L, -1)) add_rds_af_oda(&new_af, lua_tonumber(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
memcpy(&(mod->enc->data[mod->enc->program].af_oda), &new_af, sizeof(new_af));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_lua(RDSModulator* rds_mod) {
|
||||
mod = rds_mod;
|
||||
L = luaL_newstate();
|
||||
@@ -367,6 +412,9 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
|
||||
lua_register(L, "put_rds_custom_group", lua_put_rds_custom_group);
|
||||
lua_register(L, "put_rds2_custom_group", lua_put_rds2_custom_group);
|
||||
|
||||
lua_register(L, "set_rds_af_group0", lua_set_rds_af_group0);
|
||||
lua_register(L, "set_rds_af_oda", lua_set_rds_af_oda);
|
||||
}
|
||||
|
||||
void run_lua(char *str, char *cmd_output) {
|
||||
|
||||
Reference in New Issue
Block a user