/* Common part for main.c of each base station type * * (C) 2016 by Andreas Eversberg * All Rights Reserved * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include "main.h" #include "debug.h" #include "../common/sender.h" /* common settings */ int num_kanal = 0; int kanal[MAX_SENDER]; int num_sounddev = 0; const char *sounddev[MAX_SENDER] = { "hw:0,0" }; const char *call_sounddev = ""; int samplerate = 48000; int latency = 50; int cross_channels = 0; int use_mncc_sock = 0; int send_patterns = 1; int loopback = 0; int rt_prio = 0; int do_pre_emphasis = 0; int do_de_emphasis = 0; const char *read_wave = NULL; const char *write_wave = NULL; void print_help_common(const char *arg0, const char *ext_usage) { printf("Usage: %s -k %s[options] [station-id]\n", arg0, ext_usage); printf("\noptions:\n"); /* - - */ printf(" -h --help\n"); printf(" This help\n"); printf(" -D --debug \n"); printf(" Debug level: 0 = debug | 1 = info | 2 = notice (default = '%d')\n", debuglevel); printf(" -k --kanal \n"); printf(" Channel number of \"Sender\"\n"); printf(" -d --device hw:,\n"); printf(" Sound card and device number (default = '%s')\n", sounddev[0]); printf(" -s --samplerate \n"); printf(" Sample rate of sound device (default = '%d')\n", samplerate); printf(" -l --latency \n"); printf(" How many milliseconds processed in advance (default = '%d')\n", latency); printf(" -x --cross\n"); printf(" Cross channels on sound card. 1st channel (right) is swapped with\n"); printf(" second channel (left)\n"); printf(" -m --mncc-sock\n"); printf(" Disable built-in call contol and offer socket (to LCR)\n"); printf(" -c --call-device hw:,\n"); printf(" Sound card and device number for headset (default = '%s')\n", call_sounddev); printf(" -p --send-patterns 0 | 1\n"); printf(" Connect call on setup/release to provide classic tones (default = '%d')\n", send_patterns); printf(" -L --loopback \n"); printf(" Loopback test: 1 = internal | 2 = external | 3 = echo\n"); printf(" -r --realtime \n"); printf(" Set prio: 0 to diable, 99 for maximum (default = %d)\n", rt_prio); printf(" -E --pre-emphasis\n"); printf(" Enable pre-emphasis, if you directly connect to the oscillator of the\n"); printf(" transmitter. (No pre-emphasis done by the transmitter.)\n"); printf(" -e --de-emphasis\n"); printf(" Enable de-emphasis, if you directly connect to the discriminator of\n"); printf(" the receiver. (No de-emphasis done by the receiver.)\n"); printf(" -W --write-wave \n"); printf(" Write received audio to given wav audio file.\n"); printf(" -R --read-wave \n"); printf(" Replace received audio by given wav audio file.\n"); } static struct option long_options_common[] = { {"help", 0, 0, 'h'}, {"debug", 1, 0, 'D'}, {"kanal", 1, 0, 'k'}, {"device", 1, 0, 'd'}, {"call-device", 1, 0, 'c'}, {"samplerate", 1, 0, 's'}, {"latency", 1, 0, 'l'}, {"cross", 0, 0, 'x'}, {"mncc-sock", 0, 0, 'm'}, {"send-patterns", 0, 0, 'p'}, {"loopback", 1, 0, 'L'}, {"realtime", 1, 0, 'r'}, {"pre-emphasis", 0, 0, 'E'}, {"de-emphasis", 0, 0, 'e'}, {"write-wave", 1, 0, 'W'}, {"read-wave", 1, 0, 'R'}, {0, 0, 0, 0} }; const char *optstring_common = "hD:k:d:s:c:l:xmp:L:r:EeW:R:"; struct option *long_options; char *optstring; void set_options_common(const char *optstring_special, struct option *long_options_special) { int i; long_options = calloc(sizeof(*long_options), 100); for (i = 0; long_options_common[i].name; i++) memcpy(&long_options[i], &long_options_common[i], sizeof(*long_options)); for (; long_options_special->name; i++) memcpy(&long_options[i], long_options_special++, sizeof(*long_options)); optstring = calloc(strlen(optstring_common) + strlen(optstring_special) + 1, 1); strcpy(optstring, optstring_common); strcat(optstring, optstring_special); } void opt_switch_common(int c, char *arg0, int *skip_args) { switch (c) { case 'h': print_help(arg0); exit(0); case 'D': debuglevel = atoi(optarg); if (debuglevel > 2) debuglevel = 2; if (debuglevel < 0) debuglevel = 0; *skip_args += 2; break; case 'k': OPT_ARRAY(num_kanal, kanal, atoi(optarg)) *skip_args += 2; break; case 'd': OPT_ARRAY(num_sounddev, sounddev, strdup(optarg)) *skip_args += 2; break; case 's': samplerate = atoi(optarg); *skip_args += 2; break; case 'c': call_sounddev = strdup(optarg); *skip_args += 2; break; case 'l': latency = atoi(optarg); *skip_args += 2; break; case 'x': cross_channels = 1; *skip_args += 1; break; case 'm': use_mncc_sock = 1; *skip_args += 1; break; case 'p': send_patterns = atoi(optarg); *skip_args += 2; break; case 'L': loopback = atoi(optarg); *skip_args += 2; break; case 'r': rt_prio = atoi(optarg); *skip_args += 2; break; case 'E': do_pre_emphasis = 1; *skip_args += 1; break; case 'e': do_de_emphasis = 1; *skip_args += 1; break; case 'W': write_wave = strdup(optarg); *skip_args += 2; break; case 'R': read_wave = strdup(optarg); *skip_args += 2; break; default: exit (0); } } /* global variable to quit main loop */ int quit = 0; void sighandler(int sigset) { if (sigset == SIGHUP) return; if (sigset == SIGPIPE) return; fprintf(stderr, "Signal received: %d\n", sigset); quit = 1; }