annotate ater/play_cmd.c @ 44:16715bd149e0

ater: add support for data mode
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 09:01:50 +0000
parents 1dda11905e85
children db39e8855f3d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
50 void cmd_play_stop(int argc, char **argv)
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
51 {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
52 int nr;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
53 struct ater_subslot *at;
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 (argc != 2) {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
56 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
57 return;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
58 }
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
59 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
60 goto usage;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
61 nr = argv[1][0] - '0';
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
62 at = &subslots[nr];
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
63 if (!at->is_active) {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
64 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
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 if (!at->play_buffer) {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
68 fprintf(stderr, "error: no file play in progress\n");
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
69 return;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
70 }
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
71 free(at->play_buffer);
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
72 at->play_buffer = NULL;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
73 }