main_common: Move init and cleanup function to main function
This commit is contained in:
parent
4201717f36
commit
3fc4fc54be
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue