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
+23
View File
@@ -385,4 +385,27 @@ int lua_convert_to_rdscharset(lua_State *localL) {
lua_pushstring(localL, output);
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;
}
+2 -1
View File
@@ -85,4 +85,5 @@ int lua_get_rds_eon(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, "get_streams", lua_get_rds_streams);
lua_registertotable(L, "encode_group", lua_encode_group);
lua_setglobal(L, "rds");
if (luaL_loadfile(L, "/etc/rds95.lua") != LUA_OK) {
+17 -23
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);
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) {
case 0:
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(enc->data[enc->program].ecc != 0 || enc->data[enc->program].slc_data != 0) return 1;
return 0;
@@ -108,7 +113,6 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
}
uint8_t good_group = 0;
uint8_t cant_find_group = 0;
uint8_t grp_sqc_idx = 0;
char grp;
@@ -129,28 +133,18 @@ void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
if(get_rds_custom_groups(enc, group)) goto group_coded;
while(good_group == 0) {
grp_sqc_idx = enc->state[enc->program].grp_seq_idx;
if(grp_sqc_idx > enc->data[enc->program].grp_sqc_len) {
enc->state[enc->program].grp_seq_idx = 0;
grp_sqc_idx = 0;
}
grp = enc->data[enc->program].grp_sqc[grp_sqc_idx];
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++;
grp_sqc_idx = enc->state[enc->program].grp_seq_idx;
if(grp_sqc_idx > enc->data[enc->program].grp_sqc_len) {
enc->state[enc->program].grp_seq_idx = 0;
grp_sqc_idx = 0;
}
if(!good_group) grp = 0;
grp = enc->data[enc->program].grp_sqc[grp_sqc_idx];
get_rds_sequence_group(enc, group, &grp);
good_group = check_rds_good_group(enc, &grp);
enc->state[enc->program].grp_seq_idx++;
get_rds_sequence_group(enc, group, good_group, &grp);
group_coded_rds2:
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 init_rds_encoder(RDSEncoder* enc);
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_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream);