changeset 45:349fb785a414

ater: add dset command for setting Dn bits
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 09:33:55 +0000
parents 16715bd149e0
children 12415d7ce262
files ater/Makefile ater/dbits.c ater/globals.h ater/user_cmd.c
diffstat 4 files changed, 65 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ater/Makefile	Thu Sep 12 09:01:50 2024 +0000
+++ b/ater/Makefile	Thu Sep 12 09:33:55 2024 +0000
@@ -1,5 +1,5 @@
 PROG=	itt-ater-16
-OBJS=	activate.o main.o out_frame.o play_cmd.o read_file.o read_ts.o \
+OBJS=	activate.o dbits.o main.o out_frame.o play_cmd.o read_file.o read_ts.o \
 	record_ctrl.o subslot_rx.o tx_func.o user_cmd.o
 HDRS=	globals.h out_frame.h read_file.h submux.h
 LIBUTIL=../libutil/libutil.a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ater/dbits.c	Thu Sep 12 09:33:55 2024 +0000
@@ -0,0 +1,62 @@
+/*
+ * Here we implement the command for setting Dn bit patterns
+ * in data-mode TRAU-UL frames.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/select.h>
+#include <osmocom/isdn/i460_mux.h>
+#include <osmocom/trau/trau_frame.h>
+
+#include "globals.h"
+#include "submux.h"
+
+void cmd_set_dbits(int argc, char **argv)
+{
+	int nr;
+	struct ater_subslot *at;
+	struct osmo_trau_frame *fr;
+	unsigned d_offset;
+	char *bits;
+
+	if (argc != 4) {
+usage:		fprintf(stderr, "usage: %s 0|1|2|3 D-offset bits\n", argv[0]);
+		return;
+	}
+	if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
+		goto usage;
+	nr = argv[1][0] - '0';
+	at = &subslots[nr];
+	if (!at->is_active) {
+		fprintf(stderr, "error: subslot %d is not active\n", nr);
+		return;
+	}
+	if (!at->is_data) {
+		fprintf(stderr, "error: subslot %d is not in data mode\n", nr);
+		return;
+	}
+	fr = &at->ul_frame;
+	d_offset = atoi(argv[2]);
+	if (d_offset >= 252) {
+		fprintf(stderr, "error: specified offset is out of range\n");
+		return;
+	}
+	for (bits = argv[3]; *bits; bits++) {
+		if (*bits < '0' || *bits > '1') {
+			fprintf(stderr, "error: invalid bit string argument\n");
+			return;
+		}
+		if (d_offset >= 252) {
+			fprintf(stderr,
+		"error: given bit string extends past the end of Dn bits\n");
+			return;
+		}
+		fr->d_bits[d_offset++] = *bits - '0';
+	}
+}
--- a/ater/globals.h	Thu Sep 12 09:01:50 2024 +0000
+++ b/ater/globals.h	Thu Sep 12 09:33:55 2024 +0000
@@ -21,3 +21,4 @@
 void cmd_deact(int argc, char **argv);
 void cmd_play_file(int argc, char **argv);
 void cmd_play_stop(int argc, char **argv);
+void cmd_set_dbits(int argc, char **argv);
--- a/ater/user_cmd.c	Thu Sep 12 09:01:50 2024 +0000
+++ b/ater/user_cmd.c	Thu Sep 12 09:33:55 2024 +0000
@@ -20,6 +20,7 @@
 	{"activ", cmd_activate},
 	{"activ-d", cmd_activate_csd},
 	{"deact", cmd_deact},
+	{"dset", cmd_set_dbits},
 	{"play", cmd_play_file},
 	{"play-stop", cmd_play_stop},
 	{"print-rx", cmd_print_rx},