FreeCalypso > hg > ice1-trau-tester
annotate ater/play_cmd.c @ 52:626180a15857 default tip
ater play-d144: emit E-data frames manually,
osmo_trau_frame_encode() is currently broken for this frame type
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 06:40:43 +0000 |
parents | db39e8855f3d |
children |
rev | line source |
---|---|
27
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement user commands controlling file play functionality. |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdint.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdbool.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <osmocom/core/select.h> |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "globals.h" |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "submux.h" |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "read_file.h" |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 void cmd_play_file(int argc, char **argv) |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int nr, rc; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 struct ater_subslot *at; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (argc != 3) { |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 usage: fprintf(stderr, "usage: %s 0|1|2|3 play-file.tul\n", argv[0]); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 goto usage; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 nr = argv[1][0] - '0'; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 at = &subslots[nr]; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!at->is_active) { |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, "error: subslot %d is not active\n", nr); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
44
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
34 if (at->is_data) { |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
35 fprintf(stderr, "error: subslot %d is in data mode\n", nr); |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
36 return; |
16715bd149e0
ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
37 } |
27
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (at->play_buffer) { |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(stderr, "error: file play already in progress\n"); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = read_binary_file(argv[2], at->is_efr, &at->play_buffer, |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 &at->play_buf_total); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return; /* error msg already printed */ |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 at->play_buf_ptr = 0; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 at->play_wait_align = true; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
29
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
49 |
51
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
50 void cmd_play_d144(int argc, char **argv) |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
51 { |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
52 int nr, rc; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
53 struct ater_subslot *at; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
54 |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
55 if (argc != 3) { |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
56 usage: fprintf(stderr, "usage: %s 0|1|2|3 play-file.bin\n", argv[0]); |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
57 return; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
58 } |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
59 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
60 goto usage; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
61 nr = argv[1][0] - '0'; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
62 at = &subslots[nr]; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
63 if (!at->is_active) { |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
64 fprintf(stderr, "error: subslot %d is not active\n", nr); |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
65 return; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
66 } |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
67 if (!at->is_data_144) { |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
68 fprintf(stderr, "error: subslot %d is not in D144 mode\n", nr); |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
69 return; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
70 } |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
71 if (at->play_buffer) { |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
72 fprintf(stderr, "error: file play already in progress\n"); |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
73 return; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
74 } |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
75 rc = read_binary_file_d144(argv[2], &at->play_buffer, |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
76 &at->play_buf_total); |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
77 if (rc < 0) |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
78 return; /* error msg already printed */ |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
79 at->play_buf_ptr = 0; |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
80 } |
db39e8855f3d
ater: implement play-d144
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
81 |
29
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
82 void cmd_play_stop(int argc, char **argv) |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
83 { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
84 int nr; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
85 struct ater_subslot *at; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
86 |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
87 if (argc != 2) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
88 usage: fprintf(stderr, "usage: %s 0|1|2|3\n", argv[0]); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
89 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
90 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
91 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1]) |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
92 goto usage; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
93 nr = argv[1][0] - '0'; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
94 at = &subslots[nr]; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
95 if (!at->is_active) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
96 fprintf(stderr, "error: subslot %d is not active\n", nr); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
97 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
98 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
99 if (!at->play_buffer) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
100 fprintf(stderr, "error: no file play in progress\n"); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
101 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
102 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
103 free(at->play_buffer); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
104 at->play_buffer = NULL; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
105 } |