comparison ater/main.c @ 15:98ae717734d6

ater: starting skeleton
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 04:01:38 +0000
parents pcm/main.c@7233c10af3ad
children 4ffe22f5b4b5
comparison
equal deleted inserted replaced
14:99426da5603d 15:98ae717734d6
1 /*
2 * This C module is the main for itt-ater-16, a program in the icE1 TRAU tester
3 * suite that operates on a single E1 timeslot on the Ater interface.
4 *
5 * This code is based on osmo-e1d-pipe,
6 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>,
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10 #include <stdint.h>
11 #include <stdbool.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15
16 #include <osmocom/core/talloc.h>
17 #include <osmocom/core/select.h>
18 #include <osmocom/core/application.h>
19 #include <osmocom/e1d/proto_clnt.h>
20
21 #include "../libutil/open_ts.h"
22 #include "../libutil/stdin_handler.h"
23 #include "globals.h"
24
25 struct osmo_e1dp_client *g_client;
26 int ts_fd;
27
28 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
29 static const char *timeslot_spec;
30 static void *g_ctx;
31 static struct osmo_fd ts_ofd, stdin_ofd;
32
33 static void process_cmdline(int argc, char **argv)
34 {
35 extern int optind;
36 extern char *optarg;
37 int c;
38
39 while ((c = getopt(argc, argv, "p:")) != EOF) {
40 switch (c) {
41 case 'p':
42 e1d_socket_path = optarg;
43 continue;
44 default:
45 usage:
46 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n",
47 argv[0]);
48 exit(1);
49 }
50 }
51 if (argc != optind + 1)
52 goto usage;
53 timeslot_spec = argv[optind];
54 }
55
56 int main(int argc, char **argv)
57 {
58 process_cmdline(argc, argv);
59 g_ctx = talloc_named_const(NULL, 0, "g_ctx");
60 OSMO_ASSERT(g_ctx);
61 osmo_init_logging2(g_ctx, NULL);
62
63 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path);
64 if (!g_client) {
65 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n",
66 e1d_socket_path);
67 exit(1);
68 }
69 ts_fd = open_e1d_ts(g_client, timeslot_spec);
70
71 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0);
72 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0);
73
74 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb,
75 handle_user_cmd, 0);
76 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0);
77
78 while (1) {
79 osmo_select_main(0);
80 }
81 }