FreeCalypso > hg > ice1-trau-tester
annotate ater/play_cmd.c @ 41:50a72d4ff498
top Makefile: add libhr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 16:42:50 +0000 |
parents | 1dda11905e85 |
children | 16715bd149e0 |
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 } |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (at->play_buffer) { |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, "error: file play already in progress\n"); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 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
|
39 &at->play_buf_total); |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (rc < 0) |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return; /* error msg already printed */ |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 at->play_buf_ptr = 0; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 at->play_wait_align = true; |
2742dbea95f1
ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
29
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
45 |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
46 void cmd_play_stop(int argc, char **argv) |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
47 { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
48 int nr; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
49 struct ater_subslot *at; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
50 |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
51 if (argc != 2) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
52 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
|
53 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
54 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
55 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
|
56 goto usage; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
57 nr = argv[1][0] - '0'; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
58 at = &subslots[nr]; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
59 if (!at->is_active) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
60 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
|
61 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
62 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
63 if (!at->play_buffer) { |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
64 fprintf(stderr, "error: no file play in progress\n"); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
65 return; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
66 } |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
67 free(at->play_buffer); |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
68 at->play_buffer = NULL; |
1dda11905e85
ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
69 } |