encode_group

This commit is contained in:
2026-04-26 11:43:14 +02:00
parent ff6460ba0f
commit 33eb2c1c60
9 changed files with 67 additions and 28 deletions
+9
View File
@@ -95,6 +95,7 @@ hooks.ps_transmission = {}
function hooks.data_handle(data) end function hooks.data_handle(data) end
---This function is called an unknown group is seen in the group sequence. See set_grpseq ---This function is called an unknown group is seen in the group sequence. See set_grpseq
---This will be also called on recognized groups - if they can't be properly encoded by the core
---Please remember that the core always fills in PTY and TP and PI in C if this is an B group ---Please remember that the core always fills in PTY and TP and PI in C if this is an B group
---It should be defined by the user in the script. ---It should be defined by the user in the script.
---@param group string group this was called in from the group sequence ---@param group string group this was called in from the group sequence
@@ -118,6 +119,14 @@ function hooks.rds2_group(stream) end
rds = {} rds = {}
---Returns an encoded group by the core - groups that could not be encoded decay to PS
---@param group string One character, just one
---@return boolean generated Was this properly generated, or is the PS?
---@return integer b
---@return integer c
---@return integer d
function rds.encode_group(group) end
---@type integer ---@type integer
rds.eon_count = 0 rds.eon_count = 0
+2
View File
@@ -31,6 +31,8 @@ RDS95 is the only (as far as i can tell) encoder to transmit the 9-bit AF codes
Yet another unique feature, the Lua engine allows you to control the encoder, almost entirely. Yet another unique feature, the Lua engine allows you to control the encoder, almost entirely.
Every RDS2 subcarrier is in full control of Lua (except tunneling - core fills in PTY and the rest)
### RFT ### RFT
For a long time there was no RFT in RDS95, but on 28th December 2025 that changed when i implemented it in lua, just call the load function with the path and id 0, and see the your station's logo in the decoder For a long time there was no RFT in RDS95, but on 28th December 2025 that changed when i implemented it in lua, just call the load function with the path and id 0, and see the your station's logo in the decoder
+10
View File
@@ -243,6 +243,16 @@ mec_handlers[0x19] = function (data)
end) end)
return 2 return 2
end end
mec_handlers[0x16] = function (data)
-- Group sequence for stream 0
local dsn = string.byte(data, 2)
local mel = string.byte(data, 3)
local group_sequence = string.sub(data, 4, 3+mel)
dsn_helper(dsn, function ()
rds.set_grpseq(group_sequence)
end)
return 4 + mel
end
mec_handlers[0x23] = function (data) mec_handlers[0x23] = function (data)
-- Site address -- Site address
local control_bits = string.byte(data, 2) local control_bits = string.byte(data, 2)
-4
View File
@@ -77,7 +77,6 @@ function hooks.data_handle(data)
return string.format("ERTPRUN=%d\r\n", f1) return string.format("ERTPRUN=%d\r\n", f1)
elseif data == "lps" then return string.format("LPS=%s\r\n", rds.get_lps()) elseif data == "lps" then return string.format("LPS=%s\r\n", rds.get_lps())
elseif data == "ert" then return string.format("ERT=%s\r\n", rds.ext.get_ert()) elseif data == "ert" then return string.format("ERT=%s\r\n", rds.ext.get_ert())
elseif data == "grpseq" then return string.format("GRPSEQ=%s\r\n", rds.get_grpseq())
else else
local eon_cmd, eon_num = data:match("^eon(%d+)([a-z]+)$") local eon_cmd, eon_num = data:match("^eon(%d+)([a-z]+)$")
if eon_cmd then if eon_cmd then
@@ -251,9 +250,6 @@ function hooks.data_handle(data)
dp.set_writing_program(program-1) dp.set_writing_program(program-1)
rds.set_ta(false) rds.set_ta(false)
return "+\r\n" return "+\r\n"
elseif cmd == "grpseq" then
rds.set_grpseq(value)
return "+\r\n"
elseif cmd == "rtp" or cmd == "ertp" then elseif cmd == "rtp" or cmd == "ertp" then
local is_ertp = (cmd == "ertp") local is_ertp = (cmd == "ertp")
local t1, s1, l1, t2, s2, l2 = value:match("(%d+),(%d+),(%d+),(%d+),(%d+),(%d+)") local t1, s1, l1, t2, s2, l2 = value:match("(%d+),(%d+),(%d+),(%d+),(%d+),(%d+)")
+23
View File
@@ -386,3 +386,26 @@ int lua_convert_to_rdscharset(lua_State *localL) {
lua_pushstring(localL, output); lua_pushstring(localL, output);
return 1; return 1;
} }
int lua_encode_group(lua_State *localL) {
size_t len;
const char *grp = luaL_checklstring(localL, 1, &len);
if(len != 1) return luaL_error(localL, "expected a length of 1");
char PS_GROUP = 0;
RDSGroup group;
uint8_t good = check_rds_good_group(enc, grp);
if(good == 0) {
lua_pushboolean(localL, 0);
get_rds_sequence_group(enc, &group, 1, &PS_GROUP);
} else {
lua_pushboolean(localL, 1);
get_rds_sequence_group(enc, &group, 1, grp);
}
lua_pushinteger(localL, group.b);
lua_pushinteger(localL, group.c);
lua_pushinteger(localL, group.d);
return 4;
}
+1
View File
@@ -86,3 +86,4 @@ int lua_get_rds_eon(lua_State *localL);
int lua_crc16(lua_State *localL); int lua_crc16(lua_State *localL);
int lua_convert_to_rdscharset(lua_State *localL); int lua_convert_to_rdscharset(lua_State *localL);
int lua_encode_group(lua_State *localL);
+2
View File
@@ -144,6 +144,8 @@ void init_lua(RDSEncoder* _enc) {
lua_registertotable(L, "set_streams", lua_set_rds_streams); lua_registertotable(L, "set_streams", lua_set_rds_streams);
lua_registertotable(L, "get_streams", lua_get_rds_streams); lua_registertotable(L, "get_streams", lua_get_rds_streams);
lua_registertotable(L, "encode_group", lua_encode_group);
lua_setglobal(L, "rds"); lua_setglobal(L, "rds");
if (luaL_loadfile(L, "/etc/rds95.lua") != LUA_OK) { if (luaL_loadfile(L, "/etc/rds95.lua") != LUA_OK) {
+8 -14
View File
@@ -21,7 +21,12 @@ uint8_t get_rds_custom_groups(RDSEncoder* enc, RDSGroup *group);
uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group); uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group);
int get_rdsp_lua_group(RDSGroup *group, const char grp); int get_rdsp_lua_group(RDSGroup *group, const char grp);
static void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, char* grp) { void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, uint8_t good_group, char* grp) {
if(good_group == 0) {
if(get_rdsp_lua_group(group, *grp) == 0) get_rds_ps_group(enc, group);
return;
}
switch (*grp) { switch (*grp) {
case 0: case 0:
get_rds_ps_group(enc, group); get_rds_ps_group(enc, group);
@@ -52,7 +57,7 @@ static void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, char* grp)
} }
} }
static uint8_t check_rds_good_group(RDSEncoder* enc, char* grp) { uint8_t check_rds_good_group(RDSEncoder* enc, char* grp) {
if(*grp == 2) { if(*grp == 2) {
if(enc->data[enc->program].ecc != 0 || enc->data[enc->program].slc_data != 0) return 1; if(enc->data[enc->program].ecc != 0 || enc->data[enc->program].slc_data != 0) return 1;
return 0; return 0;
@@ -108,7 +113,6 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
} }
uint8_t good_group = 0; uint8_t good_group = 0;
uint8_t cant_find_group = 0;
uint8_t grp_sqc_idx = 0; uint8_t grp_sqc_idx = 0;
char grp; char grp;
@@ -129,7 +133,6 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
if(get_rds_custom_groups(enc, group)) goto group_coded; if(get_rds_custom_groups(enc, group)) goto group_coded;
while(good_group == 0) {
grp_sqc_idx = enc->state[enc->program].grp_seq_idx; grp_sqc_idx = enc->state[enc->program].grp_seq_idx;
if(grp_sqc_idx > enc->data[enc->program].grp_sqc_len) { if(grp_sqc_idx > enc->data[enc->program].grp_sqc_len) {
enc->state[enc->program].grp_seq_idx = 0; enc->state[enc->program].grp_seq_idx = 0;
@@ -139,18 +142,9 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
good_group = check_rds_good_group(enc, &grp); good_group = check_rds_good_group(enc, &grp);
if(!good_group) cant_find_group++;
else cant_find_group = 0;
if(!good_group && cant_find_group >= 23) {
cant_find_group = 0;
break;
}
enc->state[enc->program].grp_seq_idx++; enc->state[enc->program].grp_seq_idx++;
}
if(!good_group) grp = 0;
get_rds_sequence_group(enc, group, &grp); get_rds_sequence_group(enc, group, good_group, &grp);
group_coded_rds2: group_coded_rds2:
if (group->a == 0 && stream != 0) { if (group->a == 0 && stream != 0) {
+2
View File
@@ -158,6 +158,8 @@ void reset_rds_state(RDSEncoder* enc, uint8_t program);
void set_rds_defaults(RDSEncoder* enc, uint8_t program); void set_rds_defaults(RDSEncoder* enc, uint8_t program);
void init_rds_encoder(RDSEncoder* enc); void init_rds_encoder(RDSEncoder* enc);
void add_checkwords(RDSGroup *group, uint8_t *bits); void add_checkwords(RDSGroup *group, uint8_t *bits);
uint8_t check_rds_good_group(RDSEncoder* enc, char* grp);
void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, uint8_t good_group, char* grp);
void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream); void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream);
void get_rds_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream); void get_rds_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream);