FreeCalypso > hg > ice1-trau-tester
diff ater/dbits.c @ 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 | |
children | 40f781efdbe1 |
line wrap: on
line diff
--- /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'; + } +}