view pcm-br/xconn.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/read_ts.c@ca351324187a
children
line wrap: on
line source

/*
 * The two functions in this module get called from Osmocom select loop
 * whenever each timeslot data socket to osmo-e1d is ready for reading;
 * the cross-connect of the two timeslots is implemented here.
 */

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <osmocom/core/select.h>

#include "globals.h"

uint8_t readbuf_a[160], readbuf_b[160];
FILE *rec_file_a, *rec_file_b;

int tsa_fd_cb(struct osmo_fd *ofd, unsigned int what)
{
	int rc;

	rc = read(tsa_fd, readbuf_a, 160);
	if (rc != 160) {
		fprintf(stderr,
			"error: read from ts A returned %d instead of 160\n",
			rc);
		exit(1);
	}
	if (rec_file_a)
		fwrite(readbuf_a, 1, 160, rec_file_a);
	write(tsb_fd, readbuf_a, 160);
	return 0;
}

int tsb_fd_cb(struct osmo_fd *ofd, unsigned int what)
{
	int rc;

	rc = read(tsb_fd, readbuf_b, 160);
	if (rc != 160) {
		fprintf(stderr,
			"error: read from ts B returned %d instead of 160\n",
			rc);
		exit(1);
	}
	if (rec_file_b)
		fwrite(readbuf_b, 1, 160, rec_file_b);
	write(tsa_fd, readbuf_b, 160);
	return 0;
}