mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
remove control pipe
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": 1752839530190,
|
||||
"time": 1758535081582,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "control_pipe.h"
|
||||
|
||||
static int fd;
|
||||
static struct pollfd poller;
|
||||
|
||||
int open_control_pipe(char *filename) {
|
||||
fd = open(filename, O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1) return -1;
|
||||
|
||||
poller.fd = fd;
|
||||
poller.events = POLLIN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void poll_control_pipe(RDSModulator* mod) {
|
||||
static char pipe_buf[CTL_BUFFER_SIZE];
|
||||
static char cmd_buf[CMD_BUFFER_SIZE];
|
||||
int bytes_read;
|
||||
char *token;
|
||||
|
||||
if (poll(&poller, 1, READ_TIMEOUT_MS) <= 0) return;
|
||||
if (!(poller.revents & POLLIN)) return;
|
||||
|
||||
memset(pipe_buf, 0, CTL_BUFFER_SIZE);
|
||||
bytes_read = read(fd, pipe_buf, CTL_BUFFER_SIZE - 1);
|
||||
|
||||
if (bytes_read <= 0) return;
|
||||
|
||||
token = strtok((char *)pipe_buf, "\r\n");
|
||||
if(token == NULL) token = strtok((char *)pipe_buf, "\r");
|
||||
while (token != NULL) {
|
||||
size_t cmd_len = strlen(token);
|
||||
if (cmd_len > 0 && cmd_len < CMD_BUFFER_SIZE) {
|
||||
memset(cmd_buf, 0, CMD_BUFFER_SIZE);
|
||||
strncpy((char *)cmd_buf, token, CMD_BUFFER_SIZE - 1);
|
||||
process_ascii_cmd(mod, cmd_buf, NULL);
|
||||
}
|
||||
token = strtok(NULL, "\r\n");
|
||||
if(token == NULL) token = strtok(NULL, "\r");
|
||||
}
|
||||
}
|
||||
|
||||
void close_control_pipe() {
|
||||
if (fd > 0) close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/select.h>
|
||||
#include "common.h"
|
||||
#include "ascii_cmd.h"
|
||||
#include "rds.h"
|
||||
#include "modulator.h"
|
||||
|
||||
int open_control_pipe(char *filename);
|
||||
void close_control_pipe();
|
||||
void poll_control_pipe(RDSModulator* mod);
|
||||
@@ -25,12 +25,7 @@ void saveToFile(RDSEncoder *enc, const char *option) {
|
||||
} else return;
|
||||
tempEncoder.program = enc->program;
|
||||
|
||||
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};
|
||||
memcpy(&rdsEncoderfile.data[enc->program], &tempEncoder.data[enc->program], sizeof(RDSData));
|
||||
memcpy(&rdsEncoderfile.rtpData[enc->program], &tempEncoder.rtpData[enc->program], sizeof(RDSRTPlusData) * 2);
|
||||
memcpy(&rdsEncoderfile.encoder_data, &tempEncoder.encoder_data, sizeof(RDSEncoderData));
|
||||
@@ -252,7 +247,7 @@ static void get_rds_oda_af_group(RDSEncoder* enc, RDSGroup *group) {
|
||||
get_next_af_oda(enc, af);
|
||||
|
||||
group->b |= 7 << 12;
|
||||
for (int i = 0; i < 4; i++) group->b |= ((af[i] >> 8) & 1) << i;
|
||||
for (int i = 0; i < 4; i++) group->b |= ((af[i] >> 8) & 1) << i; // set the additional bits
|
||||
|
||||
group->c = af[0] & 0xFF;
|
||||
group->c <<= 8;
|
||||
|
||||
40
src/rds95.c
40
src/rds95.c
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "rds.h"
|
||||
#include "modulator.h"
|
||||
#include "control_pipe.h"
|
||||
#include "udp_server.h"
|
||||
#include "lib.h"
|
||||
#include "ascii_cmd.h"
|
||||
@@ -26,17 +25,6 @@ static void stop() {
|
||||
stop_rds = 1;
|
||||
}
|
||||
|
||||
static void *control_pipe_worker(void* modulator) {
|
||||
RDSModulator *mod = (RDSModulator*)modulator;
|
||||
while (!stop_rds) {
|
||||
poll_control_pipe(mod);
|
||||
msleep(READ_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
close_control_pipe();
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static void *udp_server_worker() {
|
||||
while (!stop_rds) {
|
||||
poll_udp_server();
|
||||
@@ -61,7 +49,6 @@ static inline void show_help(char *name) {
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char control_pipe[51];
|
||||
uint16_t udp_port;
|
||||
char rds_device_name[48];
|
||||
uint8_t num_streams;
|
||||
@@ -72,10 +59,7 @@ static int config_handler(void* user, const char* section, const char* name, con
|
||||
|
||||
#define MATCH(s, n) (strcmp(section, s) == 0 && strcmp(name, n) == 0)
|
||||
|
||||
if (MATCH("rds95", "control_pipe")) {
|
||||
strncpy(config->control_pipe, value, sizeof(config->control_pipe) - 1);
|
||||
config->control_pipe[sizeof(config->control_pipe) - 1] = '\0';
|
||||
} else if (MATCH("rds95", "udp_port")) {
|
||||
if (MATCH("rds95", "udp_port")) {
|
||||
config->udp_port = (uint16_t)atoi(value);
|
||||
} else if (MATCH("devices", "rds95")) {
|
||||
strncpy(config->rds_device_name, value, sizeof(config->rds_device_name) - 1);
|
||||
@@ -95,7 +79,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
char config_path[64] = DEFAULT_CONFIG_PATH;
|
||||
RDS95_Config config = {
|
||||
.control_pipe = "\0",
|
||||
.udp_port = 0,
|
||||
.rds_device_name = "\0",
|
||||
.num_streams = DEFAULT_STREAMS
|
||||
@@ -106,7 +89,6 @@ int main(int argc, char **argv) {
|
||||
pa_buffer_attr buffer;
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_t control_pipe_thread;
|
||||
pthread_t udp_server_thread;
|
||||
|
||||
const char *short_opt = "c:h";
|
||||
@@ -181,21 +163,6 @@ int main(int argc, char **argv) {
|
||||
init_rds_encoder(&rdsEncoder);
|
||||
init_rds_modulator(&rdsModulator, &rdsEncoder, config.num_streams);
|
||||
|
||||
if (config.control_pipe[0]) {
|
||||
if (open_control_pipe(config.control_pipe) == 0) {
|
||||
fprintf(stderr, "Reading control commands on %s.\n", config.control_pipe);
|
||||
int r = pthread_create(&control_pipe_thread, &attr, control_pipe_worker, (void*)&rdsModulator);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Could not create control pipe thread.\n");
|
||||
config.control_pipe[0] = 0;
|
||||
goto exit;
|
||||
} else fprintf(stderr, "Created control pipe thread.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Failed to open control pipe: %s.\n", config.control_pipe);
|
||||
config.control_pipe[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(config.udp_port) {
|
||||
if(open_udp_server(config.udp_port, &rdsModulator) == 0) {
|
||||
fprintf(stderr, "Reading control commands on UDP:%d.\n", config.udp_port);
|
||||
@@ -234,11 +201,6 @@ int main(int argc, char **argv) {
|
||||
free(rds_buffer);
|
||||
|
||||
exit:
|
||||
if (config.control_pipe[0]) {
|
||||
fprintf(stderr, "Waiting for pipe thread to shut down.\n");
|
||||
pthread_join(control_pipe_thread, NULL);
|
||||
}
|
||||
|
||||
if(config.udp_port) {
|
||||
fprintf(stderr, "Waiting for UDP thread to shut down.\n");
|
||||
pthread_join(udp_server_thread, NULL);
|
||||
|
||||
Reference in New Issue
Block a user