FreeCalypso > hg > freecalypso-tools
comparison rvinterf/asyncshell/tchplay.c @ 4:971906d7763d
fc-shell tch commands: changed to raw hex file format
This "backward" change is needed for two reasons:
1) to support EFR in addition to 06.10
2) to preserve the DSP status words for the downlink
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 14 Jun 2016 01:02:48 +0000 |
parents | e7502631a0f9 |
children |
comparison
equal
deleted
inserted
replaced
3:6a029ad28212 | 4:971906d7763d |
---|---|
1 /* | 1 /* |
2 * TCH uplink play-from-file functionality | 2 * TCH uplink play-from-file functionality |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <ctype.h> | |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 #include <string.h> | 8 #include <string.h> |
8 #include <strings.h> | 9 #include <strings.h> |
9 #include <stdlib.h> | 10 #include <stdlib.h> |
10 #include "pktmux.h" | 11 #include "pktmux.h" |
13 extern u_char rvi_msg[]; | 14 extern u_char rvi_msg[]; |
14 extern int rvi_msg_len; | 15 extern int rvi_msg_len; |
15 | 16 |
16 extern void async_msg_output(); | 17 extern void async_msg_output(); |
17 | 18 |
18 static FILE *gsm_data_file; | 19 static FILE *play_file; |
19 static int queued_frames; | 20 static int queued_frames; |
20 | 21 |
21 #define QUEUE_LIMIT 3 | 22 #define QUEUE_LIMIT 3 |
22 | 23 |
23 static void | 24 static void |
25 char *msg; | 26 char *msg; |
26 { | 27 { |
27 printf("%s\n", msg); | 28 printf("%s\n", msg); |
28 } | 29 } |
29 | 30 |
31 static | |
32 decode_hex_digit(ch) | |
33 { | |
34 if (isdigit(ch)) | |
35 return(ch - '0'); | |
36 else if (isupper(ch)) | |
37 return(ch - 'A' + 10); | |
38 else | |
39 return(ch - 'a' + 10); | |
40 } | |
41 | |
42 static | |
43 decode_hex_line(line, bytes) | |
44 char *line; | |
45 u_char *bytes; | |
46 { | |
47 int i; | |
48 | |
49 for (i = 0; i < 33; i++) { | |
50 if (!isxdigit(line[0]) || !isxdigit(line[1])) | |
51 return(-1); | |
52 bytes[i] = (decode_hex_digit(line[0]) << 4) | | |
53 decode_hex_digit(line[1]); | |
54 line += 2; | |
55 } | |
56 for (; *line; line++) | |
57 if (!isspace(*line)) | |
58 return(-1); | |
59 return(0); | |
60 } | |
61 | |
30 static void | 62 static void |
31 fill_uplink(msgout) | 63 fill_uplink(msgout) |
32 void (*msgout)(); | 64 void (*msgout)(); |
33 { | 65 { |
34 u_char readbytes[33], sendpkt[35]; | 66 char line[80]; |
67 u_char sendpkt[35]; | |
35 int cc; | 68 int cc; |
36 | 69 |
37 sendpkt[0] = RVT_TCH_HEADER; | 70 sendpkt[0] = RVT_TCH_HEADER; |
38 sendpkt[1] = TCH_ULBITS_REQ; | 71 sendpkt[1] = TCH_ULBITS_REQ; |
39 while (queued_frames < QUEUE_LIMIT) { | 72 while (queued_frames < QUEUE_LIMIT) { |
40 cc = fread(readbytes, 1, 33, gsm_data_file); | 73 if (!fgets(line, sizeof line, play_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"); | 74 msgout("TCH UL: file play finished"); |
45 gsm_data_file = 0; | 75 fclose(play_file); |
76 play_file = 0; | |
46 return; | 77 return; |
47 } | 78 } |
48 if ((readbytes[0] & 0xF0) != 0xD0) { | 79 if (decode_hex_line(line, sendpkt + 2) < 0) { |
49 msgout("TCH UL: bad file input, play aborted"); | 80 msgout("TCH UL: bad file input, play aborted"); |
50 gsm_data_file = 0; | 81 fclose(play_file); |
82 play_file = 0; | |
51 return; | 83 return; |
52 } | 84 } |
53 gsm0610_libgsm_to_tidsp(readbytes, sendpkt + 2); | |
54 send_pkt_to_target(sendpkt, 35); | 85 send_pkt_to_target(sendpkt, 35); |
55 queued_frames++; | 86 queued_frames++; |
56 } | 87 } |
57 } | 88 } |
58 | 89 |
59 void | 90 void |
60 tch_ulbits_conf() | 91 tch_ulbits_conf() |
61 { | 92 { |
62 if (queued_frames > 0) | 93 if (queued_frames > 0) |
63 queued_frames--; | 94 queued_frames--; |
64 if (gsm_data_file) | 95 if (play_file) |
65 fill_uplink(async_msg_output); | 96 fill_uplink(async_msg_output); |
66 } | 97 } |
67 | 98 |
68 static void | 99 static void |
69 cmd_tch_play_start(filename) | 100 cmd_tch_play_start(filename) |
70 char *filename; | 101 char *filename; |
71 { | 102 { |
72 if (gsm_data_file) { | 103 if (play_file) { |
73 printf("error: tch play session already in progress\n"); | 104 printf("error: tch play session already in progress\n"); |
74 return; | 105 return; |
75 } | 106 } |
76 gsm_data_file = fopen(filename, "r"); | 107 play_file = fopen(filename, "r"); |
77 if (!gsm_data_file) { | 108 if (!play_file) { |
78 perror(filename); | 109 perror(filename); |
79 return; | 110 return; |
80 } | 111 } |
81 printf("Starting TCH UL play from file\n"); | 112 printf("Starting TCH UL play from file\n"); |
82 tch_rx_control(1); | 113 tch_rx_control(1); |
84 } | 115 } |
85 | 116 |
86 static void | 117 static void |
87 cmd_tch_play_stop() | 118 cmd_tch_play_stop() |
88 { | 119 { |
89 if (!gsm_data_file) { | 120 if (!play_file) { |
90 printf("error: no tch play session in progress\n"); | 121 printf("error: no tch play session in progress\n"); |
91 return; | 122 return; |
92 } | 123 } |
93 fclose(gsm_data_file); | 124 fclose(play_file); |
94 gsm_data_file = 0; | 125 play_file = 0; |
95 printf("TCH UL play from file terminated\n"); | 126 printf("TCH UL play from file terminated\n"); |
96 } | 127 } |
97 | 128 |
98 void | 129 void |
99 cmd_tch_play(argc, argv) | 130 cmd_tch_play(argc, argv) |
111 | 142 |
112 void | 143 void |
113 show_tch_play_status() | 144 show_tch_play_status() |
114 { | 145 { |
115 printf("TCH UL play from file: %s\n", | 146 printf("TCH UL play from file: %s\n", |
116 gsm_data_file ? "RUNNING" : "not running"); | 147 play_file ? "RUNNING" : "not running"); |
117 printf("Outstanding UL frames: %d\n", queued_frames); | 148 printf("Outstanding UL frames: %d\n", queued_frames); |
118 } | 149 } |