annotate pcm/main.c @ 2:c03ec046471f

pcm: initial version compiles and links
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 08:35:46 +0000
parents
children 7233c10af3ad
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"
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "globals.h"
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct osmo_e1dp_client *g_client;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int ts_fd;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static const char *timeslot_spec;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static void *g_ctx;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static struct osmo_fd ts_ofd;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 static void process_cmdline(int argc, char **argv)
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 extern int optind;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 extern char *optarg;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 int c;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 while ((c = getopt(argc, argv, "p:")) != EOF) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 switch (c) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case 'p':
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 e1d_socket_path = optarg;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 continue;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 default:
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 usage:
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 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
46 argv[0]);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
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 if (argc != optind + 1)
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 goto usage;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 timeslot_spec = argv[optind];
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
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 int main(int argc, char **argv)
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 process_cmdline(argc, argv);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 g_ctx = talloc_named_const(NULL, 0, "g_ctx");
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 OSMO_ASSERT(g_ctx);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 osmo_init_logging2(g_ctx, NULL);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 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
63 if (!g_client) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 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
65 e1d_socket_path);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 ts_fd = open_e1d_ts(g_client, timeslot_spec);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 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
71 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 while (1) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 osmo_select_main(0);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }