diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2017-03-04 07:12:12 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2017-03-04 07:12:12 +0100 |
commit | 3fc4fc54be56310650a9f7ea1183aa71a3d3ac4d (patch) | |
tree | 500dfebbc37eda7b1c2b3184b5df010aa9f13479 /src | |
parent | 4201717f36f1236fd0de1597679f5e9411c8a7eb (diff) |
main_common: Move init and cleanup function to main function
Diffstat (limited to 'src')
-rw-r--r-- | src/amps/main.c | 8 | ||||
-rw-r--r-- | src/anetz/main.c | 9 | ||||
-rw-r--r-- | src/bnetz/main.c | 8 | ||||
-rw-r--r-- | src/cnetz/main.c | 8 | ||||
-rw-r--r-- | src/common/main.h | 4 | ||||
-rw-r--r-- | src/common/main_common.c | 34 | ||||
-rw-r--r-- | src/nmt/main.c | 8 |
7 files changed, 20 insertions, 59 deletions
diff --git a/src/amps/main.c b/src/amps/main.c index b742725..7f83602 100644 --- a/src/amps/main.c +++ b/src/amps/main.c @@ -283,9 +283,6 @@ int main(int argc, char *argv[]) sid_stations(sid); /* init functions */ - rc = init_common(station_id, 10); - if (rc < 0) - goto fail; dsp_init(); init_frame(); @@ -356,12 +353,9 @@ 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) / 1e6, amps_channel2freq(kanal[i], 1) / 1e6); } - main_common(&quit, latency, interval, NULL); + main_common(&quit, latency, interval, NULL, station_id, 10); fail: - /* cleanup functions */ - cleanup_common(); - /* destroy transceiver instance */ while (sender_head) amps_destroy(sender_head); diff --git a/src/anetz/main.c b/src/anetz/main.c index 0511fb5..4ed63a5 100644 --- a/src/anetz/main.c +++ b/src/anetz/main.c @@ -166,10 +166,6 @@ int main(int argc, char *argv[]) if (!loopback) print_image(); - /* init functions */ - rc = init_common(station_id, 5); - if (rc < 0) - goto fail; dsp_init(); anetz_init(); @@ -183,12 +179,9 @@ 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) / 1e6, anetz_kanal2freq(kanal[i], 1) / 1e6); } - main_common(&quit, latency, interval, NULL); + main_common(&quit, latency, interval, NULL, station_id, 5); fail: - /* cleanup functions */ - cleanup_common(); - /* destroy transceiver instance */ while (sender_head) anetz_destroy(sender_head); diff --git a/src/bnetz/main.c b/src/bnetz/main.c index c3a5a9b..c976dbe 100644 --- a/src/bnetz/main.c +++ b/src/bnetz/main.c @@ -164,9 +164,6 @@ int main(int argc, char *argv[]) print_image(); /* init functions */ - rc = init_common(station_id, 5); - if (rc < 0) - goto fail; dsp_init(); bnetz_init(); @@ -187,12 +184,9 @@ int main(int argc, char *argv[]) printf("To call phone, switch transmitter (using paging signal) to %.3f MHz.\n", bnetz_kanal2freq(19, 0) / 1e6); } - main_common(&quit, latency, interval, NULL); + main_common(&quit, latency, interval, NULL, station_id, 5); fail: - /* cleanup functions */ - cleanup_common(); - /* destroy transceiver instance */ while(sender_head) bnetz_destroy(sender_head); diff --git a/src/cnetz/main.c b/src/cnetz/main.c index 24f9429..1efa9b0 100644 --- a/src/cnetz/main.c +++ b/src/cnetz/main.c @@ -228,9 +228,6 @@ int main(int argc, char *argv[]) print_image(); /* init functions */ - rc = init_common(station_id, 7); - if (rc < 0) - goto fail; scrambler_init(); init_sysinfo(); dsp_init(); @@ -303,12 +300,9 @@ int main(int argc, char *argv[]) } } - main_common(&quit, latency, interval, NULL); + main_common(&quit, latency, interval, NULL, station_id, 7); fail: - /* cleanup functions */ - cleanup_common(); - flush_db(); /* destroy transceiver instance */ diff --git a/src/common/main.h b/src/common/main.h index 488650d..aa34cae 100644 --- a/src/common/main.h +++ b/src/common/main.h @@ -39,9 +39,7 @@ void opt_switch_common(int c, char *arg0, int *skip_args); extern int quit; void sighandler(int sigset); -int init_common(const char *station_id, int station_id_digits); -void main_common(int *quit, int latency, int interval, void (*myhandler)(void)); -void cleanup_common(void); +void main_common(int *quit, int latency, int interval, void (*myhandler)(void), const char *station_id, int station_id_digits); void dump_info(void); diff --git a/src/common/main_common.c b/src/common/main_common.c index 754f7e8..634e94c 100644 --- a/src/common/main_common.c +++ b/src/common/main_common.c @@ -417,8 +417,14 @@ static int get_char() return -1; } -int init_common(const char *station_id, int station_id_digits) +/* Loop through all transceiver instances of one network. */ +void main_common(int *quit, int latency, int interval, void (*myhandler)(void), const char *station_id, int station_id_digits) { + int latspl; + sender_t *sender; + double last_time_call = 0, begin_time, now, sleep; + struct termios term, term_orig; + int c; int rc; /* init mncc */ @@ -426,7 +432,7 @@ int init_common(const char *station_id, int station_id_digits) rc = mncc_init("/tmp/bsc_mncc"); if (rc < 0) { fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n"); - return rc; + return; } } @@ -434,14 +440,14 @@ int init_common(const char *station_id, int station_id_digits) rc = call_init(station_id, call_audiodev, call_samplerate, latency, station_id_digits, loopback, use_mncc_sock, send_patterns, release_on_disconnect); if (rc < 0) { fprintf(stderr, "Failed to create call control instance. Quitting!\n"); - return rc; + return; } #ifdef HAVE_UHD #ifdef HAVE_SOAPY if ((sdr_uhd == 1 && sdr_soapy == 1) || (sdr_uhd == 0 && sdr_soapy == 0)) { fprintf(stderr, "UHD and SoapySDR drivers are compiled in. You must choose which one you want: --sdr-uhd or --sdr-soapy\n"); - return -EINVAL; + return; } #else sdr_uhd = 1; @@ -457,21 +463,9 @@ int init_common(const char *station_id, int station_id_digits) #ifdef HAVE_SDR rc = sdr_init(sdr_uhd, sdr_soapy, sdr_args, sdr_rx_gain, sdr_tx_gain, write_iq_rx_wave, write_iq_tx_wave, read_iq_rx_wave); if (rc < 0) - return rc; + return; #endif - return 0; -} - -/* Loop through all transceiver instances of one network. */ -void main_common(int *quit, int latency, int interval, void (*myhandler)(void)) -{ - int latspl; - sender_t *sender; - double last_time_call = 0, begin_time, now, sleep; - struct termios term, term_orig; - int c; - /* open audio */ if (sender_open_audio()) return; @@ -609,11 +603,11 @@ next_char: schedp.sched_priority = 0; sched_setscheduler(0, SCHED_OTHER, &schedp); } -} -void cleanup_common(void) -{ + /* cleanup call control */ call_cleanup(); + + /* close mncc socket */ if (use_mncc_sock) mncc_exit(); } diff --git a/src/nmt/main.c b/src/nmt/main.c index 9aedd3e..89e07c4 100644 --- a/src/nmt/main.c +++ b/src/nmt/main.c @@ -348,9 +348,6 @@ int main(int argc, char *argv[]) print_image(); /* init functions */ - rc = init_common(station_id, 7); - if (rc < 0) - goto fail; rc = init_frame(); if (rc < 0) { fprintf(stderr, "Failed to setup frames. Quitting!\n"); @@ -380,7 +377,7 @@ int main(int argc, char *argv[]) nmt_check_channels(); - main_common(&quit, latency, interval, myhandler); + main_common(&quit, latency, interval, myhandler, station_id, 7); fail: /* fifo */ @@ -388,9 +385,6 @@ fail: close(sms_deliver_fd); unlink(SMS_DELIVER); - /* cleanup functions */ - cleanup_common(); - /* destroy transceiver instance */ while (sender_head) nmt_destroy(sender_head); |