diff abis/subslot_rx.c @ 33:351bd801cdce

abis: should be complete now
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Aug 2024 22:53:42 +0000
parents 94f11dc0d474
children
line wrap: on
line diff
--- a/abis/subslot_rx.c	Tue Aug 13 22:07:49 2024 +0000
+++ b/abis/subslot_rx.c	Tue Aug 13 22:53:42 2024 +0000
@@ -9,6 +9,7 @@
 #include <string.h>
 
 #include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
 #include <osmocom/isdn/i460_mux.h>
 #include <osmocom/trau/trau_sync.h>
 
@@ -23,9 +24,49 @@
 	osmo_trau_sync_rx_ubits(ab->sync, bits, num_bits);
 }
 
+static void sync_lost(struct abis_subslot *ab)
+{
+	if (!ab->got_sync)
+		return;
+	printf("Subslot %d lost frame sync\n", ab->nr);
+	ab->got_sync = false;
+}
+
+/* function copied from libosmo-abis/src/trau/trau_frame.c */
+static uint32_t get_bits(const ubit_t *bitbuf, int offset, int num)
+{
+	int i;
+	uint32_t ret = 0;
+
+	for (i = offset; i < offset + num; i++) {
+		ret = ret << 1;
+		if (bitbuf[i])
+			ret |= 1;
+	}
+	return ret;
+}
+
 void sync_rx_func(void *user_data, const ubit_t *bits, unsigned int num_bits)
 {
 	struct abis_subslot *ab = user_data;
-
+	uint8_t ft;
 
+	if (!bits) {
+		sync_lost(ab);
+		return;
+	}
+	OSMO_ASSERT(num_bits == 320);
+	ft = get_bits(bits, 17, 5);
+	if (!ab->got_sync) {
+		printf("Subslot %d got frame sync with FT=0x%02X\n",
+			ab->nr, ft);
+		ab->got_sync = true;
+		ab->frame_type = ft;
+		return;
+	}
+	if (ft == ab->frame_type)
+		return;
+	printf("Subslot %d changed frame type from 0x%02X to 0x%02X\n", ab->nr,
+		ab->frame_type, ft);
+	ab->frame_type = ft;
 }