FreeCalypso > hg > ice1-trau-tester
annotate ater/activate.c @ 44:16715bd149e0
ater: add support for data mode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 12 Sep 2024 09:01:50 +0000 |
parents | 237687e2be6c |
children | 13fffc41f989 |
rev | line source |
---|---|
24
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement the operation of activating a new TRAU channel |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * on a sub-timeslot. |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdbool.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/select.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/isdn/i460_mux.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <osmocom/trau/trau_frame.h> |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "globals.h" |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "submux.h" |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "read_file.h" |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "out_frame.h" |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 void cmd_activate(int argc, char **argv) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int nr, rc; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 bool is_efr, dtxd; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 struct ater_subslot *at; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 uint8_t *init_frame; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned init_frame_count; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (argc < 4 || argc > 5) { |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 usage: fprintf(stderr, |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 "usage: %s 0|1|2|3 fr|efr initial-frame.tul [dtxd]\n", |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 argv[0]); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 goto usage; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 nr = argv[1][0] - '0'; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (!strcmp(argv[2], "fr")) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 is_efr = false; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 else if (!strcmp(argv[2], "efr")) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 is_efr = true; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 else |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 goto usage; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (argv[4]) { |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (strcmp(argv[4], "dtxd")) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 goto usage; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 dtxd = true; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } else |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 dtxd = false; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 at = &subslots[nr]; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (at->is_active) { |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "error: subslot %d is already active\n", nr); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 rc = read_binary_file(argv[3], is_efr, &init_frame, &init_frame_count); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (rc < 0) |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return; /* error msg already printed */ |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (init_frame_count != 1) { |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 free(init_frame); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, "error: %s contains more than one frame\n", |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 argv[3]); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 return; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 /* good to proceed now */ |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 at->is_active = true; |
44
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
68 at->is_data = false; |
24
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 at->is_efr = is_efr; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 init_trau_ul_frame(nr); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 at->ul_frame.c_bits[16] = dtxd; |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 trau_frame_from_record(init_frame, is_efr, &at->ul_frame); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 free(init_frame); |
f49e57b0d1a2
ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
25
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
75 |
44
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
76 void cmd_activate_csd(int argc, char **argv) |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
77 { |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
78 int nr; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
79 bool ir_16k; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
80 struct ater_subslot *at; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
81 |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
82 if (argc != 3) { |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
83 usage: fprintf(stderr, "usage: %s 0|1|2|3 8|16\n", argv[0]); |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
84 return; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
85 } |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
86 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
87 goto usage; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
88 nr = argv[1][0] - '0'; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
89 if (!strcmp(argv[2], "8")) |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
90 ir_16k = false; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
91 else if (!strcmp(argv[2], "16")) |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
92 ir_16k = true; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
93 else |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
94 goto usage; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
95 |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
96 at = &subslots[nr]; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
97 if (at->is_active) { |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
98 fprintf(stderr, "error: subslot %d is already active\n", nr); |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
99 return; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
100 } |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
101 |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
102 /* good to proceed now */ |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
103 at->is_active = true; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
104 at->is_data = true; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
105 init_trau_ul_frame_csd(nr, ir_16k); |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
106 } |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
107 |
25
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
108 void cmd_deact(int argc, char **argv) |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
109 { |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
110 int nr; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
111 struct ater_subslot *at; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
112 |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
113 if (argc != 2) { |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
114 usage: fprintf(stderr, "usage: %s 0|1|2|3\n", argv[0]); |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
115 return; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
116 } |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
117 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
118 goto usage; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
119 nr = argv[1][0] - '0'; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
120 at = &subslots[nr]; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
121 if (!at->is_active) { |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
122 fprintf(stderr, "error: subslot %d is not active\n", nr); |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
123 return; |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
124 } |
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
125 at->is_active = false; |
26
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
25
diff
changeset
|
126 if (at->play_buffer) { |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
25
diff
changeset
|
127 free(at->play_buffer); |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
25
diff
changeset
|
128 at->play_buffer = NULL; |
237687e2be6c
ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents:
25
diff
changeset
|
129 } |
25
45411b72b6b3
ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
130 } |