diff 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
line wrap: on
line diff
--- a/rvinterf/asyncshell/tchplay.c	Sat Jun 11 01:52:51 2016 +0000
+++ b/rvinterf/asyncshell/tchplay.c	Tue Jun 14 01:02:48 2016 +0000
@@ -3,6 +3,7 @@
  */
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>
@@ -15,7 +16,7 @@
 
 extern void async_msg_output();
 
-static FILE *gsm_data_file;
+static FILE *play_file;
 static int queued_frames;
 
 #define	QUEUE_LIMIT	3
@@ -27,30 +28,60 @@
 	printf("%s\n", msg);
 }
 
+static
+decode_hex_digit(ch)
+{
+	if (isdigit(ch))
+		return(ch - '0');
+	else if (isupper(ch))
+		return(ch - 'A' + 10);
+	else
+		return(ch - 'a' + 10);
+}
+
+static
+decode_hex_line(line, bytes)
+	char *line;
+	u_char *bytes;
+{
+	int i;
+
+	for (i = 0; i < 33; i++) {
+		if (!isxdigit(line[0]) || !isxdigit(line[1]))
+			return(-1);
+		bytes[i] = (decode_hex_digit(line[0]) << 4) |
+				decode_hex_digit(line[1]);
+		line += 2;
+	}
+	for (; *line; line++)
+		if (!isspace(*line))
+			return(-1);
+	return(0);
+}
+
 static void
 fill_uplink(msgout)
 	void (*msgout)();
 {
-	u_char readbytes[33], sendpkt[35];
+	char line[80];
+	u_char sendpkt[35];
 	int cc;
 
 	sendpkt[0] = RVT_TCH_HEADER;
 	sendpkt[1] = TCH_ULBITS_REQ;
 	while (queued_frames < QUEUE_LIMIT) {
-		cc = fread(readbytes, 1, 33, gsm_data_file);
-		if (cc < 33) {
-			if (cc)
-			  msgout("TCH UL: extra bytes at the end of the file");
+		if (!fgets(line, sizeof line, play_file)) {
 			msgout("TCH UL: file play finished");
-			gsm_data_file = 0;
+			fclose(play_file);
+			play_file = 0;
 			return;
 		}
-		if ((readbytes[0] & 0xF0) != 0xD0) {
+		if (decode_hex_line(line, sendpkt + 2) < 0) {
 			msgout("TCH UL: bad file input, play aborted");
-			gsm_data_file = 0;
+			fclose(play_file);
+			play_file = 0;
 			return;
 		}
-		gsm0610_libgsm_to_tidsp(readbytes, sendpkt + 2);
 		send_pkt_to_target(sendpkt, 35);
 		queued_frames++;
 	}
@@ -61,7 +92,7 @@
 {
 	if (queued_frames > 0)
 		queued_frames--;
-	if (gsm_data_file)
+	if (play_file)
 		fill_uplink(async_msg_output);
 }
 
@@ -69,12 +100,12 @@
 cmd_tch_play_start(filename)
 	char *filename;
 {
-	if (gsm_data_file) {
+	if (play_file) {
 		printf("error: tch play session already in progress\n");
 		return;
 	}
-	gsm_data_file = fopen(filename, "r");
-	if (!gsm_data_file) {
+	play_file = fopen(filename, "r");
+	if (!play_file) {
 		perror(filename);
 		return;
 	}
@@ -86,12 +117,12 @@
 static void
 cmd_tch_play_stop()
 {
-	if (!gsm_data_file) {
+	if (!play_file) {
 		printf("error: no tch play session in progress\n");
 		return;
 	}
-	fclose(gsm_data_file);
-	gsm_data_file = 0;
+	fclose(play_file);
+	play_file = 0;
 	printf("TCH UL play from file terminated\n");
 }
 
@@ -113,6 +144,6 @@
 show_tch_play_status()
 {
 	printf("TCH UL play from file: %s\n",
-		gsm_data_file ? "RUNNING" : "not running");
+		play_file ? "RUNNING" : "not running");
 	printf("Outstanding UL frames: %d\n", queued_frames);
 }