comparison pcm-br/main.c @ 35:499d065ee591

new program itt-pcm-br (PCM bridge)
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Aug 2024 05:00:38 +0000
parents pcm/main.c@7233c10af3ad
children
comparison
equal deleted inserted replaced
34:f0b026615f3b 35:499d065ee591
1 /*
2 * This C module is the main for itt-pcm-br, a program in the icE1 TRAU tester
3 * suite that bridges two different timeslots (two TRAU channels) on the A i/f.
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 tsa_fd, tsb_fd;
27
28 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
29 static const char *timeslot_spec_a, *timeslot_spec_b;
30 static void *g_ctx;
31 static struct osmo_fd tsa_ofd, tsb_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,
47 "usage: %s [-p socket] intf:line:ts intf:line:ts\n",
48 argv[0]);
49 exit(1);
50 }
51 }
52 if (argc != optind + 2)
53 goto usage;
54 timeslot_spec_a = argv[optind];
55 timeslot_spec_b = argv[optind+1];
56 }
57
58 int main(int argc, char **argv)
59 {
60 process_cmdline(argc, argv);
61 g_ctx = talloc_named_const(NULL, 0, "g_ctx");
62 OSMO_ASSERT(g_ctx);
63 osmo_init_logging2(g_ctx, NULL);
64
65 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path);
66 if (!g_client) {
67 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n",
68 e1d_socket_path);
69 exit(1);
70 }
71 tsa_fd = open_e1d_ts(g_client, timeslot_spec_a);
72 tsb_fd = open_e1d_ts(g_client, timeslot_spec_b);
73
74 osmo_fd_setup(&tsa_ofd, tsa_fd, OSMO_FD_READ, tsa_fd_cb, NULL, 0);
75 OSMO_ASSERT(osmo_fd_register(&tsa_ofd) == 0);
76
77 osmo_fd_setup(&tsb_ofd, tsb_fd, OSMO_FD_READ, tsb_fd_cb, NULL, 0);
78 OSMO_ASSERT(osmo_fd_register(&tsb_ofd) == 0);
79
80 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb,
81 handle_user_cmd, 0);
82 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0);
83
84 while (1) {
85 osmo_select_main(0);
86 }
87 }