comparison ater8/activate.c @ 42:ff94d7fc5891

new program itt-ater-8
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 19:02:42 +0000
parents ater/activate.c@237687e2be6c
children 3cc26391d24d
comparison
equal deleted inserted replaced
41:50a72d4ff498 42:ff94d7fc5891
1 /*
2 * Here we implement the operation of activating a new TRAU channel
3 * on a sub-timeslot.
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/select.h>
13 #include <osmocom/isdn/i460_mux.h>
14 #include <osmocom/trau/trau_frame.h>
15
16 #include "globals.h"
17 #include "submux.h"
18 #include "read_file.h"
19 #include "out_frame.h"
20
21 void cmd_activate(int argc, char **argv)
22 {
23 int nr, rc;
24 bool dtxd;
25 struct ater_subslot *at;
26 int16_t *init_frame;
27 unsigned init_frame_count;
28
29 if (argc < 3 || argc > 4) {
30 usage: fprintf(stderr, "usage: %s 0-7 initial-frame.dec [dtxd]\n",
31 argv[0]);
32 return;
33 }
34 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
35 goto usage;
36 nr = argv[1][0] - '0';
37 if (argv[3]) {
38 if (strcmp(argv[3], "dtxd"))
39 goto usage;
40 dtxd = true;
41 } else
42 dtxd = false;
43
44 at = &subslots[nr];
45 if (at->is_active) {
46 fprintf(stderr, "error: subslot %d is already active\n", nr);
47 return;
48 }
49 rc = read_binary_file(argv[2], &init_frame, &init_frame_count);
50 if (rc < 0)
51 return; /* error msg already printed */
52 if (init_frame_count != 1) {
53 free(init_frame);
54 fprintf(stderr, "error: %s contains more than one frame\n",
55 argv[2]);
56 return;
57 }
58
59 /* good to proceed now */
60 at->is_active = true;
61 init_trau_ul_frame(nr);
62 at->ul_frame.c_bits[8] = dtxd;
63 trau_frame_from_record(init_frame, &at->ul_frame, &at->frame_has_taf);
64 free(init_frame);
65 }
66
67 void cmd_deact(int argc, char **argv)
68 {
69 int nr;
70 struct ater_subslot *at;
71
72 if (argc != 2) {
73 usage: fprintf(stderr, "usage: %s 0-7\n", argv[0]);
74 return;
75 }
76 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
77 goto usage;
78 nr = argv[1][0] - '0';
79 at = &subslots[nr];
80 if (!at->is_active) {
81 fprintf(stderr, "error: subslot %d is not active\n", nr);
82 return;
83 }
84 at->is_active = false;
85 if (at->play_buffer) {
86 free(at->play_buffer);
87 at->play_buffer = NULL;
88 }
89 }