comparison rvinterf/asyncshell/tchplay.c @ 0:e7502631a0f9

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