0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-27 12:53:53 +01:00
This commit is contained in:
2025-12-22 19:13:17 +01:00
parent 630fc747d6
commit ff9f3d1bb8
7 changed files with 265 additions and 22 deletions

View File

@@ -205,14 +205,6 @@ static void handle_grpseq(char *arg, RDSModulator* mod, char* output) {
strcpy(output, "+");
}
static void handle_reset(char *arg, RDSModulator* mod, char* output) {
(void)arg;
encoder_loadFromFile(mod->enc);
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(mod->enc, i);
Modulator_loadFromFile(&mod->params);
strcpy(output, "+");
}
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, "+");
@@ -321,9 +313,6 @@ static const command_handler_t commands_eq7[] = {
static const command_handler_t commands_eq8[] = {
{"ERTPRUN", handle_ertprun, 7},
};
static const command_handler_t commands_exact[] = {
{"RESET", handle_reset, 5},
};
static const pattern_command_handler_t pattern_commands[] = {
{"EON", "EN", handle_eonen},
@@ -406,14 +395,6 @@ void process_ascii_cmd(RDSModulator* mod, char *str, char *cmd_output) {
if(upper_str[i] >= 'a' && upper_str[i] <= 'z') upper_str[i] = upper_str[i] - 'a' + 'A';
}
for (size_t i = 0; i < sizeof(commands_exact) / sizeof(command_handler_t); i++) {
const command_handler_t *handler = &commands_exact[i];
if (cmd_len == handler->cmd_length && strcmp(upper_str, handler->cmd) == 0) {
handler->handler(NULL, mod, output);
return;
}
}
char *equals_pos = strchr(upper_str, '=');
if (equals_pos != NULL) {
cmd = upper_str;

View File

@@ -7,6 +7,9 @@ if type(data) == "string" then
elseif data == "init" then
set_rds_program_defaults()
return "+"
elseif data == "reset" then
reset_rds()
return "+"
end
end
cmd = cmd:lower()
@@ -115,7 +118,7 @@ if type(data) == "string" then
elseif cmd == "program" then
local program = tonumber(value)
if not program then return "-" end
if program < 1 then return "-" end
if program < 1 or program > max_programs then return "-" end
set_rds_program(program-1)
return "+"
elseif cmd == "level" then

View File

@@ -9,6 +9,16 @@ int lua_set_rds_program_defaults(lua_State *localL) {
return 0;
}
int lua_reset_rds(lua_State *localL) {
(void)localL;
encoder_saveToFile(mod->enc);
encoder_loadFromFile(mod->enc);
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(mod->enc, i);
Modulator_saveToFile(&mod->params);
Modulator_loadFromFile(&mod->params);
return 0;
}
#define INT_SETTER(name) \
int lua_set_rds_##name(lua_State *localL) { \
mod->enc->data[mod->enc->program].name = luaL_checkinteger(localL, 1); \
@@ -203,6 +213,17 @@ int lua_get_rds_grpseq2(lua_State *localL) {
return 1;
}
int lua_set_rds_grpseq(lua_State *localL) {
const char* str = luaL_checklstring(localL, 1, NULL);
if(_strnlen(str, 2) < 1) set_rds_grpseq(mod->enc, DEFAULT_GRPSQC);
else set_rds_grpseq(mod->enc, str);
return 0;
}
int lua_get_rds_grpseq(lua_State *localL) {
lua_pushstring(localL, mod->enc->data[mod->enc->program].grp_sqc);
return 1;
}
void init_lua(RDSModulator* rds_mod) {
mod = rds_mod;
L = luaL_newstate();
@@ -217,8 +238,11 @@ void init_lua(RDSModulator* rds_mod) {
lua_pushstring(L, VERSION);
lua_setglobal(L, "core_version");
lua_pushinteger(L, PROGRAMS)
lua_setglobal(L, "max_programs");
lua_register(L, "set_rds_program_defaults", lua_set_rds_program_defaults);
lua_register(L, "reset_rds", lua_reset_rds);
lua_register(L, "set_rds_pi", lua_set_rds_pi);
lua_register(L, "get_rds_pi", lua_get_rds_pi);
@@ -262,6 +286,9 @@ void init_lua(RDSModulator* rds_mod) {
lua_register(L, "set_rds_rdsgen", lua_set_rds_rdsgen);
lua_register(L, "get_rds_rdsgen", lua_get_rds_rdsgen);
lua_register(L, "set_rds_grpseq", lua_set_rds_grpseq);
lua_register(L, "get_rds_grpseq", lua_get_rds_grpseq);
lua_register(L, "set_rds_grpseq2", lua_set_rds_grpseq2);
lua_register(L, "get_rds_grpseq2", lua_get_rds_grpseq2);
@@ -294,6 +321,9 @@ void init_lua(RDSModulator* rds_mod) {
lua_register(L, "set_rds_rtplus_tags", lua_set_rds_rtplus_tags);
lua_register(L, "get_rds_rtplus_tags", lua_get_rds_rtplus_tags);
lua_register(L, "set_rds_ertplus_tags", lua_set_rds_ertplus_tags);
lua_register(L, "get_rds_ertplus_tags", lua_get_rds_ertplus_tags);
}
void run_lua(char *str, char *cmd_output) {
@@ -318,6 +348,40 @@ void run_lua(char *str, char *cmd_output) {
}
}
void lua_on_init() {
char path[128];
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
if (luaL_loadfilex(L, path, NULL) != LUA_OK) {
const char *err = lua_tostring(L, -1);
fprintf(stderr, "Lua error loading file: %s\n", err);
lua_pop(L, 1);
return;
}
lua_pushnil();
lua_setglobal(L, "data")
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
const char *err = lua_tostring(L, -1);
fprintf(stderr, "Lua error running script: %s\n", err);
lua_pop(L, 1);
return;
}
lua_getglobal(L, "on_init");
if (lua_isfunction(L, -1)) {
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "Lua error running 'on_init': %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else {
// printf("Note: 'on_init' function not found in Lua script. Skipping.\n");
lua_pop(L, 1);
}
}
void destroy_lua(void) {
if (L) {
lua_close(L);

View File

@@ -3,8 +3,10 @@
#include <lualib.h>
#include <lauxlib.h>
#include "rds.h"
#include "fs.h"
#include "modulator.h"
void init_lua(RDSModulator* rds_mod);
void run_lua(char *str, char *cmd_output);
void lua_on_init();
void destroy_lua();

View File

@@ -3,6 +3,7 @@
#include "fs.h"
#include "modulator.h"
#include "lib.h"
#include "lua_rds.h"
#include <time.h>
static uint16_t get_next_af(RDSEncoder* enc) {
@@ -695,6 +696,8 @@ void set_rds_defaults(RDSEncoder* enc, uint8_t program) {
reset_rds_state(enc, program);
enc->encoder_data.ascii_data.expected_encoder_addr = 255; // Unknown
lua_on_init();
}
void init_rds_encoder(RDSEncoder* enc) {