annotate ater8/play_cmd.c @ 48:3cc26391d24d

ater8: add support for data mode
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Sep 2024 01:03:43 +0000
parents ff94d7fc5891
children
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) {
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
23 usage: fprintf(stderr, "usage: %s 0-7 play-file.dec\n", argv[0]);
27
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 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
26 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
27
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 }
48
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
34 if (at->is_data) {
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
35 fprintf(stderr, "error: subslot %d is in data mode\n", nr);
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
diff changeset
36 return;
3cc26391d24d ater8: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 42
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 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
42 rc = read_binary_file(argv[2], &at->play_buffer, &at->play_buf_total);
27
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0)
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return; /* error msg already printed */
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 at->play_buf_ptr = 0;
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 at->play_wait_align = true;
2742dbea95f1 ater: implement play command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
29
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
48
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
49 void cmd_play_stop(int argc, char **argv)
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 int nr;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
52 struct ater_subslot *at;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
53
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
54 if (argc != 2) {
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
55 usage: fprintf(stderr, "usage: %s 0-7\n", argv[0]);
29
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
56 return;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
57 }
42
ff94d7fc5891 new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
58 if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
29
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
59 goto usage;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
60 nr = argv[1][0] - '0';
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
61 at = &subslots[nr];
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
62 if (!at->is_active) {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
63 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
64 return;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
65 }
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
66 if (!at->play_buffer) {
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
67 fprintf(stderr, "error: no file play in progress\n");
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
68 return;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
69 }
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
70 free(at->play_buffer);
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
71 at->play_buffer = NULL;
1dda11905e85 ater: implement play-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
72 }