mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
something
This commit is contained in:
25
plugin.lua
25
plugin.lua
@@ -26,6 +26,24 @@ function on_init() end
|
||||
---It should be defined by the user in the script.
|
||||
---@return nil
|
||||
function on_start() end
|
||||
---This function is called every minute
|
||||
---It should be defined by the user in the script.
|
||||
---@return nil
|
||||
function tick() end
|
||||
---This function is called in order to handle UDP data
|
||||
---It should be defined by the user in the script.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data_handle(data) end
|
||||
---This function is called when the group "L" is in the sequence
|
||||
---It should be defined by the user in the script.
|
||||
---@param b integer
|
||||
---@param c integer
|
||||
---@param d integer
|
||||
---@return integer b
|
||||
---@return integer c
|
||||
---@return integer d
|
||||
function group(a, b, c, d) end
|
||||
|
||||
---@param pi integer
|
||||
function set_rds_pi(pi) end
|
||||
@@ -240,3 +258,10 @@ function set_rds_udg(xy, groups) end
|
||||
---@param xy boolean
|
||||
---@param groups table Table of tables, this should be up to 8 tables containing 4 integers
|
||||
function set_rds_udg2(xy, groups) end
|
||||
|
||||
---Registers an ODA to be used in the O of the group sequence
|
||||
---@param group integer
|
||||
---@param group_version boolean
|
||||
---@param id integer
|
||||
---@param id_data integer
|
||||
function register_oda(group, group_version, id, id_data) end
|
||||
@@ -1,4 +1,4 @@
|
||||
if type(data) == "string" and data ~= nil then
|
||||
function data_handle(data)
|
||||
local cmd, value = data:match("([^=]+)=([^=]+)")
|
||||
if cmd == nil then
|
||||
data = data:lower()
|
||||
@@ -64,6 +64,7 @@ if type(data) == "string" and data ~= nil then
|
||||
end
|
||||
end
|
||||
|
||||
---@diagnostic disable-next-line: need-check-nil
|
||||
cmd = cmd:lower()
|
||||
|
||||
local eon_num, eon_type = cmd:match("^eon(%d+)([a-z]+)$")
|
||||
|
||||
@@ -515,23 +515,78 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
}
|
||||
|
||||
void run_lua(char *str, char *cmd_output) {
|
||||
lua_pushstring(L, str);
|
||||
lua_setglobal(L, "data");
|
||||
|
||||
int top = lua_gettop(L);
|
||||
|
||||
char path[128];
|
||||
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
|
||||
if (luaL_loadfilex(L, path, NULL) == LUA_OK && lua_pcall(L, 0, 1, 0) == LUA_OK) {
|
||||
if (lua_isstring(L, -1)) {
|
||||
if(cmd_output) strcpy(cmd_output, lua_tostring(L, -1));
|
||||
const char *home = getenv("HOME");
|
||||
if (!home) return;
|
||||
snprintf(path, sizeof(path), "%s/.rds95.command.lua", home);
|
||||
|
||||
if (luaL_loadfile(L, path) != LUA_OK) {
|
||||
fprintf(stderr, "Lua error loading file: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
|
||||
fprintf(stderr, "Lua error running script: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
lua_getglobal(L, "data_handle");
|
||||
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushstring(L, str);
|
||||
if (lua_pcall(L, 1, 1, 0) == LUA_OK) {
|
||||
if (lua_isstring(L, -1) && cmd_output) {
|
||||
const char *res = lua_tostring(L, -1);
|
||||
strcpy(cmd_output, res);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else if (lua_isstring(L, -1)) {
|
||||
if (cmd_output) strcpy(cmd_output, lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
const char *err = lua_tostring(L, -1);
|
||||
fprintf(stderr, "Lua error: %s\n", err);
|
||||
lua_pop(L, 1);
|
||||
lua_settop(L, top);
|
||||
}
|
||||
}
|
||||
|
||||
void lua_group(RDSGroup* group) {
|
||||
char path[128];
|
||||
const char *home = getenv("HOME");
|
||||
if (!home) return;
|
||||
snprintf(path, sizeof(path), "%s/.rds95.command.lua", home);
|
||||
|
||||
if (luaL_loadfile(L, path) != LUA_OK) {
|
||||
fprintf(stderr, "Lua error loading file: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
|
||||
fprintf(stderr, "Lua error running script: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
lua_getglobal(L, "group");
|
||||
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushinteger(L, group->b);
|
||||
lua_pushinteger(L, group->c);
|
||||
lua_pushinteger(L, group->d);
|
||||
if (lua_pcall(L, 3, 3, 0) == LUA_OK) {
|
||||
group->d = luaL_checkinteger(L, -1);
|
||||
group->c = luaL_checkinteger(L, -2);
|
||||
group->b = luaL_checkinteger(L, -3);
|
||||
lua_pop(L, 3);
|
||||
} else {
|
||||
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,9 +601,6 @@ void lua_call_function(const char* function) {
|
||||
return;
|
||||
}
|
||||
|
||||
lua_pushnil(L); // Make sure the script doesn't parse any old command
|
||||
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);
|
||||
@@ -560,7 +612,7 @@ void lua_call_function(const char* function) {
|
||||
|
||||
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));
|
||||
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else lua_pop(L, 1);
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
|
||||
void init_lua(RDSModulator* rds_mod);
|
||||
void run_lua(char *str, char *cmd_output);
|
||||
void lua_group(RDSGroup* group);
|
||||
void lua_call_function(const char* function);
|
||||
void destroy_lua();
|
||||
@@ -28,6 +28,7 @@ void get_rds_eon_group(RDSEncoder* enc, RDSGroup *group);
|
||||
void get_rds_ert_group(RDSEncoder* enc, RDSGroup *group);
|
||||
uint8_t get_rds_custom_groups(RDSEncoder* enc, RDSGroup *group);
|
||||
uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group);
|
||||
void get_rdsp_lua_group(RDSGroup *group);
|
||||
|
||||
#define HANDLE_UDG_STREAM(chan_idx, udg_prefix) \
|
||||
do { \
|
||||
@@ -108,6 +109,9 @@ static void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, char* grp,
|
||||
case 'T':
|
||||
get_rds_fasttuning_group(enc, group);
|
||||
break;
|
||||
case 'L':
|
||||
get_rdsp_lua_group(group);
|
||||
break;
|
||||
case 'U':
|
||||
if(enc->state[enc->program].af_oda == 0) get_rds_oda_af_group(enc, group);
|
||||
else get_rdsp_oda_af_oda_group(group);
|
||||
@@ -153,6 +157,7 @@ static void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
|
||||
utc = gmtime(&now);
|
||||
|
||||
if (utc->tm_min != enc->state[enc->program].last_minute) {
|
||||
lua_call_function("tick");
|
||||
enc->state[enc->program].last_minute = utc->tm_min;
|
||||
|
||||
uint8_t eon_has_ta = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "rds.h"
|
||||
#include "lib.h"
|
||||
#include "lua_rds.h"
|
||||
|
||||
uint16_t get_next_af(RDSEncoder* enc) {
|
||||
uint16_t out;
|
||||
@@ -365,3 +366,7 @@ uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void get_rdsp_lua_group(RDSGroup *group) {
|
||||
lua_group(group);
|
||||
group->is_type_b = (IS_TYPE_B(group->b) != 0);
|
||||
}
|
||||
Reference in New Issue
Block a user