view ater/dbits.c @ 52:626180a15857 default tip

ater play-d144: emit E-data frames manually, osmo_trau_frame_encode() is currently broken for this frame type
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 06:40:43 +0000
parents 40f781efdbe1
children
line wrap: on
line source

/*
 * 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;
	}
	if (at->is_data_144) {
		fprintf(stderr, "error: subslot %d is in D144 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';
	}
}