# HG changeset patch # User Mychaela Falconia # Date 1719131746 0 # Node ID c03ec046471f1d281241b10643e5e7af78929e9e # Parent 570252e226301cec3bfb2082d82ac77adebe2ba8 pcm: initial version compiles and links diff -r 570252e22630 -r c03ec046471f .hgignore --- a/.hgignore Sun Jun 23 07:28:51 2024 +0000 +++ b/.hgignore Sun Jun 23 08:35:46 2024 +0000 @@ -2,3 +2,5 @@ \.[oa]$ ^config\.defs$ + +^pcm/itt-pcm-one$ diff -r 570252e22630 -r c03ec046471f pcm/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/Makefile Sun Jun 23 08:35:46 2024 +0000 @@ -0,0 +1,20 @@ +PROG= itt-pcm-one +OBJS= main.o read_ts.o +LIBUTIL=../libutil/libutil.a + +include ../config.defs + +CPPFLAGS=${OSMO_INCLUDE} +OSMO_LINK=${OSMO_LPATH} ${OSMO_RPATH} ${OSMO_LIBS} + +all: ${PROG} + +${PROG}: ${OBJS} ${LIBUTIL} + ${CC} -o $@ ${OBJS} ${LIBUTIL} ${OSMO_LINK} + +install: + mkdir -p ${DESTDIR}${bindir} + install -c -m 755 ${PROG} ${DESTDIR}${bindir} + +clean: + rm -f *.o ${PROG} errs diff -r 570252e22630 -r c03ec046471f pcm/globals.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/globals.h Sun Jun 23 08:35:46 2024 +0000 @@ -0,0 +1,9 @@ +/* global vars and intermodule-linkage functions in itt-pcm-one */ + +#pragma once + +extern struct osmo_e1dp_client *g_client; +extern int ts_fd; +extern uint8_t readbuf[160]; + +int ts_fd_cb(struct osmo_fd *ofd, unsigned int what); diff -r 570252e22630 -r c03ec046471f pcm/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/main.c Sun Jun 23 08:35:46 2024 +0000 @@ -0,0 +1,76 @@ +/* + * This C module is the main for itt-pcm-one, a program in the icE1 TRAU tester + * suite that operates on a single timeslot (one TRAU channel) on the PCM side. + * + * This code is based on osmo-e1d-pipe, + * (C) 2020-2022 by Harald Welte , + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../libutil/open_ts.h" +#include "globals.h" + +struct osmo_e1dp_client *g_client; +int ts_fd; + +static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; +static const char *timeslot_spec; +static void *g_ctx; +static struct osmo_fd ts_ofd; + +static void process_cmdline(int argc, char **argv) +{ + extern int optind; + extern char *optarg; + int c; + + while ((c = getopt(argc, argv, "p:")) != EOF) { + switch (c) { + case 'p': + e1d_socket_path = optarg; + continue; + default: + usage: + fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 1) + goto usage; + timeslot_spec = argv[optind]; +} + +int main(int argc, char **argv) +{ + process_cmdline(argc, argv); + g_ctx = talloc_named_const(NULL, 0, "g_ctx"); + OSMO_ASSERT(g_ctx); + osmo_init_logging2(g_ctx, NULL); + + g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path); + if (!g_client) { + fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n", + e1d_socket_path); + exit(1); + } + ts_fd = open_e1d_ts(g_client, timeslot_spec); + + osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0); + OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); + + while (1) { + osmo_select_main(0); + } +} diff -r 570252e22630 -r c03ec046471f pcm/read_ts.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/read_ts.c Sun Jun 23 08:35:46 2024 +0000 @@ -0,0 +1,30 @@ +/* + * The function in this module gets called from Osmocom select loop + * whenever the data socket to osmo-e1d is ready for reading. + */ + +#include +#include +#include +#include +#include + +#include + +#include "globals.h" + +uint8_t readbuf[160]; + +int ts_fd_cb(struct osmo_fd *ofd, unsigned int what) +{ + int rc; + + rc = read(ts_fd, readbuf, 160); + if (rc != 160) { + fprintf(stderr, + "error: read from ts returned %d instead of 160\n", + rc); + exit(1); + } + return 0; +}