changeset 1029:333015c662bc

fc-shell: tch play implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 31 May 2016 01:53:04 +0000
parents 71bbddbcc6a1
children 194967e11b2b
files rvinterf/asyncshell/Makefile rvinterf/asyncshell/tchcmd.c rvinterf/asyncshell/tchplay.c
diffstat 3 files changed, 121 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/asyncshell/Makefile	Tue May 31 00:43:00 2016 +0000
+++ b/rvinterf/asyncshell/Makefile	Tue May 31 01:53:04 2016 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2 -I../include
 PROG=	fc-shell
 OBJS=	at.o init.o main.o oneshot.o parse.o pktsort.o poweroff.o rxctl.o \
-	sendarb.o sendsp.o tchcmd.o tchrec.o usercmd.o
+	sendarb.o sendsp.o tchcmd.o tchplay.o tchrec.o usercmd.o
 LIBS=	../libasync/libasync.a ../libg23/libg23.a
 INSTBIN=/usr/local/bin
 
--- a/rvinterf/asyncshell/tchcmd.c	Tue May 31 00:43:00 2016 +0000
+++ b/rvinterf/asyncshell/tchcmd.c	Tue May 31 01:53:04 2016 +0000
@@ -109,7 +109,9 @@
 		async_msg_output(buf);
 		return;
 	case TCH_ULBITS_CONF:
-		/* TCH UL play code will hook in here */
+		if (rvi_msg_len != 3)
+			goto inv;
+		tch_ulbits_conf();
 		return;
 	case TCH_DLBITS_IND:
 		if (rvi_msg_len != 43)
@@ -148,6 +150,7 @@
 		return;
 	}
 	show_tch_record_status();
+	show_tch_play_status();
 	printf("TCH raw dump mode is %s\n",
 		tch_rawdump_mode ? "enabled" : "disabled");
 }
@@ -166,6 +169,10 @@
 		cmd_tch_dumpraw(argc, argv);
 		return;
 	}
+	if (!strcmp(argv[0], "play")) {
+		cmd_tch_play(argc, argv);
+		return;
+	}
 	if (!strcmp(argv[0], "record")) {
 		cmd_tch_record(argc, argv);
 		return;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/asyncshell/tchplay.c	Tue May 31 01:53:04 2016 +0000
@@ -0,0 +1,112 @@
+/*
+ * TCH uplink play-from-file functionality
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "tch_feature.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+extern void async_msg_output();
+
+static FILE *gsm_data_file;
+static int queued_frames;
+
+#define	QUEUE_LIMIT	3
+
+static void
+sync_msgout(msg)
+	char *msg;
+{
+	printf("%s\n", msg);
+}
+
+static void
+fill_uplink(msgout)
+	void (*msgout)();
+{
+	u_char sendpkt[35];
+	int cc;
+
+	sendpkt[0] = RVT_TCH_HEADER;
+	sendpkt[1] = TCH_ULBITS_REQ;
+	while (queued_frames < QUEUE_LIMIT) {
+		cc = fread(sendpkt + 2, 1, 33, gsm_data_file);
+		if (cc < 33) {
+			if (cc)
+			  msgout("TCH UL: extra bytes at the end of the file");
+			msgout("TCH UL: file play finished");
+			gsm_data_file = 0;
+			return;
+		}
+		send_pkt_to_target(sendpkt, 35);
+		queued_frames++;
+	}
+}
+
+void
+tch_ulbits_conf()
+{
+	if (queued_frames > 0)
+		queued_frames--;
+	if (gsm_data_file)
+		fill_uplink(async_msg_output);
+}
+
+static void
+cmd_tch_play_start(filename)
+	char *filename;
+{
+	if (gsm_data_file) {
+		printf("error: tch play session already in progress\n");
+		return;
+	}
+	gsm_data_file = fopen(filename, "r");
+	if (!gsm_data_file) {
+		perror(filename);
+		return;
+	}
+	printf("Starting TCH UL play from file\n");
+	tch_rx_control(1);
+	fill_uplink(sync_msgout);
+}
+
+static void
+cmd_tch_play_stop()
+{
+	if (!gsm_data_file) {
+		printf("error: no tch play session in progress\n");
+		return;
+	}
+	fclose(gsm_data_file);
+	gsm_data_file = 0;
+	printf("TCH UL play from file terminated\n");
+}
+
+void
+cmd_tch_play(argc, argv)
+	char **argv;
+{
+	if (argc < 2) {
+		printf("error: too few arguments\n");
+		return;
+	}
+	if (strcmp(argv[1], "stop"))
+		cmd_tch_play_start(argv[1]);
+	else
+		cmd_tch_play_stop();
+}
+
+void
+show_tch_play_status()
+{
+	printf("TCH UL play from file: %s\n",
+		gsm_data_file ? "RUNNING" : "not running");
+	printf("Outstanding UL frames: %d\n", queued_frames);
+}