aboutsummaryrefslogtreecommitdiffstats
path: root/src/zeitansage/main.c
blob: 7112f7fc1db3ee54114e6ccaea9f08cf602b2045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Zeitansage main
 *
 * (C) 2020 by Andreas Eversberg <jolly@eversberg.eu>
 * 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 <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "../libsample/sample.h"
#include "../libdebug/debug.h"
#include "../libmobile/call.h"
#include "../libmobile/main_mobile.h"
#include "../liboptions/options.h"
#include "zeitansage.h"
#include "samples.h"

double audio_level_dBm = -16.0;
int alerting = 0;


void print_help(const char *arg0)
{
	main_mobile_print_help(arg0, "-c hw:0,0 ");
	/*      -                                                                             - */
	printf(" -G --gain\n");
	printf("        Gain of audio level relative to 1 mW on a 600 Ohm line. (default = %.0f)\n", audio_level_dBm);
	printf(" -A --alerting\n");
	printf("        Play as early audio while alerting. Don't send a connect.\n");
	main_mobile_print_hotkeys();
}

static void add_options(void)
{
	main_mobile_add_options();
	option_add('G', "gain", 1);
	option_add('A', "alerting", 0);
}

static int handle_options(int short_option, int argi, char **argv)
{
	switch (short_option) {
	case 'G':
		audio_level_dBm = atof(argv[argi]);
		break;
	case 'A':
		alerting = 1;
		send_patterns = 0;
		break;
	default:
		return main_mobile_handle_options(short_option, argi, argv);
	}

	return 1;
}

static const struct number_lengths number_lengths[] = {
	{ 0, "no number" },
	{ 4, "number '1191'" },
	{ 0, NULL },
};

int main(int argc, char *argv[])
{
	int rc, argi;

	allow_sdr = 0;

	/* init system specific tones */
	init_samples();

	/* init mobile interface */
	main_mobile_init("0123456789", number_lengths, NULL, NULL);

	/* handle options / config file */
	add_options();
	rc = options_config_file(argc, argv, "~/.osmocom/analog/zeitansage.conf", handle_options);
	if (rc < 0)
		return 0;
	argi = options_command_line(argc, argv, handle_options);
	if (argi <= 0)
		return argi;

	/* inits */
	fm_init(fast_math);
	zeit_init(audio_level_dBm, alerting);

	main_mobile_loop("zeitansage", &quit, NULL, "1191");

//fail:
	/* exits */
	zeit_exit();
	fm_exit();

	options_free();

	return 0;
}