FreeCalypso > hg > ice1-trau-tester
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:570252e22630 | 2:c03ec046471f |
---|---|
1 /* | |
2 * This C module is the main for itt-pcm-one, a program in the icE1 TRAU tester | |
3 * suite that operates on a single timeslot (one TRAU channel) on the PCM side. | |
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 "globals.h" | |
23 | |
24 struct osmo_e1dp_client *g_client; | |
25 int ts_fd; | |
26 | |
27 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; | |
28 static const char *timeslot_spec; | |
29 static void *g_ctx; | |
30 static struct osmo_fd ts_ofd; | |
31 | |
32 static void process_cmdline(int argc, char **argv) | |
33 { | |
34 extern int optind; | |
35 extern char *optarg; | |
36 int c; | |
37 | |
38 while ((c = getopt(argc, argv, "p:")) != EOF) { | |
39 switch (c) { | |
40 case 'p': | |
41 e1d_socket_path = optarg; | |
42 continue; | |
43 default: | |
44 usage: | |
45 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n", | |
46 argv[0]); | |
47 exit(1); | |
48 } | |
49 } | |
50 if (argc != optind + 1) | |
51 goto usage; | |
52 timeslot_spec = argv[optind]; | |
53 } | |
54 | |
55 int main(int argc, char **argv) | |
56 { | |
57 process_cmdline(argc, argv); | |
58 g_ctx = talloc_named_const(NULL, 0, "g_ctx"); | |
59 OSMO_ASSERT(g_ctx); | |
60 osmo_init_logging2(g_ctx, NULL); | |
61 | |
62 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path); | |
63 if (!g_client) { | |
64 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n", | |
65 e1d_socket_path); | |
66 exit(1); | |
67 } | |
68 ts_fd = open_e1d_ts(g_client, timeslot_spec); | |
69 | |
70 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0); | |
71 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); | |
72 | |
73 while (1) { | |
74 osmo_select_main(0); | |
75 } | |
76 } |