Move realtime scheduling and signal handling to common code
This commit is contained in:
@@ -22,8 +22,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include "../common/main.h"
|
#include "../common/main.h"
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
@@ -357,32 +355,8 @@ int main(int argc, char *argv[])
|
|||||||
printf("Base station on channel %d ready (%s), please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], chan_type_long_name(chan_type[i]), amps_channel2freq(kanal[i], 0), amps_channel2freq(kanal[i], 1));
|
printf("Base station on channel %d ready (%s), please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], chan_type_long_name(chan_type[i]), amps_channel2freq(kanal[i], 0), amps_channel2freq(kanal[i], 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT,sighandler);
|
|
||||||
signal(SIGHUP,sighandler);
|
|
||||||
signal(SIGTERM,sighandler);
|
|
||||||
signal(SIGPIPE,sighandler);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_loop(&quit, latency, interval, NULL);
|
main_loop(&quit, latency, interval, NULL);
|
||||||
|
|
||||||
if (rt_prio > 0) {
|
|
||||||
struct sched_param schedp;
|
|
||||||
|
|
||||||
memset(&schedp, 0, sizeof(schedp));
|
|
||||||
schedp.sched_priority = 0;
|
|
||||||
sched_setscheduler(0, SCHED_OTHER, &schedp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* cleanup functions */
|
/* cleanup functions */
|
||||||
call_cleanup();
|
call_cleanup();
|
||||||
|
@@ -22,8 +22,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include "../common/main.h"
|
#include "../common/main.h"
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
@@ -177,32 +175,8 @@ int main(int argc, char *argv[])
|
|||||||
printf("Base station on channel %d ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], anetz_kanal2freq(kanal[i], 0), anetz_kanal2freq(kanal[i], 1));
|
printf("Base station on channel %d ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], anetz_kanal2freq(kanal[i], 0), anetz_kanal2freq(kanal[i], 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT,sighandler);
|
|
||||||
signal(SIGHUP,sighandler);
|
|
||||||
signal(SIGTERM,sighandler);
|
|
||||||
signal(SIGPIPE,sighandler);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_loop(&quit, latency, interval, NULL);
|
main_loop(&quit, latency, interval, NULL);
|
||||||
|
|
||||||
if (rt_prio > 0) {
|
|
||||||
struct sched_param schedp;
|
|
||||||
|
|
||||||
memset(&schedp, 0, sizeof(schedp));
|
|
||||||
schedp.sched_priority = 0;
|
|
||||||
sched_setscheduler(0, SCHED_OTHER, &schedp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* cleanup functions */
|
/* cleanup functions */
|
||||||
call_cleanup();
|
call_cleanup();
|
||||||
|
@@ -22,8 +22,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
#include "../common/call.h"
|
#include "../common/call.h"
|
||||||
@@ -197,32 +195,8 @@ int main(int argc, char *argv[])
|
|||||||
printf("To call phone, switch transmitter (using pilot signal) to %.3f MHz.\n", bnetz_kanal2freq(19, 0));
|
printf("To call phone, switch transmitter (using pilot signal) to %.3f MHz.\n", bnetz_kanal2freq(19, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT,sighandler);
|
|
||||||
signal(SIGHUP,sighandler);
|
|
||||||
signal(SIGTERM,sighandler);
|
|
||||||
signal(SIGPIPE,sighandler);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_loop(&quit, latency, interval, NULL);
|
main_loop(&quit, latency, interval, NULL);
|
||||||
|
|
||||||
if (rt_prio > 0) {
|
|
||||||
struct sched_param schedp;
|
|
||||||
|
|
||||||
memset(&schedp, 0, sizeof(schedp));
|
|
||||||
schedp.sched_priority = 0;
|
|
||||||
sched_setscheduler(0, SCHED_OTHER, &schedp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* cleanup functions */
|
/* cleanup functions */
|
||||||
call_cleanup();
|
call_cleanup();
|
||||||
|
@@ -22,8 +22,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include "../common/main.h"
|
#include "../common/main.h"
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "../common/timer.h"
|
#include "../common/timer.h"
|
||||||
@@ -311,32 +309,8 @@ int main(int argc, char *argv[])
|
|||||||
printf("Base station on channel %d ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], cnetz_kanal2freq(kanal[i], 0), cnetz_kanal2freq(kanal[i], 1));
|
printf("Base station on channel %d ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz.\n", kanal[i], cnetz_kanal2freq(kanal[i], 0), cnetz_kanal2freq(kanal[i], 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT,sighandler);
|
|
||||||
signal(SIGHUP,sighandler);
|
|
||||||
signal(SIGTERM,sighandler);
|
|
||||||
signal(SIGPIPE,sighandler);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_loop(&quit, latency, interval, NULL);
|
main_loop(&quit, latency, interval, NULL);
|
||||||
|
|
||||||
if (rt_prio > 0) {
|
|
||||||
struct sched_param schedp;
|
|
||||||
|
|
||||||
memset(&schedp, 0, sizeof(schedp));
|
|
||||||
schedp.sched_priority = 0;
|
|
||||||
sched_setscheduler(0, SCHED_OTHER, &schedp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* cleanup functions */
|
/* cleanup functions */
|
||||||
call_cleanup();
|
call_cleanup();
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
@@ -256,7 +257,7 @@ void sighandler(int sigset)
|
|||||||
if (sigset == SIGPIPE)
|
if (sigset == SIGPIPE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(stderr, "Signal received: %d\n", sigset);
|
fprintf(stderr, "\nSignal received: %d\n", sigset);
|
||||||
|
|
||||||
quit = 1;
|
quit = 1;
|
||||||
}
|
}
|
||||||
@@ -287,6 +288,24 @@ void main_loop(int *quit, int latency, int interval, void (*myhandler)(void))
|
|||||||
struct termios term, term_orig;
|
struct termios term, term_orig;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
/* catch signals */
|
||||||
|
signal(SIGINT, sighandler);
|
||||||
|
signal(SIGHUP, sighandler);
|
||||||
|
signal(SIGTERM, sighandler);
|
||||||
|
signal(SIGPIPE, sighandler);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/* prepare terminal */
|
/* prepare terminal */
|
||||||
tcgetattr(0, &term_orig);
|
tcgetattr(0, &term_orig);
|
||||||
term = term_orig;
|
term = term_orig;
|
||||||
@@ -323,6 +342,7 @@ next_char:
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case 3:
|
case 3:
|
||||||
/* quit */
|
/* quit */
|
||||||
|
fprintf(stderr, "\nCTRL+c received, quitting!\n");
|
||||||
*quit = 1;
|
*quit = 1;
|
||||||
goto next_char;
|
goto next_char;
|
||||||
case 'w':
|
case 'w':
|
||||||
@@ -349,5 +369,20 @@ next_char:
|
|||||||
|
|
||||||
/* reset terminal */
|
/* reset terminal */
|
||||||
tcsetattr(0, TCSANOW, &term_orig);
|
tcsetattr(0, TCSANOW, &term_orig);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reset signals */
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
signal(SIGTERM, SIG_DFL);
|
||||||
|
signal(SIGPIPE, SIG_DFL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,8 +22,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -358,32 +356,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
nmt_check_channels();
|
nmt_check_channels();
|
||||||
|
|
||||||
signal(SIGINT,sighandler);
|
|
||||||
signal(SIGHUP,sighandler);
|
|
||||||
signal(SIGTERM,sighandler);
|
|
||||||
signal(SIGPIPE,sighandler);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_loop(&quit, latency, interval, myhandler);
|
main_loop(&quit, latency, interval, myhandler);
|
||||||
|
|
||||||
if (rt_prio > 0) {
|
|
||||||
struct sched_param schedp;
|
|
||||||
|
|
||||||
memset(&schedp, 0, sizeof(schedp));
|
|
||||||
schedp.sched_priority = 0;
|
|
||||||
sched_setscheduler(0, SCHED_OTHER, &schedp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* fifo */
|
/* fifo */
|
||||||
if (sms_deliver_fd > 0)
|
if (sms_deliver_fd > 0)
|
||||||
|
Reference in New Issue
Block a user