FreeCalypso > hg > freecalypso-sw
comparison rvinterf/asyncshell/tchplay.c @ 1029:333015c662bc
fc-shell: tch play implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 31 May 2016 01:53:04 +0000 |
parents | |
children | 194967e11b2b |
comparison
equal
deleted
inserted
replaced
1028:71bbddbcc6a1 | 1029:333015c662bc |
---|---|
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 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(sendpkt + 2, 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 send_pkt_to_target(sendpkt, 35); | |
49 queued_frames++; | |
50 } | |
51 } | |
52 | |
53 void | |
54 tch_ulbits_conf() | |
55 { | |
56 if (queued_frames > 0) | |
57 queued_frames--; | |
58 if (gsm_data_file) | |
59 fill_uplink(async_msg_output); | |
60 } | |
61 | |
62 static void | |
63 cmd_tch_play_start(filename) | |
64 char *filename; | |
65 { | |
66 if (gsm_data_file) { | |
67 printf("error: tch play session already in progress\n"); | |
68 return; | |
69 } | |
70 gsm_data_file = fopen(filename, "r"); | |
71 if (!gsm_data_file) { | |
72 perror(filename); | |
73 return; | |
74 } | |
75 printf("Starting TCH UL play from file\n"); | |
76 tch_rx_control(1); | |
77 fill_uplink(sync_msgout); | |
78 } | |
79 | |
80 static void | |
81 cmd_tch_play_stop() | |
82 { | |
83 if (!gsm_data_file) { | |
84 printf("error: no tch play session in progress\n"); | |
85 return; | |
86 } | |
87 fclose(gsm_data_file); | |
88 gsm_data_file = 0; | |
89 printf("TCH UL play from file terminated\n"); | |
90 } | |
91 | |
92 void | |
93 cmd_tch_play(argc, argv) | |
94 char **argv; | |
95 { | |
96 if (argc < 2) { | |
97 printf("error: too few arguments\n"); | |
98 return; | |
99 } | |
100 if (strcmp(argv[1], "stop")) | |
101 cmd_tch_play_start(argv[1]); | |
102 else | |
103 cmd_tch_play_stop(); | |
104 } | |
105 | |
106 void | |
107 show_tch_play_status() | |
108 { | |
109 printf("TCH UL play from file: %s\n", | |
110 gsm_data_file ? "RUNNING" : "not running"); | |
111 printf("Outstanding UL frames: %d\n", queued_frames); | |
112 } |