annotate ater8/activate.c @ 51:db39e8855f3d

ater: implement play-d144
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 05:53:38 +0000
parents 3cc26391d24d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
24 bool dtxd;
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct ater_subslot *at;
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
26 int16_t *init_frame;
24
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
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
29 if (argc < 3 || argc > 4) {
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
30 usage: fprintf(stderr, "usage: %s 0-7 initial-frame.dec [dtxd]\n",
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 argv[0]);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
34 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 goto usage;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 nr = argv[1][0] - '0';
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
37 if (argv[3]) {
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
38 if (strcmp(argv[3], "dtxd"))
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 goto usage;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 dtxd = true;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 } else
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 dtxd = false;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 at = &subslots[nr];
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (at->is_active) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr, "error: subslot %d is already active\n", nr);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
49 rc = read_binary_file(argv[2], &init_frame, &init_frame_count);
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc < 0)
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return; /* error msg already printed */
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (init_frame_count != 1) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 free(init_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fprintf(stderr, "error: %s contains more than one frame\n",
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
55 argv[2]);
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* good to proceed now */
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 at->is_active = true;
48
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
61 at->is_data = false;
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 init_trau_ul_frame(nr);
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
63 at->ul_frame.c_bits[8] = dtxd;
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
64 trau_frame_from_record(init_frame, &at->ul_frame, &at->frame_has_taf);
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 free(init_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
67
48
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
68 void cmd_activate_csd(int argc, char **argv)
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
69 {
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
70 int nr;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
71 struct ater_subslot *at;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
72
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
73 if (argc != 2) {
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
74 usage: fprintf(stderr, "usage: %s 0-7\n", argv[0]);
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
75 return;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
76 }
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
77 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
78 goto usage;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
79 nr = argv[1][0] - '0';
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
80
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
81 at = &subslots[nr];
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
82 if (at->is_active) {
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
83 fprintf(stderr, "error: subslot %d is already active\n", nr);
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
84 return;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
85 }
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
86
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
87 /* good to proceed now */
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
88 at->is_active = true;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
89 at->is_data = true;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
90 }
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
91
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
92 void cmd_deact(int argc, char **argv)
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
93 {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
94 int nr;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
95 struct ater_subslot *at;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
96
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
97 if (argc != 2) {
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
98 usage: fprintf(stderr, "usage: %s 0-7\n", argv[0]);
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
99 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
100 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
101 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
102 goto usage;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
103 nr = argv[1][0] - '0';
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
104 at = &subslots[nr];
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
105 if (!at->is_active) {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
106 fprintf(stderr, "error: subslot %d is not active\n", nr);
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
107 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
108 }
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
109 at->is_active = false;
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
110 if (at->play_buffer) {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
111 free(at->play_buffer);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
112 at->play_buffer = NULL;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
113 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
114 }