annotate ater/activate.c @ 41:50a72d4ff498

top Makefile: add libhr
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 16:42:50 +0000
parents 237687e2be6c
children 16715bd149e0
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;
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;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 at->is_efr = is_efr;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 init_trau_ul_frame(nr);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 at->ul_frame.c_bits[16] = dtxd;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 trau_frame_from_record(init_frame, is_efr, &at->ul_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 free(init_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
74
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
75 void cmd_deact(int argc, char **argv)
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
76 {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
77 int nr;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
78 struct ater_subslot *at;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
79
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
80 if (argc != 2) {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
81 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
82 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
83 }
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
84 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
85 goto usage;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
86 nr = argv[1][0] - '0';
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
87 at = &subslots[nr];
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
88 if (!at->is_active) {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
89 fprintf(stderr, "error: subslot %d is not active\n", nr);
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
90 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
91 }
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
92 at->is_active = false;
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
93 if (at->play_buffer) {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
94 free(at->play_buffer);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
95 at->play_buffer = NULL;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
96 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
97 }