comparison 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
comparison
equal deleted inserted replaced
44:16715bd149e0 45:349fb785a414
1 /*
2 * Here we implement the command for setting Dn bit patterns
3 * in data-mode TRAU-UL frames.
4 */
5
6 #include <stdint.h>
7 #include <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include <osmocom/core/bits.h>
13 #include <osmocom/core/select.h>
14 #include <osmocom/isdn/i460_mux.h>
15 #include <osmocom/trau/trau_frame.h>
16
17 #include "globals.h"
18 #include "submux.h"
19
20 void cmd_set_dbits(int argc, char **argv)
21 {
22 int nr;
23 struct ater_subslot *at;
24 struct osmo_trau_frame *fr;
25 unsigned d_offset;
26 char *bits;
27
28 if (argc != 4) {
29 usage: fprintf(stderr, "usage: %s 0|1|2|3 D-offset bits\n", argv[0]);
30 return;
31 }
32 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
33 goto usage;
34 nr = argv[1][0] - '0';
35 at = &subslots[nr];
36 if (!at->is_active) {
37 fprintf(stderr, "error: subslot %d is not active\n", nr);
38 return;
39 }
40 if (!at->is_data) {
41 fprintf(stderr, "error: subslot %d is not in data mode\n", nr);
42 return;
43 }
44 fr = &at->ul_frame;
45 d_offset = atoi(argv[2]);
46 if (d_offset >= 252) {
47 fprintf(stderr, "error: specified offset is out of range\n");
48 return;
49 }
50 for (bits = argv[3]; *bits; bits++) {
51 if (*bits < '0' || *bits > '1') {
52 fprintf(stderr, "error: invalid bit string argument\n");
53 return;
54 }
55 if (d_offset >= 252) {
56 fprintf(stderr,
57 "error: given bit string extends past the end of Dn bits\n");
58 return;
59 }
60 fr->d_bits[d_offset++] = *bits - '0';
61 }
62 }