diff abis/read_ts.c @ 30:5dd30224b70a

abis: starting new program
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Aug 2024 21:38:55 +0000
parents ater/read_ts.c@61862af2247f
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/abis/read_ts.c	Tue Aug 13 21:38:55 2024 +0000
@@ -0,0 +1,36 @@
+/*
+ * The function in this module gets called from Osmocom select loop
+ * whenever the data socket to osmo-e1d is ready for reading.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/isdn/i460_mux.h>
+
+#include "globals.h"
+
+uint8_t readbuf[160];
+FILE *record_file;
+
+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);
+	}
+	if (record_file)
+		fwrite(readbuf, 1, 160, record_file);
+	osmo_i460_demux_in(&i460_ts, readbuf, 160);
+	transmit_e1_ts();
+	return 0;
+}