Osmoradio fixes: Use real time scheduling and always transmit empty buffer

This commit is contained in:
Andreas Eversberg 2018-05-21 08:59:21 +02:00
parent ce4a540745
commit c774180082
1 changed files with 37 additions and 13 deletions

View File

@ -25,6 +25,7 @@ enum paging_signal;
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <sched.h>
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <termios.h> #include <termios.h>
@ -42,6 +43,7 @@ enum paging_signal;
void *sender_head = NULL; void *sender_head = NULL;
int use_sdr = 0; int use_sdr = 0;
int num_kanal = 1; /* only one channel used for debugging */ int num_kanal = 1; /* only one channel used for debugging */
int rt_prio = 1;
void *get_sender_by_empfangsfrequenz() { return NULL; } void *get_sender_by_empfangsfrequenz() { return NULL; }
@ -331,6 +333,18 @@ int main(int argc, char *argv[])
goto error; goto error;
} }
/* real time priority */
if (rt_prio > 0) {
struct sched_param schedp;
int rc;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = rt_prio;
rc = sched_setscheduler(0, SCHED_RR, &schedp);
if (rc)
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
double tx_frequencies[1], rx_frequencies[1]; double tx_frequencies[1], rx_frequencies[1];
tx_frequencies[0] = frequency; tx_frequencies[0] = frequency;
rx_frequencies[0] = frequency; rx_frequencies[0] = frequency;
@ -369,20 +383,21 @@ int main(int argc, char *argv[])
if (got < 0) if (got < 0)
break; break;
} }
if (tx) { tosend = sdr_get_tosend(sdr, latspl);
tosend = sdr_get_tosend(sdr, latspl); if (tosend > latspl / 10)
if (tosend > latspl / 10) tosend = latspl / 10;
tosend = latspl / 10; if (tosend == 0) {
if (tosend == 0) { continue;
continue;
}
/* perform radio modulation */
tosend = radio_tx(&radio, sendbuff, tosend);
if (tosend < 0)
break;
/* write to SDR */
sdr_write(sdr, (void *)sendbuff, NULL, tosend, NULL, NULL, 0);
} }
/* perform radio modulation */
if (tx)
tosend = radio_tx(&radio, sendbuff, tosend);
else
memset(sendbuff, 0, tosend * sizeof(*sendbuff) * 2);
if (tosend < 0)
break;
/* write to SDR */
sdr_write(sdr, (void *)sendbuff, NULL, tosend, NULL, NULL, 0);
/* process keyboard input */ /* process keyboard input */
next_char: next_char:
@ -435,6 +450,15 @@ next_char:
tcsetattr(0, TCSANOW, &term_orig); tcsetattr(0, TCSANOW, &term_orig);
error: error:
/* reset real time prio */
if (rt_prio > 0) {
struct sched_param schedp;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = 0;
sched_setscheduler(0, SCHED_OTHER, &schedp);
}
free(sendbuff); free(sendbuff);
if (sdr) if (sdr)
sdr_close(sdr); sdr_close(sdr);