FreeCalypso > hg > ice1-trau-tester
annotate ater/dbits.c @ 49:40f781efdbe1
ater: beginning of D144 mode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 24 Sep 2024 05:59:28 +0000 |
parents | 349fb785a414 |
children |
rev | line source |
---|---|
45
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement the command for setting Dn bit patterns |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * in data-mode TRAU-UL frames. |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdbool.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/bits.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/core/select.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <osmocom/isdn/i460_mux.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <osmocom/trau/trau_frame.h> |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "globals.h" |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "submux.h" |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 void cmd_set_dbits(int argc, char **argv) |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int nr; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 struct ater_subslot *at; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct osmo_trau_frame *fr; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned d_offset; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 char *bits; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (argc != 4) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 usage: fprintf(stderr, "usage: %s 0|1|2|3 D-offset bits\n", argv[0]); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 goto usage; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 nr = argv[1][0] - '0'; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 at = &subslots[nr]; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!at->is_active) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fprintf(stderr, "error: subslot %d is not active\n", nr); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (!at->is_data) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, "error: subslot %d is not in data mode\n", nr); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
49
40f781efdbe1
ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
44 if (at->is_data_144) { |
40f781efdbe1
ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
45 fprintf(stderr, "error: subslot %d is in D144 mode\n", nr); |
40f781efdbe1
ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
46 return; |
40f781efdbe1
ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
45
diff
changeset
|
47 } |
45
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fr = &at->ul_frame; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 d_offset = atoi(argv[2]); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (d_offset >= 252) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(stderr, "error: specified offset is out of range\n"); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 for (bits = argv[3]; *bits; bits++) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (*bits < '0' || *bits > '1') { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fprintf(stderr, "error: invalid bit string argument\n"); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (d_offset >= 252) { |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fprintf(stderr, |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 "error: given bit string extends past the end of Dn bits\n"); |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 fr->d_bits[d_offset++] = *bits - '0'; |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
349fb785a414
ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |