mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
eon
This commit is contained in:
@@ -78,96 +78,8 @@ static void handle_udg2(char *arg, char *pattern, RDSModulator* mod, char* outpu
|
||||
else 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, "+");
|
||||
}
|
||||
|
||||
static void handle_eonpi(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].pi = strtoul(arg, NULL, 16);
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eonps(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
arg[PS_LENGTH * 2] = 0;
|
||||
|
||||
RDSEON *eon = &mod->enc->data[mod->enc->program].eon[atoi(pattern)-1];
|
||||
memset(eon->ps, ' ', sizeof(eon->ps));
|
||||
|
||||
uint16_t len = 0;
|
||||
while (*arg != 0 && len < 24) eon->ps[len++] = *arg++;
|
||||
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eonpty(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].pty = atoi(arg);
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eonta(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
if (!mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].enabled ||
|
||||
!mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].tp) {
|
||||
strcpy(output, "-");
|
||||
return;
|
||||
}
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].ta = atoi(arg);
|
||||
if(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].ta) mod->enc->data[mod->enc->program].ta = 1;
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eontp(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].tp = atoi(arg);
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eonaf(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
if (arg[0] == 0) {
|
||||
memset(&(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af), 0, sizeof(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af));
|
||||
strcpy(output, "+");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af), 0, sizeof(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af));
|
||||
uint8_t arg_count;
|
||||
RDSAFs new_af;
|
||||
float af[MAX_AFS], *af_iter;
|
||||
|
||||
arg_count = sscanf(arg,
|
||||
"%f,%f,%f,%f,%f,"
|
||||
"%f,%f,%f,%f,%f,"
|
||||
"%f,%f,%f,%f,%f,"
|
||||
"%f,%f,%f,%f,%f,"
|
||||
"%f,%f,%f,%f,%f",
|
||||
&af[0], &af[1], &af[2], &af[3], &af[4],
|
||||
&af[5], &af[6], &af[7], &af[8], &af[9],
|
||||
&af[10], &af[11], &af[12], &af[13], &af[14],
|
||||
&af[15], &af[16], &af[17], &af[18], &af[19],
|
||||
&af[20], &af[21], &af[22], &af[23], &af[24]);
|
||||
|
||||
af_iter = af;
|
||||
memset(&new_af, 0, sizeof(RDSAFs));
|
||||
|
||||
while (arg_count-- != 0) add_rds_af(&new_af, *af_iter++);
|
||||
|
||||
memcpy(&(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af), &new_af, sizeof(mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].af));
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static void handle_eondt(char *arg, char *pattern, RDSModulator* mod, char* output) {
|
||||
mod->enc->data[mod->enc->program].eon[atoi(pattern)-1].data = strtoul(arg, NULL, 16);
|
||||
strcpy(output, "+");
|
||||
}
|
||||
|
||||
static const pattern_command_handler_t pattern_commands[] = {
|
||||
{"EON", "EN", handle_eonen},
|
||||
{"EON", "PI", handle_eonpi},
|
||||
{"EON", "PS", handle_eonps},
|
||||
{"EON", "PTY", handle_eonpty},
|
||||
{"EON", "TA", handle_eonta},
|
||||
{"EON", "TP", handle_eontp},
|
||||
{"EON", "AF", handle_eonaf},
|
||||
{"EON", "DT", handle_eondt},
|
||||
{"UDG", "", handle_udg},
|
||||
{"2UDG", "", handle_udg2},
|
||||
};
|
||||
|
||||
118
src/command.lua
118
src/command.lua
@@ -47,6 +47,35 @@ if type(data) == "string" and data ~= nil then
|
||||
else return "?" end
|
||||
-- TODO: more
|
||||
end
|
||||
local eon_cmd, eon_num = data:match("^eon(%d+)([a-z]+)$")
|
||||
if eon_cmd then
|
||||
local eon_idx = tonumber(eon_cmd)
|
||||
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then
|
||||
return "?"
|
||||
end
|
||||
|
||||
eon_idx = eon_idx - 1
|
||||
|
||||
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
||||
|
||||
if eon_num == "en" then
|
||||
return string.format("EON%dEN=%d\r\n", eon_idx + 1, enabled and 1 or 0)
|
||||
elseif eon_num == "pi" then
|
||||
return string.format("EON%dPI=%x\r\n", eon_idx + 1, pi)
|
||||
elseif eon_num == "ps" then
|
||||
return string.format("EON%dPS=%s\r\n", eon_idx + 1, ps)
|
||||
elseif eon_num == "pty" then
|
||||
return string.format("EON%dPTY=%d\r\n", eon_idx + 1, pty)
|
||||
elseif eon_num == "ta" then
|
||||
return string.format("EON%dTA=%d\r\n", eon_idx + 1, ta and 1 or 0)
|
||||
elseif eon_num == "tp" then
|
||||
return string.format("EON%dTP=%d\r\n", eon_idx + 1, tp and 1 or 0)
|
||||
elseif eon_num == "dt" then
|
||||
return string.format("EON%dDT=%x\r\n", eon_idx + 1, data_val)
|
||||
else
|
||||
return "?"
|
||||
end
|
||||
end
|
||||
cmd = cmd:lower()
|
||||
if cmd == "pi" then
|
||||
local pi = tonumber(value, 16)
|
||||
@@ -248,6 +277,93 @@ if type(data) == "string" and data ~= nil then
|
||||
set_rds_af_oda(af_table)
|
||||
return "+"
|
||||
else
|
||||
return "?"
|
||||
local eon_set_cmd, eon_set_num, eon_set_type = cmd:match("^eon(%d+)([a-z]+)$")
|
||||
if eon_set_cmd then
|
||||
local eon_idx = tonumber(eon_set_cmd)
|
||||
if not eon_idx or eon_idx < 1 or eon_idx > eon_count then
|
||||
return "?"
|
||||
end
|
||||
|
||||
eon_idx = eon_idx - 1
|
||||
|
||||
local enabled, pi, tp, ta, pty, ps, afs, data_val = get_rds_eon(eon_idx)
|
||||
|
||||
if eon_set_type == "en" then
|
||||
local en_val = tonumber(value)
|
||||
if not en_val then return "-" end
|
||||
enabled = (en_val ~= 0)
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "pi" then
|
||||
local pi_val = tonumber(value, 16)
|
||||
if not pi_val then return "-" end
|
||||
set_rds_eon(eon_idx, enabled, pi_val, tp, ta, pty, ps, afs, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "ps" then
|
||||
local ps_val = value:sub(1, 24)
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps_val, afs, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "pty" then
|
||||
local pty_val = tonumber(value)
|
||||
if not pty_val then return "-" end
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty_val, ps, afs, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "ta" then
|
||||
if not enabled or not tp then
|
||||
return "-"
|
||||
end
|
||||
local ta_val = tonumber(value)
|
||||
if not ta_val then return "-" end
|
||||
ta = (ta_val ~= 0)
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||
if ta then
|
||||
set_rds_ta(true)
|
||||
end
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "tp" then
|
||||
local tp_val = tonumber(value)
|
||||
if not tp_val then return "-" end
|
||||
tp = (tp_val ~= 0)
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "af" then
|
||||
local af_table = {}
|
||||
|
||||
if value == "" or value == "0" then
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, {}, data_val)
|
||||
return "+"
|
||||
end
|
||||
|
||||
for freq_str in value:gmatch("([^,]+)") do
|
||||
local f = tonumber(freq_str)
|
||||
if f then
|
||||
table.insert(af_table, f)
|
||||
else
|
||||
return "-"
|
||||
end
|
||||
end
|
||||
|
||||
if #af_table > 25 then return "-" end
|
||||
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, af_table, data_val)
|
||||
return "+"
|
||||
|
||||
elseif eon_set_type == "dt" then
|
||||
local dt_val = tonumber(value, 16)
|
||||
if not dt_val then return "-" end
|
||||
set_rds_eon(eon_idx, enabled, pi, tp, ta, pty, ps, afs, dt_val)
|
||||
return "+"
|
||||
else
|
||||
return "?"
|
||||
end
|
||||
else
|
||||
return "?"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user