Use global init/cleanup function
This commit is contained in:
parent
bc028cd4d3
commit
2d8d7e62c1
|
@ -282,20 +282,11 @@ int main(int argc, char *argv[])
|
|||
sid_stations(sid);
|
||||
|
||||
/* init functions */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rc = init_common(station_id, 10);
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
dsp_init();
|
||||
init_frame();
|
||||
rc = call_init(station_id, call_audiodev, samplerate, latency, 10, loopback);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create call control instance. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* check for mandatory CC */
|
||||
for (i = 0; i < num_kanal; i++) {
|
||||
|
@ -368,9 +359,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
fail:
|
||||
/* cleanup functions */
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
cleanup_common();
|
||||
|
||||
/* destroy transceiver instance */
|
||||
while (sender_head)
|
||||
|
|
|
@ -166,20 +166,11 @@ int main(int argc, char *argv[])
|
|||
print_image();
|
||||
|
||||
/* init functions */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rc = init_common(station_id, 5);
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
dsp_init();
|
||||
anetz_init();
|
||||
rc = call_init(station_id, call_audiodev, samplerate, latency, 5, loopback);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create call control instance. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* create transceiver instance */
|
||||
for (i = 0; i < num_kanal; i++) {
|
||||
|
@ -195,9 +186,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
fail:
|
||||
/* cleanup functions */
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
cleanup_common();
|
||||
|
||||
/* destroy transceiver instance */
|
||||
while (sender_head)
|
||||
|
|
|
@ -170,20 +170,11 @@ int main(int argc, char *argv[])
|
|||
print_image();
|
||||
|
||||
/* init functions */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
rc = init_common(station_id, 5);
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
dsp_init();
|
||||
bnetz_init();
|
||||
rc = call_init(station_id, call_audiodev, samplerate, latency, 5, loopback);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create call control instance. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* SDR always requires emphasis */
|
||||
if (!strcmp(audiodev[0], "sdr")) {
|
||||
|
@ -206,9 +197,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
fail:
|
||||
/* cleanup functions */
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
cleanup_common();
|
||||
|
||||
/* destroy transceiver instance */
|
||||
while(sender_head)
|
||||
|
|
|
@ -244,13 +244,9 @@ int main(int argc, char *argv[])
|
|||
print_image();
|
||||
|
||||
/* init functions */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
rc = init_common(station_id, 7);
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
scrambler_init();
|
||||
init_sysinfo();
|
||||
dsp_init();
|
||||
|
@ -261,11 +257,6 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
init_coding();
|
||||
cnetz_init();
|
||||
rc = call_init(station_id, call_audiodev, samplerate, latency, 7, loopback);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create call control instance. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* check for mandatory OgK */
|
||||
for (i = 0; i < num_kanal; i++) {
|
||||
|
@ -326,9 +317,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
fail:
|
||||
/* cleanup functions */
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
cleanup_common();
|
||||
|
||||
flush_db();
|
||||
|
||||
|
|
|
@ -34,10 +34,6 @@
|
|||
|
||||
#define DISC_TIMEOUT 30
|
||||
|
||||
extern int use_mncc_sock;
|
||||
extern int send_patterns;
|
||||
extern int release_on_disconnect;
|
||||
|
||||
/* stream patterns/announcements */
|
||||
int16_t *test_spl = NULL;
|
||||
int16_t *ringback_spl = NULL;
|
||||
|
@ -175,6 +171,10 @@ typedef struct call {
|
|||
int test_audio_pos; /* position for test tone toward mobile */
|
||||
int dial_digits; /* number of digits to be dialed */
|
||||
int loopback; /* loopback test for echo */
|
||||
int use_mncc_sock;
|
||||
int send_patterns;
|
||||
int release_on_disconnect;
|
||||
|
||||
} call_t;
|
||||
|
||||
static call_t call;
|
||||
|
@ -454,20 +454,23 @@ static void process_timeout(struct timer *timer)
|
|||
}
|
||||
}
|
||||
|
||||
int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback)
|
||||
int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback, int use_mncc_sock, int send_patterns, int release_on_disconnect)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
init_testton();
|
||||
|
||||
if (use_mncc_sock)
|
||||
return 0;
|
||||
|
||||
memset(&call, 0, sizeof(call));
|
||||
strncpy(call.station_id, station_id, sizeof(call.station_id) - 1);
|
||||
call.latspl = latency * samplerate / 1000;
|
||||
call.dial_digits = dial_digits;
|
||||
call.loopback = loopback;
|
||||
call.use_mncc_sock = use_mncc_sock;
|
||||
call.send_patterns = send_patterns;
|
||||
call.release_on_disconnect = release_on_disconnect;
|
||||
|
||||
if (call.use_mncc_sock)
|
||||
return 0;
|
||||
|
||||
if (!audiodev[0])
|
||||
return 0;
|
||||
|
@ -502,7 +505,7 @@ error:
|
|||
|
||||
void call_cleanup(void)
|
||||
{
|
||||
if (use_mncc_sock)
|
||||
if (call.use_mncc_sock)
|
||||
return;
|
||||
|
||||
/* close sound devoice */
|
||||
|
@ -625,7 +628,7 @@ void print_console_text(void)
|
|||
* returns 1 on exit (ctrl+c) */
|
||||
void process_call(int c)
|
||||
{
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
mncc_handle();
|
||||
return;
|
||||
}
|
||||
|
@ -714,7 +717,7 @@ int call_in_setup(int callref, const char *callerid, const char *dialing)
|
|||
if (!strcmp(dialing, "010"))
|
||||
PDEBUG(DCALL, DEBUG_INFO, " -> Call to Operator '%s'\n", dialing);
|
||||
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
uint8_t buf[sizeof(struct gsm_mncc)];
|
||||
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
|
||||
int rc;
|
||||
|
@ -777,11 +780,11 @@ void call_in_alerting(int callref)
|
|||
|
||||
PDEBUG(DCALL, DEBUG_INFO, "Call is alerting\n");
|
||||
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
uint8_t buf[sizeof(struct gsm_mncc)];
|
||||
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
|
||||
|
||||
if (!send_patterns) {
|
||||
if (!call.send_patterns) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
mncc->msg_type = MNCC_ALERT_IND;
|
||||
mncc->callref = callref;
|
||||
|
@ -830,7 +833,7 @@ void call_in_answer(int callref, const char *connect_id)
|
|||
|
||||
PDEBUG(DCALL, DEBUG_INFO, "Call has been answered by '%s'\n", connect_id);
|
||||
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
_indicate_answer(callref, connect_id);
|
||||
set_pattern_process(callref, PATTERN_NONE);
|
||||
set_state_process(callref, CALL_CONNECT);
|
||||
|
@ -857,7 +860,7 @@ void call_in_release(int callref, int cause)
|
|||
|
||||
PDEBUG(DCALL, DEBUG_INFO, "Call has been released with cause=%d\n", cause);
|
||||
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
uint8_t buf[sizeof(struct gsm_mncc)];
|
||||
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
|
||||
|
||||
|
@ -869,7 +872,7 @@ void call_in_release(int callref, int cause)
|
|||
mncc->cause.value = cause;
|
||||
|
||||
if (is_process(callref)) {
|
||||
if (!send_patterns
|
||||
if (!call.send_patterns
|
||||
|| is_process_state(callref) == CALL_DISCONNECTED
|
||||
|| is_process_state(callref) == CALL_SETUP_MO) {
|
||||
PDEBUG(DMNCC, DEBUG_INFO, "Releasing MNCC call towards Network\n");
|
||||
|
@ -901,7 +904,7 @@ void call_tx_audio(int callref, int16_t *samples, int count)
|
|||
if (!callref)
|
||||
return;
|
||||
|
||||
if (use_mncc_sock) {
|
||||
if (call.use_mncc_sock) {
|
||||
uint8_t buf[sizeof(struct gsm_data_frame) + count * sizeof(int16_t)];
|
||||
struct gsm_data_frame *data = (struct gsm_data_frame *)buf;
|
||||
|
||||
|
@ -1046,7 +1049,7 @@ void call_mncc_recv(uint8_t *buf, int length)
|
|||
rc = call_out_setup(callref, caller_id, caller_type, number);
|
||||
if (rc < 0) {
|
||||
PDEBUG(DCALL, DEBUG_NOTICE, "Call rejected, cause %d\n", -rc);
|
||||
if (send_patterns) {
|
||||
if (call.send_patterns) {
|
||||
PDEBUG(DCALL, DEBUG_DEBUG, "Early connecting after setup\n");
|
||||
_indicate_answer(callref, number);
|
||||
disconnect_process(callref, -rc);
|
||||
|
@ -1064,7 +1067,7 @@ void call_mncc_recv(uint8_t *buf, int length)
|
|||
break;
|
||||
}
|
||||
|
||||
if (send_patterns) {
|
||||
if (call.send_patterns) {
|
||||
PDEBUG(DCALL, DEBUG_DEBUG, "Early connecting after setup\n");
|
||||
_indicate_answer(callref, number);
|
||||
break;
|
||||
|
@ -1077,7 +1080,7 @@ void call_mncc_recv(uint8_t *buf, int length)
|
|||
case MNCC_DISC_REQ:
|
||||
PDEBUG(DMNCC, DEBUG_INFO, "Received MNCC disconnect from Network with cause %d\n", mncc->cause.value);
|
||||
|
||||
if (is_process_state(callref) == CALL_CONNECT && release_on_disconnect) {
|
||||
if (is_process_state(callref) == CALL_CONNECT && call.release_on_disconnect) {
|
||||
PDEBUG(DCALL, DEBUG_INFO, "Releaseing, because we don't send disconnect tones to mobile phone\n");
|
||||
|
||||
PDEBUG(DMNCC, DEBUG_INFO, "Releasing MNCC call towards Network\n");
|
||||
|
|
|
@ -9,7 +9,7 @@ enum number_type {
|
|||
TYPE_INTERNATIONAL,
|
||||
};
|
||||
|
||||
int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback);
|
||||
int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback, int use_mncc_sock, int send_patterns, int release_on_disconnect);
|
||||
void call_cleanup(void);
|
||||
void process_call(int c);
|
||||
void clear_console_text(void);
|
||||
|
|
|
@ -39,7 +39,9 @@ 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 dump_info(void);
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "sender.h"
|
||||
#include "timer.h"
|
||||
#include "call.h"
|
||||
#include "mncc_sock.h"
|
||||
#ifdef HAVE_SDR
|
||||
#include "sdr.h"
|
||||
#endif
|
||||
|
@ -353,6 +354,35 @@ static int get_char()
|
|||
return -1;
|
||||
}
|
||||
|
||||
int init_common(const char *station_id, int station_id_digits)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* init mncc */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* init call device */
|
||||
rc = call_init(station_id, call_audiodev, 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;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SDR
|
||||
rc = sdr_init(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;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Loop through all transceiver instances of one network. */
|
||||
void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
|
||||
{
|
||||
|
@ -362,11 +392,6 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
|
|||
struct termios term, term_orig;
|
||||
int c;
|
||||
|
||||
#ifdef HAVE_SDR
|
||||
if (sdr_init(sdr_args, sdr_rx_gain, sdr_tx_gain))
|
||||
return;
|
||||
#endif
|
||||
|
||||
/* open audio */
|
||||
if (sender_open_audio())
|
||||
return;
|
||||
|
@ -477,3 +502,10 @@ next_char:
|
|||
}
|
||||
}
|
||||
|
||||
void cleanup_common(void)
|
||||
{
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -347,24 +347,15 @@ int main(int argc, char *argv[])
|
|||
print_image();
|
||||
|
||||
/* init functions */
|
||||
if (use_mncc_sock) {
|
||||
rc = mncc_init("/tmp/bsc_mncc");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
dsp_init();
|
||||
rc = call_init(station_id, call_audiodev, samplerate, latency, 7, loopback);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create call control instance. Quitting!\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* SDR always requires emphasis */
|
||||
if (!strcmp(audiodev[0], "sdr")) {
|
||||
|
@ -397,9 +388,7 @@ fail:
|
|||
unlink(SMS_DELIVER);
|
||||
|
||||
/* cleanup functions */
|
||||
call_cleanup();
|
||||
if (use_mncc_sock)
|
||||
mncc_exit();
|
||||
cleanup_common();
|
||||
|
||||
/* destroy transceiver instance */
|
||||
while (sender_head)
|
||||
|
|
Loading…
Reference in New Issue