annotate pcm/main.c @ 32:94f11dc0d474

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