mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-27 04:43:52 +01:00
fix tps and dps logic fix dps1enq, adjust data structure and add reset
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"port": 13452,
|
||||
"time": 1742235713567,
|
||||
"time": 1742301947694,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
@@ -64,12 +64,14 @@ static void handle_tps(char *arg, RDSModulator* mod, char* output) {
|
||||
static void handle_rt1(char *arg, RDSModulator* mod, char* output) {
|
||||
arg[RT_LENGTH * 2] = 0;
|
||||
set_rds_rt1(mod->enc, xlat(arg));
|
||||
if(mod->enc->data[mod->enc->program].eqtext1) set_rds_dps1(mod->enc, xlat(arg));
|
||||
strcpy(output, "+\0");
|
||||
}
|
||||
|
||||
static void handle_dps1(char *arg, RDSModulator* mod, char* output) {
|
||||
arg[DPS_LENGTH * 2] = 0;
|
||||
set_rds_dps1(mod->enc, xlat(arg));
|
||||
if(mod->enc->data[mod->enc->program].eqtext1) set_rds_rt1(mod->enc, xlat(arg));
|
||||
strcpy(output, "+\0");
|
||||
}
|
||||
static void handle_dps1mod(char *arg, RDSModulator* mod, char* output) {
|
||||
@@ -300,11 +302,9 @@ static void handle_program(char *arg, RDSModulator* mod, char* output) {
|
||||
|
||||
static void handle_grpseq(char *arg, RDSModulator* mod, char* output) {
|
||||
if (arg[0] == '\0') {
|
||||
memset(&(mod->enc->data[mod->enc->program].grp_sqc), 0, 24);
|
||||
memcpy(&(mod->enc->data[mod->enc->program].grp_sqc), (char*)DEFAULT_GRPSQC, sizeof(DEFAULT_GRPSQC));
|
||||
set_rds_grpseq(mod->enc, DEFAULT_GRPSQC);
|
||||
} else {
|
||||
memset(&(mod->enc->data[mod->enc->program].grp_sqc), 0, 24);
|
||||
memcpy(&(mod->enc->data[mod->enc->program].grp_sqc), arg, 24);
|
||||
set_rds_grpseq(mod->enc, arg);
|
||||
}
|
||||
strcpy(output, "+\0");
|
||||
}
|
||||
@@ -314,6 +314,15 @@ static void handle_level(char *arg, RDSModulator* mod, char* output) {
|
||||
strcpy(output, "+\0");
|
||||
}
|
||||
|
||||
static void handle_reset(char *arg, RDSModulator* mod, char* output) {
|
||||
loadFromFile(mod->enc);
|
||||
for(int i = 0; i < PROGRAMS; i++) {
|
||||
reset_rds_state(mod->enc, i);
|
||||
}
|
||||
Modulator_loadFromFile(mod->params);
|
||||
strcpy(output, "\0");
|
||||
}
|
||||
|
||||
static void handle_rdsgen(char *arg, RDSModulator* mod, char* output) {
|
||||
mod->params.rdsgen = strtoul((char *)arg, NULL, 10);
|
||||
strcpy(output, "+\0");
|
||||
@@ -436,7 +445,8 @@ static const command_handler_t commands_eq6[] = {
|
||||
{"PINEN", handle_pinen, 5},
|
||||
{"RT1EN", handle_rt1en, 5},
|
||||
{"ECCEN", handle_eccen, 5},
|
||||
{"LEVEL", handle_level, 5}
|
||||
{"LEVEL", handle_level, 5},
|
||||
{"RESET", handle_reset, 5},
|
||||
};
|
||||
|
||||
static const command_handler_t commands_eq7[] = {
|
||||
|
||||
151
src/rds.c
151
src/rds.c
@@ -53,7 +53,6 @@ void saveToFile(RDSEncoder *emp, const char *option) {
|
||||
} else if (strcmp(option, "DPS1") == 0) {
|
||||
memcpy(tempEncoder.data[emp->program].dps1, emp->data[emp->program].dps1, DPS_LENGTH);
|
||||
tempEncoder.data[emp->program].dps1_enabled = emp->data[emp->program].dps1_enabled;
|
||||
tempEncoder.data[emp->program].dps1_len = emp->data[emp->program].dps1_len;
|
||||
tempEncoder.data[emp->program].dps1_numberofrepeats = emp->data[emp->program].dps1_numberofrepeats;
|
||||
tempEncoder.data[emp->program].dps1_numberofrepeats_clear = emp->data[emp->program].dps1_numberofrepeats_clear;
|
||||
} else if (strcmp(option, "DPS1EN") == 0) {
|
||||
@@ -208,7 +207,7 @@ static uint16_t get_next_af(RDSEncoder* enc) {
|
||||
|
||||
// #region Group encoding
|
||||
static void get_rds_ps_group(RDSEncoder* enc, uint16_t *blocks) {
|
||||
uint8_t dps1_on = (enc->data[enc->program].dps1_enabled && enc->data[enc->program].dps1_len != 0);
|
||||
uint8_t dps1_on = (enc->data[enc->program].dps1_enabled && enc->state[enc->program].dps1_len != 0);
|
||||
get_ps:
|
||||
if(enc->state[enc->program].ps_csegment == 0) {
|
||||
if(enc->state[enc->program].ps_update && !dps1_on) {
|
||||
@@ -216,7 +215,7 @@ get_ps:
|
||||
enc->state[enc->program].ps_update = 0;
|
||||
}
|
||||
|
||||
if(enc->state[enc->program].tps_update) {
|
||||
if(enc->state[enc->program].tps_update && !dps1_on) {
|
||||
memcpy(enc->state[enc->program].tps_text, enc->data[enc->program].tps, PS_LENGTH);
|
||||
enc->state[enc->program].tps_update = 0;
|
||||
}
|
||||
@@ -228,8 +227,11 @@ get_ps:
|
||||
}
|
||||
|
||||
if(dps1_on) {
|
||||
char ps_text[PS_LENGTH];
|
||||
strncpy(ps_text, (enc->data[enc->program].ta) ? enc->data[enc->program].tps : enc->data[enc->program].ps, PS_LENGTH);
|
||||
|
||||
if(enc->state[enc->program].dynamic_ps_state == 0) {
|
||||
memcpy(enc->state[enc->program].ps_text, enc->data[enc->program].ps, PS_LENGTH);
|
||||
memcpy(enc->state[enc->program].ps_text, ps_text, PS_LENGTH);
|
||||
|
||||
if(enc->state[enc->program].static_ps_period >= enc->data[enc->program].static_ps_period) {
|
||||
enc->state[enc->program].dynamic_ps_state = 1;
|
||||
@@ -237,101 +239,50 @@ get_ps:
|
||||
enc->state[enc->program].dynamic_ps_position = 0;
|
||||
}
|
||||
} else if(enc->state[enc->program].dynamic_ps_state == 1) {
|
||||
if(enc->data[enc->program].dps1_len > PS_LENGTH) {
|
||||
uint8_t scroll_threshold = (enc->data[enc->program].dps_speed == 0) ? 4 : 2;
|
||||
uint8_t scroll_threshold = (enc->data[enc->program].dps_speed == 0) ? 4 : 2;
|
||||
if(enc->data[enc->program].dps1_mode == 0) scroll_threshold = enc->data[enc->program].dps_label_period;
|
||||
|
||||
if(enc->state[enc->program].dynamic_ps_scroll_counter >= scroll_threshold) {
|
||||
if(enc->state[enc->program].dynamic_ps_position >= enc->data[enc->program].dps1_len) {
|
||||
enc->state[enc->program].dynamic_ps_position = 0;
|
||||
enc->state[enc->program].dps1_repeat_count++;
|
||||
if(enc->state[enc->program].dynamic_ps_scroll_counter >= scroll_threshold) {
|
||||
if(enc->state[enc->program].dynamic_ps_position >= enc->state[enc->program].dps1_len) {
|
||||
enc->state[enc->program].dynamic_ps_position = 0;
|
||||
enc->state[enc->program].dps1_repeat_count++;
|
||||
|
||||
if(enc->state[enc->program].dps1_repeat_count >= enc->data[enc->program].dps1_numberofrepeats) {
|
||||
if(enc->state[enc->program].dps1_nexttext_len != 0 && enc->data[enc->program].dps1_len < 128 && enc->state[enc->program].dps1_nexttext_update) {
|
||||
enc->state[enc->program].dps1_nexttext_update = 0;
|
||||
|
||||
enc->state[enc->program].dynamic_ps_state = 2; // DPS1 nexttext
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
enc->state[enc->program].dps1_repeat_count = 0;
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
enc->state[enc->program].static_ps_period = 0;
|
||||
goto get_ps;
|
||||
} else {
|
||||
enc->state[enc->program].dynamic_ps_state = 0;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
enc->state[enc->program].dps1_repeat_count = 0;
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
enc->state[enc->program].static_ps_period = 0;
|
||||
memcpy(enc->state[enc->program].ps_text, enc->data[enc->program].ps, PS_LENGTH);
|
||||
goto encode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(enc->data[enc->program].dps1_mode) {
|
||||
case 0:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_text[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position += PS_LENGTH;
|
||||
break;
|
||||
case 1:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_text[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position++;
|
||||
break;
|
||||
}
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
} else {
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter++;
|
||||
}
|
||||
} else {
|
||||
memcpy(enc->state[enc->program].ps_text, enc->state[enc->program].dps1_text, PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_period++;
|
||||
|
||||
if(enc->state[enc->program].dynamic_ps_period >= enc->data[enc->program].dps_label_period) {
|
||||
enc->state[enc->program].dynamic_ps_state = 0;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
}
|
||||
}
|
||||
} else if(enc->state[enc->program].dynamic_ps_state == 2) {
|
||||
if(enc->data[enc->program].dps1_len > PS_LENGTH) {
|
||||
uint8_t scroll_threshold = (enc->data[enc->program].dps_speed == 0) ? 4 : 2;
|
||||
|
||||
if(enc->state[enc->program].dynamic_ps_scroll_counter >= scroll_threshold) {
|
||||
if(enc->state[enc->program].dynamic_ps_position >= enc->state[enc->program].dps1_nexttext_len) {
|
||||
enc->state[enc->program].dynamic_ps_position = 0;
|
||||
enc->state[enc->program].dps1_repeat_count++;
|
||||
|
||||
if(enc->state[enc->program].dps1_repeat_count >= enc->data[enc->program].dps1_numberofrepeats) {
|
||||
if(enc->state[enc->program].dps1_repeat_count >= enc->data[enc->program].dps1_numberofrepeats) {
|
||||
if(enc->state[enc->program].dps1_nexttext_len != 0 && enc->state[enc->program].dps1_len < 128 && enc->state[enc->program].dps1_nexttext_update) {
|
||||
enc->state[enc->program].dps1_nexttext_update = 0;
|
||||
enc->state[enc->program].dynamic_ps_state = 1;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
enc->state[enc->program].dps1_repeat_count = 0;
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
enc->state[enc->program].static_ps_period = 0;
|
||||
memcpy(enc->state[enc->program].dps1_text, enc->state[enc->program].dps1_nexttext, PS_LENGTH);
|
||||
enc->state[enc->program].dps1_len = enc->state[enc->program].dps1_nexttext_len;
|
||||
goto get_ps;
|
||||
} else {
|
||||
enc->state[enc->program].dynamic_ps_state = 0;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
enc->state[enc->program].dps1_repeat_count = 0;
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
enc->state[enc->program].static_ps_period = 0;
|
||||
memcpy(enc->state[enc->program].ps_text, enc->data[enc->program].ps, PS_LENGTH);
|
||||
memcpy(enc->state[enc->program].ps_text, ps_text, PS_LENGTH);
|
||||
goto encode;
|
||||
}
|
||||
}
|
||||
|
||||
switch(enc->data[enc->program].dps1_mode) {
|
||||
case 0:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_nexttext[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position += PS_LENGTH;
|
||||
break;
|
||||
case 1:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_nexttext[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position++;
|
||||
break;
|
||||
}
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
} else {
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter++;
|
||||
}
|
||||
|
||||
switch(enc->data[enc->program].dps1_mode) {
|
||||
case 0:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_text[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position += PS_LENGTH;
|
||||
break;
|
||||
case 1:
|
||||
memcpy(enc->state[enc->program].ps_text, &(enc->state[enc->program].dps1_text[enc->state[enc->program].dynamic_ps_position]), PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_position++;
|
||||
break;
|
||||
}
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter = 0;
|
||||
} else {
|
||||
memcpy(enc->state[enc->program].ps_text, enc->state[enc->program].dps1_nexttext, PS_LENGTH);
|
||||
enc->state[enc->program].dynamic_ps_period++;
|
||||
|
||||
if(enc->state[enc->program].dynamic_ps_period >= enc->data[enc->program].dps_label_period) {
|
||||
enc->state[enc->program].dynamic_ps_state = 0;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
}
|
||||
enc->state[enc->program].dynamic_ps_scroll_counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -662,6 +613,13 @@ void reset_rds_state(RDSEncoder* enc, uint8_t program) {
|
||||
set_rds_tps(&tempCoder, enc->data[program].tps);
|
||||
set_rds_ptyn(&tempCoder, enc->data[program].ptyn);
|
||||
set_rds_lps(&tempCoder, enc->data[program].lps);
|
||||
set_rds_grpseq(&tempCoder, enc->data[program].grp_sqc);
|
||||
|
||||
|
||||
struct tm *utc, *local_time;
|
||||
time(local_time);
|
||||
utc = gmtime(local_time);
|
||||
enc->state[enc->program].last_ct_minute = utc->tm_min;
|
||||
|
||||
memcpy(&(enc->state[program]), &(tempCoder.state[program]), sizeof(RDSState));
|
||||
}
|
||||
@@ -695,6 +653,9 @@ void set_rds_defaults(RDSEncoder* enc, uint8_t program) {
|
||||
reset_rds_state(enc, program);
|
||||
|
||||
init_rtplus(enc, GROUP_11A, program);
|
||||
|
||||
enc->encoder_data->ascii_data.expected_encoder_addr = 255;
|
||||
enc->encoder_data->ascii_data.expected_site_addr = 255;
|
||||
}
|
||||
|
||||
void init_rds_encoder(RDSEncoder* enc) {
|
||||
@@ -748,7 +709,7 @@ void set_rds_dps1(RDSEncoder* enc, char *dps1) {
|
||||
enc->state[enc->program].dps1_update = 1;
|
||||
memset(enc->data[enc->program].dps1, ' ', DPS_LENGTH);
|
||||
while (*dps1 != 0 && len < DPS_LENGTH) enc->data[enc->program].dps1[len++] = *dps1++;
|
||||
enc->data[enc->program].dps1_len = len;
|
||||
enc->state[enc->program].dps1_len = len;
|
||||
|
||||
enc->state[enc->program].dynamic_ps_position = 0;
|
||||
enc->state[enc->program].dynamic_ps_period = 0;
|
||||
@@ -833,4 +794,18 @@ void set_rds_ptyn(RDSEncoder* enc, char *ptyn) {
|
||||
|
||||
memset(enc->data[enc->program].ptyn, ' ', PTYN_LENGTH);
|
||||
while (*ptyn != 0 && len < PTYN_LENGTH) enc->data[enc->program].ptyn[len++] = *ptyn++;
|
||||
}
|
||||
|
||||
void set_rds_grpseq(RDSEncoder* enc, char *grpseq) {
|
||||
uint8_t len = 0;
|
||||
|
||||
if(grpseq[0] == '\0') {
|
||||
while (DEFAULT_GRPSQC[len] != 0 && len < 24) {
|
||||
enc->data[enc->program].grp_sqc[len++] = DEFAULT_GRPSQC[len];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
memset(enc->data[enc->program].grp_sqc, 0, 24);
|
||||
while (*grpseq != 0 && len < 24) enc->data[enc->program].grp_sqc[len++] = *grpseq++;
|
||||
}
|
||||
24
src/rds.h
24
src/rds.h
@@ -96,9 +96,7 @@ typedef struct {
|
||||
uint8_t eqtext1 : 1;
|
||||
uint8_t dps1_enabled : 1;
|
||||
uint8_t dps2_enabled : 1;
|
||||
uint8_t dps1_len;
|
||||
char dps1[DPS_LENGTH];
|
||||
uint8_t dps2_len;
|
||||
char dps2[DPS_LENGTH];
|
||||
uint8_t dps1_mode : 2;
|
||||
uint8_t dps2_mode : 2;
|
||||
@@ -155,6 +153,8 @@ typedef struct {
|
||||
|
||||
uint8_t dps1_update : 1;
|
||||
uint8_t dps2_update : 1;
|
||||
uint8_t dps1_len;
|
||||
uint8_t dps2_len;
|
||||
uint8_t dps1_nexttext_update : 1;
|
||||
uint8_t dps1_nexttext_len;
|
||||
char dps1_text[DPS_LENGTH];
|
||||
@@ -191,6 +191,8 @@ typedef struct {
|
||||
uint8_t udg_idxs[2];
|
||||
|
||||
uint8_t last_ct_minute : 6;
|
||||
|
||||
uint8_t eon_index : 3;
|
||||
} RDSState;
|
||||
typedef struct {
|
||||
uint8_t group;
|
||||
@@ -210,12 +212,21 @@ typedef struct {
|
||||
uint8_t start[2];
|
||||
uint8_t len[2];
|
||||
} RDSRTPlusData;
|
||||
typedef struct {
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t expected_encoder_addr;
|
||||
uint16_t expected_site_addr : 10;
|
||||
} RDSEncoderASCIIData;
|
||||
typedef struct
|
||||
{
|
||||
uint8_t uecp_enabled : 1;
|
||||
} RDSEncoderUECPData;
|
||||
typedef struct {
|
||||
uint8_t encoder_addr[2];
|
||||
uint16_t site_addr[2];
|
||||
uint8_t selected_encoder_addr;
|
||||
uint16_t selected_site_addr : 10;
|
||||
RDSEncoderASCIIData ascii_data;
|
||||
RDSEncoderUECPData uecp_data;
|
||||
} RDSEncoderData;
|
||||
typedef struct {
|
||||
RDSEncoderData encoder_data[PROGRAMS];
|
||||
@@ -226,7 +237,6 @@ typedef struct {
|
||||
RDSRTPlusData rtpData[PROGRAMS];
|
||||
uint8_t program : 3;
|
||||
} RDSEncoder;
|
||||
|
||||
typedef struct {
|
||||
uint8_t file_starter; // Always is 225 first polish radio programme am frequency
|
||||
RDSData data[PROGRAMS];
|
||||
@@ -303,6 +313,7 @@ void saveToFile(RDSEncoder *emp, const char *option);
|
||||
void loadFromFile(RDSEncoder *emp);
|
||||
int rdssaved();
|
||||
|
||||
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 get_rds_bits(RDSEncoder* enc, uint8_t *bits);
|
||||
@@ -315,5 +326,6 @@ void set_rds_lps(RDSEncoder* enc, char *lps);
|
||||
void set_rds_rtplus_flags(RDSEncoder* enc, uint8_t flags);
|
||||
void set_rds_rtplus_tags(RDSEncoder* enc, uint8_t *tags);
|
||||
void set_rds_ptyn(RDSEncoder* enc, char *ptyn);
|
||||
void set_rds_grpseq(RDSEncoder* enc, char *grpseq);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user