changeset 13:315428573a25

fc-mcsi-rxtx: implement record function
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2024 07:24:53 +0000
parents 23555b9a1c20
children f908a782cff9
files sw/mcsi-rxtx/Makefile sw/mcsi-rxtx/mainloop.c sw/mcsi-rxtx/record.c sw/mcsi-rxtx/rx_samples.c sw/mcsi-rxtx/usercmd.c
diffstat 5 files changed, 67 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sw/mcsi-rxtx/Makefile	Mon Oct 28 06:52:33 2024 +0000
+++ b/sw/mcsi-rxtx/Makefile	Mon Oct 28 07:24:53 2024 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	fc-mcsi-rxtx
-OBJS=	main.o mainloop.o rx_samples.o ttymagic.o tx_func.o usercmd.o
+OBJS=	main.o mainloop.o record.o rx_samples.o ttymagic.o tx_func.o usercmd.o
 LIBS=	../libserial/libserial.a
 
 INSTALL_PREFIX=	/opt/freecalypso
--- a/sw/mcsi-rxtx/mainloop.c	Mon Oct 28 06:52:33 2024 +0000
+++ b/sw/mcsi-rxtx/mainloop.c	Mon Oct 28 07:24:53 2024 +0000
@@ -47,6 +47,7 @@
 				off);
 			async_msg_output(buf);
 			off = 0;
+			record_auto_stop();
 			continue;
 		}
 		if (FD_ISSET(0, &fds))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sw/mcsi-rxtx/record.c	Mon Oct 28 07:24:53 2024 +0000
@@ -0,0 +1,59 @@
+/*
+ * Here we implement the functionality of recording MCSI Rx streams
+ * into robe files.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+extern u_short rx_pcm_samples[160];
+
+static FILE *record_file;
+
+void
+record_process()
+{
+	unsigned n, samp;
+
+	if (!record_file)
+		return;
+	for (n = 0; n < 160; n++) {
+		samp = rx_pcm_samples[n];
+		putc(samp >> 8, record_file);
+		putc(samp, record_file);
+	}
+}
+
+void
+record_auto_stop()
+{
+	if (!record_file)
+		return;
+	fclose(record_file);
+	record_file = 0;
+}
+
+void
+cmd_record(argc, argv)
+	char **argv;
+{
+	if (record_file) {
+		printf("error: recording already in progress\n");
+		return;
+	}
+	record_file = fopen(argv[1], "w");
+	if (!record_file)
+		perror(argv[1]);
+}
+
+void
+cmd_record_stop()
+{
+	if (!record_file) {
+		printf("error: no recording in progress\n");
+		return;
+	}
+	fclose(record_file);
+	record_file = 0;
+}
--- a/sw/mcsi-rxtx/rx_samples.c	Mon Oct 28 06:52:33 2024 +0000
+++ b/sw/mcsi-rxtx/rx_samples.c	Mon Oct 28 07:24:53 2024 +0000
@@ -21,6 +21,7 @@
 		samp = ((unsigned) sp[1] << 8) | ((unsigned) sp[0]);
 		rx_pcm_samples[n] = samp;
 	}
+	record_process();
 }
 
 void
--- a/sw/mcsi-rxtx/usercmd.c	Mon Oct 28 06:52:33 2024 +0000
+++ b/sw/mcsi-rxtx/usercmd.c	Mon Oct 28 07:24:53 2024 +0000
@@ -13,6 +13,8 @@
 
 extern void cmd_pcm_fill();
 extern void cmd_print_rx();
+extern void cmd_record();
+extern void cmd_record_stop();
 
 static void
 cmd_exit()
@@ -31,6 +33,9 @@
 	{"pcm-fill", 0, 1, cmd_pcm_fill},
 	{"print-rx", 0, 0, cmd_print_rx},
 	{"quit", 0, 0, cmd_exit},
+	{"record", 1, 1, cmd_record},
+	{"record-stop", 0, 0, cmd_record_stop},
+	/* table search terminator */
 	{0, 0, 0, 0}
 };