mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-29 16:29:17 +02:00
uecp testing
This commit is contained in:
+73
-57
@@ -6,24 +6,25 @@ static int in_set_defaults = 0;
|
||||
extern lua_State *L;
|
||||
extern RDSEncoder* enc;
|
||||
extern uint8_t unload_refs[33];
|
||||
static int writing_program = 0;
|
||||
|
||||
int lua_get_userdata(lua_State *localL) {
|
||||
lua_pushlstring(localL, (const char*)&enc->data[enc->program].lua_data, LUA_USER_DATA);
|
||||
lua_pushlstring(localL, (const char*)&enc->data[writing_program].lua_data, LUA_USER_DATA);
|
||||
return 1;
|
||||
}
|
||||
int lua_get_userdata_offset(lua_State *localL) {
|
||||
uint16_t offset = luaL_checkinteger(localL, 1);
|
||||
uint16_t size = luaL_checkinteger(localL, 2);
|
||||
if((offset+size) > LUA_USER_DATA) return luaL_error(localL, "data exceeds limit");
|
||||
lua_pushlstring(localL, (const char*)&enc->data[enc->program].lua_data[offset], size);
|
||||
lua_pushlstring(localL, (const char*)&enc->data[writing_program].lua_data[offset], size);
|
||||
return 1;
|
||||
}
|
||||
int lua_set_userdata(lua_State *localL) {
|
||||
size_t len;
|
||||
const char *data = luaL_checklstring(localL, 1, &len);
|
||||
if(len > LUA_USER_DATA) return luaL_error(localL, "data exceeds limit");
|
||||
memset(enc->data[enc->program].lua_data, 0, LUA_USER_DATA);
|
||||
memcpy(enc->data[enc->program].lua_data, data, len);
|
||||
memset(enc->data[writing_program].lua_data, 0, LUA_USER_DATA);
|
||||
memcpy(enc->data[writing_program].lua_data, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -34,8 +35,8 @@ int lua_set_userdata_offset(lua_State *localL) {
|
||||
size_t len;
|
||||
const char *data = luaL_checklstring(localL, 3, &len);
|
||||
if(len > size || (offset + size) > LUA_USER_DATA) return luaL_error(localL, "data exceeds limit");
|
||||
memset(enc->data[enc->program].lua_data + offset, 0, size);
|
||||
memcpy(enc->data[enc->program].lua_data + offset, data, len);
|
||||
memset(enc->data[writing_program].lua_data + offset, 0, size);
|
||||
memcpy(enc->data[writing_program].lua_data + offset, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -55,7 +56,7 @@ int lua_set_rds_program_defaults(lua_State *localL) {
|
||||
in_set_defaults = 1;
|
||||
for (int i = 1; i < *unload_refs; i++) luaL_unref(L, LUA_REGISTRYINDEX, unload_refs[i]);
|
||||
unload_refs[0] = 1;
|
||||
set_rds_defaults(enc, enc->program);
|
||||
set_rds_defaults(enc, writing_program);
|
||||
lua_call_tfunction_nolock("on_init");
|
||||
lua_call_tfunction_nolock("on_state");
|
||||
in_set_defaults = 0;
|
||||
@@ -77,24 +78,24 @@ int lua_reset_rds(lua_State *localL) {
|
||||
#define BOOL_SETTER(name) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
if (!lua_isboolean(localL, 1)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 1)); \
|
||||
enc->data[enc->program].name = lua_toboolean(localL, 1); \
|
||||
enc->data[writing_program].name = lua_toboolean(localL, 1); \
|
||||
return 0; \
|
||||
}
|
||||
#define INT_SETTER(name) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
enc->data[enc->program].name = luaL_checkinteger(localL, 1); \
|
||||
enc->data[writing_program].name = luaL_checkinteger(localL, 1); \
|
||||
return 0; \
|
||||
}
|
||||
#define STR_SETTER(name, function) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
const char* str = luaL_checklstring(localL, 1, NULL); \
|
||||
function(enc, convert_to_rdscharset(str)); \
|
||||
function(enc, convert_to_rdscharset(str), writing_program); \
|
||||
return 0; \
|
||||
}
|
||||
#define STR_RAW_SETTER(name, function) \
|
||||
int lua_set_rds_##name(lua_State *localL) { \
|
||||
const char* str = luaL_checklstring(localL, 1, NULL); \
|
||||
function(enc, str); \
|
||||
function(enc, str, writing_program); \
|
||||
return 0; \
|
||||
}
|
||||
#define AF_SETTER(name, af_field, af_struct, add_func) \
|
||||
@@ -103,7 +104,7 @@ int lua_set_rds_##name(lua_State *localL) { \
|
||||
\
|
||||
int n = lua_rawlen(localL, 1); \
|
||||
if (n == 0) { \
|
||||
memset(&(enc->data[enc->program].af_field), 0, sizeof(af_struct)); \
|
||||
memset(&(enc->data[writing_program].af_field), 0, sizeof(af_struct)); \
|
||||
return 0; \
|
||||
} \
|
||||
if(n > 25) return luaL_error(localL, "table length over 25"); \
|
||||
@@ -117,24 +118,24 @@ int lua_set_rds_##name(lua_State *localL) { \
|
||||
else return luaL_error(localL, "number expected, got %s", luaL_typename(localL, -1)); \
|
||||
lua_pop(localL, 1); \
|
||||
} \
|
||||
memcpy(&(enc->data[enc->program].af_field), &new_af, sizeof(new_af)); \
|
||||
memcpy(&(enc->data[writing_program].af_field), &new_af, sizeof(new_af)); \
|
||||
\
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define INT_GETTER(name) \
|
||||
int lua_get_rds_##name(lua_State *localL) { \
|
||||
lua_pushinteger(localL, enc->data[enc->program].name); \
|
||||
lua_pushinteger(localL, enc->data[writing_program].name); \
|
||||
return 1; \
|
||||
}
|
||||
#define BOOL_GETTER(name) \
|
||||
int lua_get_rds_##name(lua_State *localL) { \
|
||||
lua_pushboolean(localL, enc->data[enc->program].name); \
|
||||
lua_pushboolean(localL, enc->data[writing_program].name); \
|
||||
return 1; \
|
||||
}
|
||||
#define STR_RAW_GETTER(name, length) \
|
||||
int lua_get_rds_##name(lua_State *localL) { \
|
||||
lua_pushlstring(localL, enc->data[enc->program].name, length); \
|
||||
lua_pushlstring(localL, enc->data[writing_program].name, length); \
|
||||
return 1; \
|
||||
}
|
||||
INT_SETTER(pi)
|
||||
@@ -195,12 +196,12 @@ int lua_get_rds_streams(lua_State *localL) {
|
||||
|
||||
int lua_set_rds_link(lua_State *localL) {
|
||||
if (!lua_isboolean(localL, 1)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 1));
|
||||
enc->state[enc->program].eon_linkage = lua_toboolean(localL, 1);
|
||||
enc->state[writing_program].eon_linkage = lua_toboolean(localL, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_link(lua_State *localL) {
|
||||
lua_pushboolean(localL, enc->state[enc->program].eon_linkage);
|
||||
lua_pushboolean(localL, enc->state[writing_program].eon_linkage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -214,6 +215,7 @@ int lua_set_rds_program(lua_State *localL) {
|
||||
enc->data[enc->program].ta = 0;
|
||||
enc->data[(uint8_t)program].ta = 0;
|
||||
enc->program = (uint8_t)program;
|
||||
writing_program = program;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -222,34 +224,48 @@ int lua_get_rds_program(lua_State *localL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_set_rds_writing_program(lua_State *localL) {
|
||||
int program = luaL_checkinteger(localL, 1);
|
||||
if(program >= PROGRAMS) program = (PROGRAMS-1);
|
||||
if(program < 0) program = 0;
|
||||
|
||||
writing_program = program;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_writing_program(lua_State *localL) {
|
||||
lua_pushinteger(localL, writing_program);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_set_rds_rt_switching_period(lua_State *localL) {
|
||||
enc->data[enc->program].rt_switching_period = luaL_checkinteger(localL, 1);
|
||||
enc->state[enc->program].rt_switching_period_state = enc->data[enc->program].rt_switching_period;
|
||||
enc->data[writing_program].rt_switching_period = luaL_checkinteger(localL, 1);
|
||||
enc->state[writing_program].rt_switching_period_state = enc->data[writing_program].rt_switching_period;
|
||||
return 0;
|
||||
}
|
||||
INT_GETTER(rt_switching_period)
|
||||
|
||||
int lua_set_rds_rt_text_timeout(lua_State *localL) {
|
||||
enc->data[enc->program].rt_text_timeout = luaL_checkinteger(localL, 1);
|
||||
enc->state[enc->program].rt_text_timeout_state = enc->data[enc->program].rt_text_timeout;
|
||||
enc->data[writing_program].rt_text_timeout = luaL_checkinteger(localL, 1);
|
||||
enc->state[writing_program].rt_text_timeout_state = enc->data[writing_program].rt_text_timeout;
|
||||
return 0;
|
||||
}
|
||||
INT_GETTER(rt_text_timeout)
|
||||
|
||||
int lua_put_rds_custom_group(lua_State *localL) {
|
||||
enc->state[enc->program].custom_group[0] = 1;
|
||||
enc->state[enc->program].custom_group[1] = luaL_checkinteger(localL, 1);
|
||||
enc->state[enc->program].custom_group[2] = luaL_checkinteger(localL, 2);
|
||||
enc->state[enc->program].custom_group[3] = luaL_checkinteger(localL, 3);
|
||||
enc->state[writing_program].custom_group[0] = 1;
|
||||
enc->state[writing_program].custom_group[1] = luaL_checkinteger(localL, 1);
|
||||
enc->state[writing_program].custom_group[2] = luaL_checkinteger(localL, 2);
|
||||
enc->state[writing_program].custom_group[3] = luaL_checkinteger(localL, 3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_put_rds2_custom_group(lua_State *localL) {
|
||||
enc->state[enc->program].custom_group2[0] = 1;
|
||||
enc->state[enc->program].custom_group2[1] = luaL_checkinteger(localL, 1);
|
||||
enc->state[enc->program].custom_group2[2] = luaL_checkinteger(localL, 2);
|
||||
enc->state[enc->program].custom_group2[3] = luaL_checkinteger(localL, 3);
|
||||
enc->state[enc->program].custom_group2[4] = luaL_checkinteger(localL, 4);
|
||||
enc->state[writing_program].custom_group2[0] = 1;
|
||||
enc->state[writing_program].custom_group2[1] = luaL_checkinteger(localL, 1);
|
||||
enc->state[writing_program].custom_group2[2] = luaL_checkinteger(localL, 2);
|
||||
enc->state[writing_program].custom_group2[3] = luaL_checkinteger(localL, 3);
|
||||
enc->state[writing_program].custom_group2[4] = luaL_checkinteger(localL, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -268,8 +284,8 @@ STR_RAW_GETTER(grp_sqc_rds2, 32)
|
||||
|
||||
int lua_set_rds_grp_sqc(lua_State *localL) {
|
||||
const char* str = luaL_checklstring(localL, 1, NULL);
|
||||
if(_strnlen(str, 2) < 1) set_rds_grpseq(enc, DEFAULT_GRPSQC);
|
||||
else set_rds_grpseq(enc, str);
|
||||
if(_strnlen(str, 2) < 1) set_rds_grpseq(enc, DEFAULT_GRPSQC, writing_program);
|
||||
else set_rds_grpseq(enc, str, writing_program);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -284,16 +300,16 @@ int lua_set_rds_eon(lua_State *localL) {
|
||||
if (!lua_isboolean(localL, 4)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 4));
|
||||
if (!lua_isboolean(localL, 5)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 5));
|
||||
luaL_checktype(localL, 8, LUA_TTABLE);
|
||||
enc->data[enc->program].eon[eon].enabled = lua_toboolean(localL, 2);
|
||||
enc->data[enc->program].eon[eon].pi = luaL_checkinteger(localL, 3);
|
||||
enc->data[enc->program].eon[eon].tp = lua_toboolean(localL, 4);
|
||||
enc->data[enc->program].eon[eon].ta = lua_toboolean(localL, 5);
|
||||
enc->data[enc->program].eon[eon].pty = luaL_checkinteger(localL, 6);
|
||||
_strncpy(enc->data[enc->program].eon[eon].ps, luaL_checklstring(localL, 7, NULL), 8);
|
||||
enc->data[writing_program].eon[eon].enabled = lua_toboolean(localL, 2);
|
||||
enc->data[writing_program].eon[eon].pi = luaL_checkinteger(localL, 3);
|
||||
enc->data[writing_program].eon[eon].tp = lua_toboolean(localL, 4);
|
||||
enc->data[writing_program].eon[eon].ta = lua_toboolean(localL, 5);
|
||||
enc->data[writing_program].eon[eon].pty = luaL_checkinteger(localL, 6);
|
||||
_strncpy(enc->data[writing_program].eon[eon].ps, luaL_checklstring(localL, 7, NULL), 8);
|
||||
|
||||
int n = lua_rawlen(localL, 8);
|
||||
if (n == 0) {
|
||||
memset(&(enc->data[enc->program].eon[eon].af), 0, sizeof(RDSAFs));
|
||||
memset(&(enc->data[writing_program].eon[eon].af), 0, sizeof(RDSAFs));
|
||||
return 0;
|
||||
}
|
||||
if(n > 25) return luaL_error(localL, "table length over 25");
|
||||
@@ -307,23 +323,23 @@ int lua_set_rds_eon(lua_State *localL) {
|
||||
else return luaL_error(localL, "number expected, got %s", luaL_typename(localL, -1));
|
||||
lua_pop(localL, 1);
|
||||
}
|
||||
memcpy(&(enc->data[enc->program].eon[eon].af), &new_af, sizeof(new_af));
|
||||
memcpy(&(enc->data[writing_program].eon[eon].af), &new_af, sizeof(new_af));
|
||||
|
||||
enc->data[enc->program].eon[eon].data = luaL_checkinteger(localL, 9);
|
||||
enc->data[writing_program].eon[eon].data = luaL_checkinteger(localL, 9);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_eon(lua_State *localL) {
|
||||
int eon = luaL_checkinteger(localL, 1);
|
||||
if(eon >= EONs) return luaL_error(localL, "eon index exceeded");
|
||||
lua_pushboolean(localL, enc->data[enc->program].eon[eon].enabled);
|
||||
lua_pushinteger(localL, enc->data[enc->program].eon[eon].pi);
|
||||
lua_pushboolean(localL, enc->data[enc->program].eon[eon].tp);
|
||||
lua_pushboolean(localL, enc->data[enc->program].eon[eon].ta);
|
||||
lua_pushinteger(localL, enc->data[enc->program].eon[eon].pty);
|
||||
lua_pushlstring(localL, enc->data[enc->program].eon[eon].ps, 8);
|
||||
lua_pushboolean(localL, enc->data[writing_program].eon[eon].enabled);
|
||||
lua_pushinteger(localL, enc->data[writing_program].eon[eon].pi);
|
||||
lua_pushboolean(localL, enc->data[writing_program].eon[eon].tp);
|
||||
lua_pushboolean(localL, enc->data[writing_program].eon[eon].ta);
|
||||
lua_pushinteger(localL, enc->data[writing_program].eon[eon].pty);
|
||||
lua_pushlstring(localL, enc->data[writing_program].eon[eon].ps, 8);
|
||||
lua_createtable(localL, 0, 0); // don't have decoding for AF, so just return empty table
|
||||
lua_pushinteger(localL, enc->data[enc->program].eon[eon].data);
|
||||
lua_pushinteger(localL, enc->data[writing_program].eon[eon].data);
|
||||
return 8;
|
||||
}
|
||||
|
||||
@@ -353,11 +369,11 @@ int lua_set_rds_udg(lua_State *localL) {
|
||||
}
|
||||
|
||||
if(xy) {
|
||||
memcpy(&(enc->data[enc->program].udg2), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[enc->program].udg2_len = n;
|
||||
memcpy(&(enc->data[writing_program].udg2), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[writing_program].udg2_len = n;
|
||||
} else {
|
||||
memcpy(&(enc->data[enc->program].udg1), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[enc->program].udg1_len = n;
|
||||
memcpy(&(enc->data[writing_program].udg1), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[writing_program].udg1_len = n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -389,11 +405,11 @@ int lua_set_rds_udg2(lua_State *localL) {
|
||||
}
|
||||
|
||||
if(xy) {
|
||||
memcpy(&(enc->data[enc->program].udg2_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[enc->program].udg2_len_rds2 = n;
|
||||
memcpy(&(enc->data[writing_program].udg2_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[writing_program].udg2_len_rds2 = n;
|
||||
} else {
|
||||
memcpy(&(enc->data[enc->program].udg1_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[enc->program].udg1_len_rds2 = n;
|
||||
memcpy(&(enc->data[writing_program].udg1_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[writing_program].udg1_len_rds2 = n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user