mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
more success in lua
This commit is contained in:
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@@ -42,6 +42,14 @@
|
||||
"set_rds_rt_type",
|
||||
"set_rds_rds2mod",
|
||||
"set_rds_rdsgen",
|
||||
"set_rds_ptyn"
|
||||
"set_rds_ptyn",
|
||||
"set_rds_ps",
|
||||
"core_version",
|
||||
"set_rds_tps",
|
||||
"data",
|
||||
"set_rds_rt2",
|
||||
"set_rds_rt1",
|
||||
"set_rds_lps",
|
||||
"set_rds_ert"
|
||||
]
|
||||
}
|
||||
@@ -12,29 +12,6 @@ typedef struct {
|
||||
void (*handler)(char *arg, char *pattern, RDSModulator* mod, char* output);
|
||||
} pattern_command_handler_t;
|
||||
|
||||
#define SIMPLE_INT_HANDLER(name, field) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
mod->enc->data[mod->enc->program].field = atoi(arg); \
|
||||
strcpy(output, "+"); \
|
||||
}
|
||||
#define STRING_HANDLER(name, length, function) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
arg[length*2] = 0; \
|
||||
function(mod->enc, convert_to_rdscharset(arg)); \
|
||||
strcpy(output, "+"); \
|
||||
}
|
||||
#define RAW_STRING_HANDLER(name, length, function) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
arg[length*2] = 0; \
|
||||
function(mod->enc, arg); \
|
||||
strcpy(output, "+"); \
|
||||
}
|
||||
#define HEX_HANDLER(name, field) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
mod->enc->data[mod->enc->program].field = strtoul(arg, NULL, 16); \
|
||||
strcpy(output, "+"); \
|
||||
}
|
||||
|
||||
#define AF_HANDLER(name, af_struct, af_entry, add_func) \
|
||||
static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
if (arg[0] == 0) { \
|
||||
@@ -74,14 +51,6 @@ static void handle_##name(char *arg, RDSModulator* mod, char* output) { \
|
||||
AF_HANDLER(af, RDSAFs, af, add_rds_af)
|
||||
AF_HANDLER(afo, RDSAFsODA, af_oda, add_rds_af_oda)
|
||||
|
||||
STRING_HANDLER(ps, PS_LENGTH, set_rds_ps)
|
||||
STRING_HANDLER(tps, PS_LENGTH, set_rds_tps)
|
||||
STRING_HANDLER(rt1, RT_LENGTH, set_rds_rt1)
|
||||
STRING_HANDLER(rt2, RT_LENGTH, set_rds_rt2)
|
||||
|
||||
RAW_STRING_HANDLER(lps, LPS_LENGTH, set_rds_lps)
|
||||
RAW_STRING_HANDLER(ert, ERT_LENGTH, set_rds_ert)
|
||||
|
||||
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];
|
||||
@@ -296,12 +265,6 @@ static void handle_init(char *arg, RDSModulator* mod, char* output) {
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_ver(char *arg, RDSModulator* mod, char* output) {
|
||||
(void)arg;
|
||||
(void)mod;
|
||||
sprintf(output, "rds95 v. %s - (C) 2025 radio95", VERSION);
|
||||
}
|
||||
|
||||
static void handle_eonen(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].enabled = atoi(arg);
|
||||
strcpy(output, "+");
|
||||
@@ -384,23 +347,16 @@ static void handle_eondt(char *arg, char *pattern, RDSModulator* mod, char* outp
|
||||
}
|
||||
|
||||
static const command_handler_t commands_eq3[] = {
|
||||
{"PS", handle_ps, 2},
|
||||
{"AF", handle_af, 2}
|
||||
};
|
||||
|
||||
static const command_handler_t commands_eq4[] = {
|
||||
{"TPS", handle_tps, 3},
|
||||
{"RT1", handle_rt1, 3},
|
||||
{"RT2", handle_rt2, 3},
|
||||
{"RTP", handle_rtp, 3},
|
||||
{"LPS", handle_lps, 3},
|
||||
{"ERT", handle_ert, 3},
|
||||
{"AFO", handle_afo, 3},
|
||||
{"ADR", handle_adr, 3}
|
||||
};
|
||||
|
||||
static const command_handler_t commands_eq5[] = {
|
||||
{"TEXT", handle_rt1, 4},
|
||||
{"ERTP", handle_ertp, 4},
|
||||
{"LINK", handle_link, 4},
|
||||
{"SITE", handle_site, 4}
|
||||
@@ -428,7 +384,6 @@ static const command_handler_t commands_eq8[] = {
|
||||
};
|
||||
static const command_handler_t commands_exact[] = {
|
||||
{"INIT", handle_init, 4},
|
||||
{"VER", handle_ver, 3},
|
||||
{"RESET", handle_reset, 5},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
do return "" end
|
||||
|
||||
if type(cmd) == "string" then
|
||||
local cmd, value = cmd:match("([^=]+)=([^=]+)")
|
||||
if type(data) == "string" then
|
||||
local cmd, value = data:match("([^=]+)=([^=]+)")
|
||||
if cmd == nil then
|
||||
data = data:lower()
|
||||
if data == "ver" then
|
||||
return string.format("rds95 v. %s - (C) 2025 radio95", core_version)
|
||||
end
|
||||
end
|
||||
cmd = cmd:lower()
|
||||
if cmd == "pi" then
|
||||
local pi = tonumber(value, 16)
|
||||
@@ -77,6 +81,24 @@ if type(cmd) == "string" then
|
||||
elseif cmd == "ptyn" then
|
||||
set_rds_ptyn(value)
|
||||
return "+"
|
||||
elseif cmd == "ps" then
|
||||
set_rds_ps(value)
|
||||
return "+"
|
||||
elseif cmd == "tps" then
|
||||
set_rds_tps(value)
|
||||
return "+"
|
||||
elseif cmd == "rt1" or cmd == "text" then
|
||||
set_rds_rt1(value)
|
||||
return "+"
|
||||
elseif cmd == "rt2" then
|
||||
set_rds_rt2(value)
|
||||
return "+"
|
||||
elseif cmd == "lps" then
|
||||
set_rds_lps(value)
|
||||
return "+"
|
||||
elseif cmd == "ert" then
|
||||
set_rds_ert(value)
|
||||
return "+"
|
||||
else
|
||||
return "?"
|
||||
end
|
||||
|
||||
@@ -9,6 +9,12 @@ int lua_set_rds_##name(lua_State *localL) { \
|
||||
return 0; \
|
||||
}
|
||||
#define STR_NONRETURN_HANDLER(name, function) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
const char* str = luaL_checklstring(localL, 1, NULL); \
|
||||
function(mod->enc, convert_to_rdscharset(str)); \
|
||||
return 0; \
|
||||
}
|
||||
#define STR_RAW_NONRETURN_HANDLER(name, function) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
const char* str = luaL_checklstring(localL, 1, NULL); \
|
||||
function(mod->enc, str); \
|
||||
@@ -38,6 +44,13 @@ int lua_set_rds_rdsgen(lua_State *localL) {
|
||||
}
|
||||
|
||||
STR_NONRETURN_HANDLER(ptyn, set_rds_ptyn)
|
||||
STR_NONRETURN_HANDLER(ps, set_rds_ps)
|
||||
STR_NONRETURN_HANDLER(tps, set_rds_tps)
|
||||
STR_NONRETURN_HANDLER(rt1, set_rds_rt1)
|
||||
STR_NONRETURN_HANDLER(rt2, set_rds_rt2)
|
||||
|
||||
STR_RAW_NONRETURN_HANDLER(lps, set_rds_lps)
|
||||
STR_RAW_NONRETURN_HANDLER(ert, set_rds_ert)
|
||||
|
||||
void init_lua(RDSModulator* rds_mod) {
|
||||
mod = rds_mod;
|
||||
@@ -51,6 +64,9 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
luaL_requiref(L, LUA_MATHLIBNAME, luaopen_math, 1);
|
||||
lua_pop(L, 6);
|
||||
|
||||
lua_pushstring(L, VERSION);
|
||||
lua_setglobal(L, "core_version");
|
||||
|
||||
lua_register(L, "set_rds_pi", lua_set_rds_pi);
|
||||
lua_register(L, "set_rds_pty", lua_set_rds_pty);
|
||||
lua_register(L, "set_rds_ecc", lua_set_rds_ecc);
|
||||
@@ -66,11 +82,17 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
lua_register(L, "set_rds_rds2mod", lua_set_rds_rds2mod);
|
||||
lua_register(L, "set_rds_rdsgen", lua_set_rds_rdsgen);
|
||||
lua_register(L, "set_rds_ptyn", lua_set_rds_ptyn);
|
||||
lua_register(L, "set_rds_ps", lua_set_rds_ps);
|
||||
lua_register(L, "set_rds_tps", lua_set_rds_tps);
|
||||
lua_register(L, "set_rds_rt1", lua_set_rds_rt1);
|
||||
lua_register(L, "set_rds_rt2", lua_set_rds_rt2);
|
||||
lua_register(L, "set_rds_lps", lua_set_rds_lps);
|
||||
lua_register(L, "set_rds_ert", lua_set_rds_ert);
|
||||
}
|
||||
|
||||
void run_lua(char *str, char *cmd_output) {
|
||||
lua_pushstring(L, str);
|
||||
lua_setglobal(L, "cmd");
|
||||
lua_setglobal(L, "data");
|
||||
|
||||
int top = lua_gettop(L);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user