changeset 8:70aa8cbdbde9

pcm: implement pcm-fill command
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 19:30:40 +0000
parents ca351324187a
children e3d16d490ce2
files pcm/globals.h pcm/pcm_tx.c pcm/user_cmd.c
diffstat 3 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pcm/globals.h	Sun Jun 23 19:21:00 2024 +0000
+++ b/pcm/globals.h	Sun Jun 23 19:30:40 2024 +0000
@@ -14,3 +14,4 @@
 void cmd_record_start(int argc, char **argv);
 void cmd_record_stop(int argc, char **argv);
 void cmd_print_rx(int argc, char **argv);
+void cmd_pcm_fill(int argc, char **argv);
--- a/pcm/pcm_tx.c	Sun Jun 23 19:21:00 2024 +0000
+++ b/pcm/pcm_tx.c	Sun Jun 23 19:30:40 2024 +0000
@@ -2,6 +2,7 @@
  * In this module we implement PCM Tx toward the TRAU.
  */
 
+#include <ctype.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -54,3 +55,24 @@
 		memset(buf, pcm_fill_octet, 160);
 	write(ts_fd, buf, 160);
 }
+
+void cmd_pcm_fill(int argc, char **argv)
+{
+	u_long val;
+	char *cp;
+
+	if (argc != 2) {
+		printf("error: pcm-fill command needs 1 argument\n");
+		return;
+	}
+	if (!isxdigit(argv[1][0])) {
+inv_arg:	printf("error: argument is not a valid hex octet\n");
+		return;
+	}
+	val = strtoul(argv[1], &cp, 16);
+	if (*cp)
+		goto inv_arg;
+	if (val > 0xFF)
+		goto inv_arg;
+	pcm_fill_octet = val;
+}
--- a/pcm/user_cmd.c	Sun Jun 23 19:21:00 2024 +0000
+++ b/pcm/user_cmd.c	Sun Jun 23 19:30:40 2024 +0000
@@ -17,6 +17,7 @@
 	char	*cmd;
 	void	(*func)(int argc, char **argv);
 } cmdtab[] = {
+	{"pcm-fill", cmd_pcm_fill},
 	{"print-rx", cmd_print_rx},
 	{"record", cmd_record_start},
 	{"record-stop", cmd_record_stop},