annotate rvinterf/asyncshell/tchplay.c @ 1030:194967e11b2b

fc-shell: tch record and tch play reworked for libgsm-compatible file format
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 31 May 2016 18:39:06 +0000
parents 333015c662bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1029
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * TCH uplink play-from-file functionality
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "pktmux.h"
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "tch_feature.h"
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern u_char rvi_msg[];
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int rvi_msg_len;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern void async_msg_output();
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static FILE *gsm_data_file;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static int queued_frames;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define QUEUE_LIMIT 3
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 sync_msgout(msg)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *msg;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 printf("%s\n", msg);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 fill_uplink(msgout)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 void (*msgout)();
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
1030
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
34 u_char readbytes[33], sendpkt[35];
1029
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 int cc;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 sendpkt[0] = RVT_TCH_HEADER;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 sendpkt[1] = TCH_ULBITS_REQ;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 while (queued_frames < QUEUE_LIMIT) {
1030
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
40 cc = fread(readbytes, 1, 33, gsm_data_file);
1029
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (cc < 33) {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (cc)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 msgout("TCH UL: extra bytes at the end of the file");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 msgout("TCH UL: file play finished");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 gsm_data_file = 0;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
1030
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
48 if ((readbytes[0] & 0xF0) != 0xD0) {
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
49 msgout("TCH UL: bad file input, play aborted");
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
50 gsm_data_file = 0;
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
51 return;
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
52 }
194967e11b2b fc-shell: tch record and tch play reworked for libgsm-compatible file format
Mychaela Falconia <falcon@freecalypso.org>
parents: 1029
diff changeset
53 gsm0610_libgsm_to_tidsp(readbytes, sendpkt + 2);
1029
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 send_pkt_to_target(sendpkt, 35);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 queued_frames++;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 tch_ulbits_conf()
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (queued_frames > 0)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 queued_frames--;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (gsm_data_file)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fill_uplink(async_msg_output);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 static void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 cmd_tch_play_start(filename)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 char *filename;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (gsm_data_file) {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 printf("error: tch play session already in progress\n");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 gsm_data_file = fopen(filename, "r");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (!gsm_data_file) {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 perror(filename);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 printf("Starting TCH UL play from file\n");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 tch_rx_control(1);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fill_uplink(sync_msgout);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 static void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 cmd_tch_play_stop()
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (!gsm_data_file) {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 printf("error: no tch play session in progress\n");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 return;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 fclose(gsm_data_file);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 gsm_data_file = 0;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 printf("TCH UL play from file terminated\n");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 cmd_tch_play(argc, argv)
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 char **argv;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (argc < 2) {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 printf("error: too few arguments\n");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return;
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (strcmp(argv[1], "stop"))
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cmd_tch_play_start(argv[1]);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 else
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 cmd_tch_play_stop();
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 void
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 show_tch_play_status()
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 {
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 printf("TCH UL play from file: %s\n",
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 gsm_data_file ? "RUNNING" : "not running");
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 printf("Outstanding UL frames: %d\n", queued_frames);
333015c662bc fc-shell: tch play implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }