mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-29 08:19:17 +02:00
remove integration of the modulator into command parsing
This commit is contained in:
@@ -163,15 +163,6 @@ function rds.set_streams(streams) end
|
||||
---@return integer
|
||||
function rds.get_streams() end
|
||||
|
||||
---This function returns the absolute number of streams that can be output without restarting the core
|
||||
---@return integer
|
||||
function rds.get_available_streams() end
|
||||
|
||||
---@param level number
|
||||
function rds.set_level(level) end
|
||||
---@return number
|
||||
function rds.get_level() end
|
||||
|
||||
-- Program & Linking
|
||||
---@param linkage boolean
|
||||
function rds.set_link(linkage) end
|
||||
|
||||
@@ -59,7 +59,6 @@ function data_handle(data)
|
||||
elseif data == "rttype" then return string.format("RTTYPE=%s\r\n", string.format("%d", rds.get_rt_type()))
|
||||
elseif data == "rds2mod" then return string.format("RDS2MOD=%s\r\n", string.format("%d", rds.get_rds2_mode()))
|
||||
elseif data == "rdsgen" then return string.format("RDSGEN=%s\r\n", string.format("%d", rds.get_streams()))
|
||||
elseif data == "level" then return string.format("LEVEL=%s\r\n", string.format("%d", rds.get_level() * 255))
|
||||
elseif data == "link" then return string.format("LINK=%s\r\n", string.format("%d", (rds.get_link() and 1 or 0)))
|
||||
elseif data == "rtp" then
|
||||
local t1, s1, l1, t2, s2, l2 = rds.ext.get_rtplus_tags(false)
|
||||
@@ -306,11 +305,6 @@ function data_handle(data)
|
||||
dp.set_program(program-1)
|
||||
rds.set_ta(false)
|
||||
return "+\r\n"
|
||||
elseif cmd == "level" then
|
||||
local level = tonumber(value)
|
||||
if not level then return "-\r\n" end
|
||||
rds.set_level(level/255)
|
||||
return "+\r\n"
|
||||
elseif cmd == "dttmout" then
|
||||
local timeout = tonumber(value)
|
||||
if not timeout then return "-\r\n" end
|
||||
|
||||
@@ -16,8 +16,9 @@ void encoder_saveToFile(RDSEncoder *enc) {
|
||||
memcpy(tempEncoder.data, enc->data, sizeof(RDSData) * PROGRAMS);
|
||||
memcpy(&tempEncoder.encoder_data, &enc->encoder_data, sizeof(RDSEncoderData));
|
||||
tempEncoder.program = enc->program;
|
||||
tempEncoder.enabled_streams = enc->enabled_streams;
|
||||
|
||||
RDSEncoderFile rdsEncoderfile = {.file_starter = 225, .file_middle = 160, .file_ender = 95, .program = tempEncoder.program};
|
||||
RDSEncoderFile rdsEncoderfile = {.file_starter = 225, .file_middle = 160, .file_ender = 95, .program = tempEncoder.program, .enabled_streams = tempEncoder.enabled_streams};
|
||||
memcpy(&rdsEncoderfile.data, &tempEncoder.data, sizeof(RDSData)*PROGRAMS);
|
||||
memcpy(&rdsEncoderfile.encoder_data, &tempEncoder.encoder_data, sizeof(RDSEncoderData));
|
||||
|
||||
@@ -59,78 +60,6 @@ int encoder_loadFromFile(RDSEncoder *enc) {
|
||||
memcpy(&(enc->data), &(rdsEncoderfile.data), sizeof(RDSData)*PROGRAMS);
|
||||
memcpy(&(enc->encoder_data), &(rdsEncoderfile.encoder_data), sizeof(RDSEncoderData));
|
||||
enc->program = rdsEncoderfile.program;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Modulator_saveToFile(RDSModulatorParameters *emp) {
|
||||
char modulatorPath[128];
|
||||
snprintf(modulatorPath, sizeof(modulatorPath), "%s/.rdsModulator", getenv("HOME"));
|
||||
FILE *file;
|
||||
|
||||
RDSModulatorParameters tempMod;
|
||||
RDSModulatorParametersFile tempFile;
|
||||
memset(&tempFile, 0, sizeof(tempFile));
|
||||
file = fopen(modulatorPath, "rb");
|
||||
if (file != NULL) {
|
||||
fread(&tempFile, sizeof(RDSModulatorParametersFile), 1, file);
|
||||
fclose(file);
|
||||
} else {
|
||||
memset(&tempFile, 0, sizeof(RDSModulatorParametersFile));
|
||||
tempFile.check = 160;
|
||||
memcpy(&tempFile.params, emp, sizeof(RDSModulatorParameters));
|
||||
tempFile.crc = crc16_ccitt((char*)&tempFile, offsetof(RDSModulatorParametersFile, crc));
|
||||
}
|
||||
memcpy(&tempMod, &tempFile.params, sizeof(RDSModulatorParameters));
|
||||
|
||||
tempMod.level = emp->level;
|
||||
tempMod.rdsgen = emp->rdsgen;
|
||||
|
||||
memcpy(&tempFile.params, &tempMod, sizeof(RDSModulatorParameters));
|
||||
tempFile.check = 160;
|
||||
tempFile.crc = crc16_ccitt((char*)&tempFile, offsetof(RDSModulatorParametersFile, crc));
|
||||
|
||||
file = fopen(modulatorPath, "wb");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file");
|
||||
return;
|
||||
}
|
||||
fwrite(&tempFile, sizeof(RDSModulatorParametersFile), 1, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void Modulator_loadFromFile(RDSModulatorParameters *emp) {
|
||||
char modulatorPath[128];
|
||||
snprintf(modulatorPath, sizeof(modulatorPath), "%s/.rdsModulator", getenv("HOME"));
|
||||
FILE *file = fopen(modulatorPath, "rb");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file");
|
||||
return;
|
||||
}
|
||||
RDSModulatorParametersFile tempFile;
|
||||
memset(&tempFile, 0, sizeof(tempFile));
|
||||
fread(&tempFile, sizeof(RDSModulatorParametersFile), 1, file);
|
||||
if (tempFile.check != 160) {
|
||||
fprintf(stderr, "[RDSMODULATOR-FILE] Invalid file format\n");
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
uint16_t calculated_crc = crc16_ccitt((char*)&tempFile, offsetof(RDSModulatorParametersFile, crc));
|
||||
if (calculated_crc != tempFile.crc) {
|
||||
fprintf(stderr, "[RDSMODULATOR-FILE] CRC mismatch! Data may be corrupted\n");
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
memcpy(emp, &tempFile.params, sizeof(RDSModulatorParameters));
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int modulatorsaved() {
|
||||
char encoderPath[128];
|
||||
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsModulator", getenv("HOME"));
|
||||
FILE *file = fopen(encoderPath, "rb");
|
||||
if (file) {
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
enc->enabled_streams = rdsEncoderfile.enabled_streams;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include "rds.h"
|
||||
#include "modulator.h"
|
||||
#include "lib.h"
|
||||
|
||||
void encoder_saveToFile(RDSEncoder *emp);
|
||||
int encoder_loadFromFile(RDSEncoder *emp);
|
||||
|
||||
void Modulator_saveToFile(RDSModulatorParameters *emp);
|
||||
void Modulator_loadFromFile(RDSModulatorParameters *emp);
|
||||
int modulatorsaved();
|
||||
int encoder_loadFromFile(RDSEncoder *emp);
|
||||
+71
-89
@@ -4,26 +4,26 @@
|
||||
static int in_set_defaults = 0;
|
||||
|
||||
extern lua_State *L;
|
||||
extern RDSModulator* mod;
|
||||
extern RDSEncoder* enc;
|
||||
extern uint8_t unload_refs[33];
|
||||
|
||||
int lua_get_userdata(lua_State *localL) {
|
||||
lua_pushlstring(localL, (const char*)&mod->enc->data[mod->enc->program].lua_data, LUA_USER_DATA);
|
||||
lua_pushlstring(localL, (const char*)&enc->data[enc->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*)&mod->enc->data[mod->enc->program].lua_data[offset], size);
|
||||
lua_pushlstring(localL, (const char*)&enc->data[enc->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(mod->enc->data[mod->enc->program].lua_data, 0, LUA_USER_DATA);
|
||||
memcpy(mod->enc->data[mod->enc->program].lua_data, data, len);
|
||||
memset(enc->data[enc->program].lua_data, 0, LUA_USER_DATA);
|
||||
memcpy(enc->data[enc->program].lua_data, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -34,16 +34,15 @@ 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(mod->enc->data[mod->enc->program].lua_data + offset, 0, size);
|
||||
memcpy(mod->enc->data[mod->enc->program].lua_data + offset, data, len);
|
||||
memset(enc->data[enc->program].lua_data + offset, 0, size);
|
||||
memcpy(enc->data[enc->program].lua_data + offset, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_force_save(lua_State *localL) {
|
||||
(void)localL;
|
||||
encoder_saveToFile(mod->enc);
|
||||
Modulator_saveToFile(&mod->params);
|
||||
encoder_saveToFile(enc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -56,7 +55,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(mod->enc, mod->enc->program);
|
||||
set_rds_defaults(enc, enc->program);
|
||||
lua_call_tfunction_nolock("on_init");
|
||||
lua_call_tfunction_nolock("on_state");
|
||||
in_set_defaults = 0;
|
||||
@@ -67,12 +66,10 @@ int lua_reset_rds(lua_State *localL) {
|
||||
(void)localL;
|
||||
for (int i = 1; i < *unload_refs; i++) luaL_unref(L, LUA_REGISTRYINDEX, unload_refs[i]);
|
||||
unload_refs[0] = 1;
|
||||
encoder_saveToFile(mod->enc);
|
||||
Modulator_saveToFile(&mod->params);
|
||||
encoder_saveToFile(enc);
|
||||
|
||||
encoder_loadFromFile(mod->enc);
|
||||
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(mod->enc, i);
|
||||
Modulator_loadFromFile(&mod->params);
|
||||
encoder_loadFromFile(enc);
|
||||
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(enc, i);
|
||||
lua_call_tfunction_nolock("on_state");
|
||||
return 0;
|
||||
}
|
||||
@@ -80,24 +77,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)); \
|
||||
mod->enc->data[mod->enc->program].name = lua_toboolean(localL, 1); \
|
||||
enc->data[enc->program].name = lua_toboolean(localL, 1); \
|
||||
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); \
|
||||
enc->data[enc->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(mod->enc, convert_to_rdscharset(str)); \
|
||||
function(enc, convert_to_rdscharset(str)); \
|
||||
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(mod->enc, str); \
|
||||
function(enc, str); \
|
||||
return 0; \
|
||||
}
|
||||
#define AF_SETTER(name, af_field, af_struct, add_func) \
|
||||
@@ -106,7 +103,7 @@ int lua_set_rds_##name(lua_State *localL) { \
|
||||
\
|
||||
int n = lua_rawlen(localL, 1); \
|
||||
if (n == 0) { \
|
||||
memset(&(mod->enc->data[mod->enc->program].af_field), 0, sizeof(af_struct)); \
|
||||
memset(&(enc->data[enc->program].af_field), 0, sizeof(af_struct)); \
|
||||
return 0; \
|
||||
} \
|
||||
if(n > 25) return luaL_error(localL, "table length over 25"); \
|
||||
@@ -120,24 +117,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(&(mod->enc->data[mod->enc->program].af_field), &new_af, sizeof(new_af)); \
|
||||
memcpy(&(enc->data[enc->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, mod->enc->data[mod->enc->program].name); \
|
||||
lua_pushinteger(localL, enc->data[enc->program].name); \
|
||||
return 1; \
|
||||
}
|
||||
#define BOOL_GETTER(name) \
|
||||
int lua_get_rds_##name(lua_State *localL) { \
|
||||
lua_pushboolean(localL, mod->enc->data[mod->enc->program].name); \
|
||||
lua_pushboolean(localL, enc->data[enc->program].name); \
|
||||
return 1; \
|
||||
}
|
||||
#define STR_RAW_GETTER(name, length) \
|
||||
int lua_get_rds_##name(lua_State *localL) { \
|
||||
lua_pushlstring(localL, mod->enc->data[mod->enc->program].name, length); \
|
||||
lua_pushlstring(localL, enc->data[enc->program].name, length); \
|
||||
return 1; \
|
||||
}
|
||||
INT_SETTER(pi)
|
||||
@@ -177,33 +174,33 @@ INT_SETTER(rt_type)
|
||||
INT_GETTER(rt_type)
|
||||
|
||||
int lua_set_rds2_mode(lua_State *localL) {
|
||||
mod->enc->encoder_data.rds2_mode = luaL_checkinteger(localL, 1);
|
||||
enc->encoder_data.rds2_mode = luaL_checkinteger(localL, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds2_mode(lua_State *localL) {
|
||||
lua_pushinteger(localL, mod->enc->encoder_data.rds2_mode);
|
||||
lua_pushinteger(localL, enc->encoder_data.rds2_mode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_set_rds_streams(lua_State *localL) {
|
||||
mod->params.rdsgen = luaL_checkinteger(localL, 1);
|
||||
enc->enabled_streams = luaL_checkinteger(localL, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_streams(lua_State *localL) {
|
||||
lua_pushinteger(localL, mod->params.rdsgen);
|
||||
lua_pushinteger(localL, enc->enabled_streams);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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));
|
||||
mod->enc->state[mod->enc->program].eon_linkage = lua_toboolean(localL, 1);
|
||||
enc->state[enc->program].eon_linkage = lua_toboolean(localL, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_link(lua_State *localL) {
|
||||
lua_pushboolean(localL, mod->enc->state[mod->enc->program].eon_linkage);
|
||||
lua_pushboolean(localL, enc->state[enc->program].eon_linkage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -212,57 +209,47 @@ int lua_set_rds_program(lua_State *localL) {
|
||||
if(program >= PROGRAMS) program = (PROGRAMS-1);
|
||||
if(program < 0) program = 0;
|
||||
|
||||
if(mod->enc->program == program) return 0;
|
||||
if(enc->program == program) return 0;
|
||||
|
||||
mod->enc->data[mod->enc->program].ta = 0;
|
||||
mod->enc->data[(uint8_t)program].ta = 0;
|
||||
mod->enc->program = (uint8_t)program;
|
||||
enc->data[enc->program].ta = 0;
|
||||
enc->data[(uint8_t)program].ta = 0;
|
||||
enc->program = (uint8_t)program;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_program(lua_State *localL) {
|
||||
lua_pushinteger(localL, mod->enc->program);
|
||||
lua_pushinteger(localL, enc->program);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_set_rds_rt_switching_period(lua_State *localL) {
|
||||
mod->enc->data[mod->enc->program].rt_switching_period = luaL_checkinteger(localL, 1);
|
||||
mod->enc->state[mod->enc->program].rt_switching_period_state = mod->enc->data[mod->enc->program].rt_switching_period;
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
INT_GETTER(rt_switching_period)
|
||||
|
||||
int lua_set_rds_rt_text_timeout(lua_State *localL) {
|
||||
mod->enc->data[mod->enc->program].rt_text_timeout = luaL_checkinteger(localL, 1);
|
||||
mod->enc->state[mod->enc->program].rt_text_timeout_state = mod->enc->data[mod->enc->program].rt_text_timeout;
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
INT_GETTER(rt_text_timeout)
|
||||
|
||||
int lua_set_rds_level(lua_State *localL) {
|
||||
mod->params.level = luaL_checknumber(localL, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_rds_level(lua_State *localL) {
|
||||
lua_pushnumber(localL, mod->params.level);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_put_rds_custom_group(lua_State *localL) {
|
||||
mod->enc->state[mod->enc->program].custom_group[0] = 1;
|
||||
mod->enc->state[mod->enc->program].custom_group[1] = luaL_checkinteger(localL, 1);
|
||||
mod->enc->state[mod->enc->program].custom_group[2] = luaL_checkinteger(localL, 2);
|
||||
mod->enc->state[mod->enc->program].custom_group[3] = luaL_checkinteger(localL, 3);
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_put_rds2_custom_group(lua_State *localL) {
|
||||
mod->enc->state[mod->enc->program].custom_group2[0] = 1;
|
||||
mod->enc->state[mod->enc->program].custom_group2[1] = luaL_checkinteger(localL, 1);
|
||||
mod->enc->state[mod->enc->program].custom_group2[2] = luaL_checkinteger(localL, 2);
|
||||
mod->enc->state[mod->enc->program].custom_group2[3] = luaL_checkinteger(localL, 3);
|
||||
mod->enc->state[mod->enc->program].custom_group2[4] = luaL_checkinteger(localL, 4);
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -281,8 +268,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(mod->enc, DEFAULT_GRPSQC);
|
||||
else set_rds_grpseq(mod->enc, str);
|
||||
if(_strnlen(str, 2) < 1) set_rds_grpseq(enc, DEFAULT_GRPSQC);
|
||||
else set_rds_grpseq(enc, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -297,16 +284,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);
|
||||
mod->enc->data[mod->enc->program].eon[eon].enabled = lua_toboolean(localL, 2);
|
||||
mod->enc->data[mod->enc->program].eon[eon].pi = luaL_checkinteger(localL, 3);
|
||||
mod->enc->data[mod->enc->program].eon[eon].tp = lua_toboolean(localL, 4);
|
||||
mod->enc->data[mod->enc->program].eon[eon].ta = lua_toboolean(localL, 5);
|
||||
mod->enc->data[mod->enc->program].eon[eon].pty = luaL_checkinteger(localL, 6);
|
||||
_strncpy(mod->enc->data[mod->enc->program].eon[eon].ps, luaL_checklstring(localL, 7, NULL), 8);
|
||||
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);
|
||||
|
||||
int n = lua_rawlen(localL, 8);
|
||||
if (n == 0) {
|
||||
memset(&(mod->enc->data[mod->enc->program].eon[eon].af), 0, sizeof(RDSAFs));
|
||||
memset(&(enc->data[enc->program].eon[eon].af), 0, sizeof(RDSAFs));
|
||||
return 0;
|
||||
}
|
||||
if(n > 25) return luaL_error(localL, "table length over 25");
|
||||
@@ -320,23 +307,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(&(mod->enc->data[mod->enc->program].eon[eon].af), &new_af, sizeof(new_af));
|
||||
memcpy(&(enc->data[enc->program].eon[eon].af), &new_af, sizeof(new_af));
|
||||
|
||||
mod->enc->data[mod->enc->program].eon[eon].data = luaL_checkinteger(localL, 9);
|
||||
enc->data[enc->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, mod->enc->data[mod->enc->program].eon[eon].enabled);
|
||||
lua_pushinteger(localL, mod->enc->data[mod->enc->program].eon[eon].pi);
|
||||
lua_pushboolean(localL, mod->enc->data[mod->enc->program].eon[eon].tp);
|
||||
lua_pushboolean(localL, mod->enc->data[mod->enc->program].eon[eon].ta);
|
||||
lua_pushinteger(localL, mod->enc->data[mod->enc->program].eon[eon].pty);
|
||||
lua_pushlstring(localL, mod->enc->data[mod->enc->program].eon[eon].ps, 8);
|
||||
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_createtable(localL, 0, 0); // don't have decoding for AF, so just return empty table
|
||||
lua_pushinteger(localL, mod->enc->data[mod->enc->program].eon[eon].data);
|
||||
lua_pushinteger(localL, enc->data[enc->program].eon[eon].data);
|
||||
return 8;
|
||||
}
|
||||
|
||||
@@ -366,11 +353,11 @@ int lua_set_rds_udg(lua_State *localL) {
|
||||
}
|
||||
|
||||
if(xy) {
|
||||
memcpy(&(mod->enc->data[mod->enc->program].udg2), blocks, n * sizeof(uint16_t[3]));
|
||||
mod->enc->data[mod->enc->program].udg2_len = n;
|
||||
memcpy(&(enc->data[enc->program].udg2), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[enc->program].udg2_len = n;
|
||||
} else {
|
||||
memcpy(&(mod->enc->data[mod->enc->program].udg1), blocks, n * sizeof(uint16_t[3]));
|
||||
mod->enc->data[mod->enc->program].udg1_len = n;
|
||||
memcpy(&(enc->data[enc->program].udg1), blocks, n * sizeof(uint16_t[3]));
|
||||
enc->data[enc->program].udg1_len = n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -402,21 +389,16 @@ int lua_set_rds_udg2(lua_State *localL) {
|
||||
}
|
||||
|
||||
if(xy) {
|
||||
memcpy(&(mod->enc->data[mod->enc->program].udg2_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
mod->enc->data[mod->enc->program].udg2_len_rds2 = n;
|
||||
memcpy(&(enc->data[enc->program].udg2_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[enc->program].udg2_len_rds2 = n;
|
||||
} else {
|
||||
memcpy(&(mod->enc->data[mod->enc->program].udg1_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
mod->enc->data[mod->enc->program].udg1_len_rds2 = n;
|
||||
memcpy(&(enc->data[enc->program].udg1_rds2), blocks, n * sizeof(uint16_t[4]));
|
||||
enc->data[enc->program].udg1_len_rds2 = n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_get_available_rds_streams(lua_State *localL) {
|
||||
lua_pushinteger(localL, mod->num_streams);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_crc16(lua_State *localL) {
|
||||
size_t len;
|
||||
const char* data = luaL_checklstring(localL, 1, &len);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <lauxlib.h>
|
||||
#include "rds.h"
|
||||
#include "fs.h"
|
||||
#include "modulator.h"
|
||||
|
||||
int lua_get_userdata(lua_State *localL);
|
||||
int lua_get_userdata_offset(lua_State *localL);
|
||||
@@ -56,7 +55,6 @@ int lua_get_rds2_mode(lua_State *localL);
|
||||
|
||||
int lua_set_rds_streams(lua_State *localL);
|
||||
int lua_get_rds_streams(lua_State *localL);
|
||||
int lua_get_available_rds_streams(lua_State *localL);
|
||||
|
||||
int lua_set_rds_grp_sqc(lua_State *localL);
|
||||
int lua_get_rds_grp_sqc(lua_State *localL);
|
||||
@@ -76,9 +74,6 @@ int lua_get_rds_rt_switching_period(lua_State *localL);
|
||||
int lua_set_rds_rt_text_timeout(lua_State *localL);
|
||||
int lua_get_rds_rt_text_timeout(lua_State *localL);
|
||||
|
||||
int lua_set_rds_level(lua_State *localL);
|
||||
int lua_get_rds_level(lua_State *localL);
|
||||
|
||||
int lua_put_rds_custom_group(lua_State *localL);
|
||||
int lua_put_rds2_custom_group(lua_State *localL);
|
||||
|
||||
|
||||
+4
-9
@@ -2,15 +2,15 @@
|
||||
#include <pthread.h>
|
||||
#include "lua_api.h"
|
||||
|
||||
RDSModulator* mod = NULL;
|
||||
RDSEncoder* enc = NULL;
|
||||
lua_State *L = NULL;
|
||||
static pthread_mutex_t lua_mutex;
|
||||
uint8_t unload_refs[33] = {LUA_REFNIL};
|
||||
|
||||
#define lua_registertotable(L,n,f) (lua_pushcfunction(L, (f)), lua_setfield(L, -2, (n)))
|
||||
void init_lua(RDSModulator* rds_mod) {
|
||||
void init_lua(RDSEncoder* _enc) {
|
||||
static int mutex_initialized = 0;
|
||||
mod = rds_mod;
|
||||
enc = _enc;
|
||||
L = luaL_newstate();
|
||||
printf("Initializing %s\n", LUA_COPYRIGHT);
|
||||
|
||||
@@ -141,14 +141,9 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
lua_registertotable(L, "set_udg", lua_set_rds_udg);
|
||||
lua_registertotable(L, "set_udg2", lua_set_rds_udg2);
|
||||
|
||||
lua_registertotable(L, "set_level", lua_set_rds_level);
|
||||
lua_registertotable(L, "get_level", lua_get_rds_level);
|
||||
|
||||
lua_registertotable(L, "set_streams", lua_set_rds_streams);
|
||||
lua_registertotable(L, "get_streams", lua_get_rds_streams);
|
||||
|
||||
lua_registertotable(L, "get_available_streams", lua_get_available_rds_streams);
|
||||
|
||||
lua_setglobal(L, "rds");
|
||||
|
||||
|
||||
@@ -381,6 +376,6 @@ void destroy_lua() {
|
||||
lua_close(L);
|
||||
L = NULL;
|
||||
}
|
||||
mod = NULL;
|
||||
enc = NULL;
|
||||
pthread_mutex_destroy(&lua_mutex);
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include "rds.h"
|
||||
#include "modulator.h"
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
void init_lua(RDSModulator* rds_mod);
|
||||
void init_lua(RDSEncoder* _enc);
|
||||
void run_lua(char *str, char *cmd_output, size_t* out_len);
|
||||
int lua_group(RDSGroup* group, const char grp);
|
||||
int lua_rds2_group(RDSGroup* group, int stream);
|
||||
|
||||
+1
-2
@@ -34,7 +34,6 @@ void cleanup_rds_modulator(RDSModulator* rdsMod) {
|
||||
|
||||
float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) {
|
||||
if(stream >= rdsMod->num_streams) return 0.0f;
|
||||
if((rdsMod->params.rdsgen > stream ? 1 : 0) == 0) return 0.0f;
|
||||
|
||||
rdsMod->data[stream].phase += 1187.5 / RDS_SAMPLE_RATE;
|
||||
|
||||
@@ -53,5 +52,5 @@ float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) {
|
||||
float sample = sinf(M_2PI * rdsMod->data[stream].phase + rdsMod->data[stream].symbol_shift);
|
||||
if(rdsMod->data[stream].cur_output == 0) sample = -sample; // do bpsk, if you comment this part out, nothing will be decoded
|
||||
|
||||
return sample*rdsMod->params.level;
|
||||
return sample;
|
||||
}
|
||||
@@ -3,19 +3,6 @@
|
||||
#include "lib.h"
|
||||
#include "rds.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float level;
|
||||
uint8_t rdsgen : 3;
|
||||
} RDSModulatorParameters;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t check;
|
||||
RDSModulatorParameters params;
|
||||
uint16_t crc;
|
||||
} RDSModulatorParametersFile;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bit_buffer[BITS_PER_GROUP];
|
||||
@@ -29,7 +16,6 @@ typedef struct
|
||||
|
||||
typedef struct {
|
||||
RDSModulatorModulationData *data;
|
||||
RDSModulatorParameters params;
|
||||
RDSEncoder* enc;
|
||||
uint8_t num_streams;
|
||||
} RDSModulator;
|
||||
|
||||
@@ -164,6 +164,7 @@ typedef struct {
|
||||
RDSData data[PROGRAMS];
|
||||
RDSState state[PROGRAMS];
|
||||
uint8_t program : 3;
|
||||
uint8_t enabled_streams : 3;
|
||||
} RDSEncoder;
|
||||
typedef struct {
|
||||
uint8_t file_starter; // Always is 225 first polish radio programme am frequency
|
||||
@@ -171,6 +172,7 @@ typedef struct {
|
||||
uint8_t file_middle; // Always is 160, average of both
|
||||
RDSEncoderData encoder_data;
|
||||
uint8_t program : 3;
|
||||
uint8_t enabled_streams : 3;
|
||||
uint8_t file_ender; // Always is 95 my freq
|
||||
uint16_t crc;
|
||||
} RDSEncoderFile;
|
||||
|
||||
+6
-4
@@ -203,7 +203,11 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
while(!stop_rds) {
|
||||
for (uint16_t i = 0; i < NUM_MPX_FRAMES * config.num_streams; i++) rds_buffer[i] = get_rds_sample(&rdsModulator, i % config.num_streams);
|
||||
for (uint16_t i = 0; i < NUM_MPX_FRAMES * config.num_streams; i++) {
|
||||
uint8_t stream = i % config.num_streams;
|
||||
if((rdsEncoder.enabled_streams > stream ? 1 : 0) == 0) rds_buffer[i] = 0.0f;
|
||||
rds_buffer[i] = get_rds_sample(&rdsModulator, stream);
|
||||
}
|
||||
|
||||
if (pa_simple_write(rds_device, rds_buffer, NUM_MPX_FRAMES * config.num_streams * sizeof(float), &pulse_error) != 0) {
|
||||
fprintf(stderr, "Error: could not play audio. (%s : %d)\n", pa_strerror(pulse_error), pulse_error);
|
||||
@@ -216,15 +220,13 @@ int main(int argc, char **argv) {
|
||||
RDSGroup group;
|
||||
char output_buffer[1024];
|
||||
char starts[4][5] = {"G:\r\n", "H:\r\n", "I:\r\n", "J:\r\n"};
|
||||
uint8_t num_processed = config.num_streams;
|
||||
if(rdsModulator.params.rdsgen < num_processed) num_processed = rdsModulator.params.rdsgen;
|
||||
|
||||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
|
||||
while(!stop_rds) {
|
||||
if (is_tcp_server_running()) accept_tcp_clients();
|
||||
|
||||
for(uint8_t i = 0; i < num_processed; i++) {
|
||||
for(uint8_t i = 0; i < config.num_streams; i++) {
|
||||
get_rds_group(&rdsEncoder, &group, i);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
Reference in New Issue
Block a user