changeset 6:631f2db08538

pcm: implement print-rx and record commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 18:53:01 +0000
parents 7233c10af3ad
children ca351324187a
files pcm/Makefile pcm/globals.h pcm/read_ts.c pcm/record_ctrl.c pcm/user_cmd.c
diffstat 5 files changed, 81 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pcm/Makefile	Sun Jun 23 18:33:09 2024 +0000
+++ b/pcm/Makefile	Sun Jun 23 18:53:01 2024 +0000
@@ -1,5 +1,5 @@
 PROG=	itt-pcm-one
-OBJS=	main.o read_ts.o user_cmd.o
+OBJS=	main.o read_ts.o record_ctrl.o user_cmd.o
 LIBUTIL=../libutil/libutil.a
 
 include ../config.defs
@@ -9,6 +9,8 @@
 
 all:	${PROG}
 
+${OBJS}:	globals.h
+
 ${PROG}: ${OBJS} ${LIBUTIL}
 	${CC} -o $@ ${OBJS} ${LIBUTIL} ${OSMO_LINK}
 
--- a/pcm/globals.h	Sun Jun 23 18:33:09 2024 +0000
+++ b/pcm/globals.h	Sun Jun 23 18:53:01 2024 +0000
@@ -5,6 +5,10 @@
 extern struct osmo_e1dp_client *g_client;
 extern int ts_fd;
 extern uint8_t readbuf[160];
+extern FILE *record_file;
 
 int ts_fd_cb(struct osmo_fd *ofd, unsigned int what);
 void handle_user_cmd(int argc, char **argv);
+void cmd_record_start(int argc, char **argv);
+void cmd_record_stop(int argc, char **argv);
+void cmd_print_rx(int argc, char **argv);
--- a/pcm/read_ts.c	Sun Jun 23 18:33:09 2024 +0000
+++ b/pcm/read_ts.c	Sun Jun 23 18:53:01 2024 +0000
@@ -14,6 +14,7 @@
 #include "globals.h"
 
 uint8_t readbuf[160];
+FILE *record_file;
 
 int ts_fd_cb(struct osmo_fd *ofd, unsigned int what)
 {
@@ -26,5 +27,7 @@
 			rc);
 		exit(1);
 	}
+	if (record_file)
+		fwrite(readbuf, 1, 160, record_file);
 	return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcm/record_ctrl.c	Sun Jun 23 18:53:01 2024 +0000
@@ -0,0 +1,50 @@
+/*
+ * Here we implement stdin commands that control recording of E1 timeslot
+ * read stream.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <osmocom/core/select.h>
+
+#include "globals.h"
+
+void cmd_record_start(int argc, char **argv)
+{
+	if (argc != 2) {
+		printf("error: record command needs 1 argument\n");
+		return;
+	}
+	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(int argc, char **argv)
+{
+	if (!record_file) {
+		printf("error: no recording in progress\n");
+		return;
+	}
+	fclose(record_file);
+	record_file = NULL;
+}
+
+void cmd_print_rx(int argc, char **argv)
+{
+	int i, j, off;
+
+	off = 0;
+	for (i = 0; i < 10; i++) {
+		for (j = 0; j < 16; j++)
+			printf(" %02X", readbuf[off++]);
+		putchar('\n');
+	}
+}
--- a/pcm/user_cmd.c	Sun Jun 23 18:33:09 2024 +0000
+++ b/pcm/user_cmd.c	Sun Jun 23 18:53:01 2024 +0000
@@ -13,7 +13,27 @@
 
 #include "globals.h"
 
+static struct cmdtab {
+	char	*cmd;
+	void	(*func)(int argc, char **argv);
+} cmdtab[] = {
+	{"print-rx", cmd_print_rx},
+	{"record", cmd_record_start},
+	{"record-stop", cmd_record_stop},
+	/* table search terminator */
+	{NULL, NULL}
+};
+
 void handle_user_cmd(int argc, char **argv)
 {
-	/* to be filled */
+	struct cmdtab *tp;
+
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[0]))
+			break;
+	if (!tp->func) {
+		printf("error: unknown or unimplemented command\n");
+		return;
+	}
+	tp->func(argc, argv);
 }