diff ater/play_cmd.c @ 27:2742dbea95f1

ater: implement play command
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 20:31:29 +0000
parents
children 1dda11905e85
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ater/play_cmd.c	Mon Jun 24 20:31:29 2024 +0000
@@ -0,0 +1,44 @@
+/*
+ * Here we implement user commands controlling file play functionality.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/core/select.h>
+
+#include "globals.h"
+#include "submux.h"
+#include "read_file.h"
+
+void cmd_play_file(int argc, char **argv)
+{
+	int nr, rc;
+	struct ater_subslot *at;
+
+	if (argc != 3) {
+usage:		fprintf(stderr, "usage: %s 0|1|2|3 play-file.tul\n", argv[0]);
+		return;
+	}
+	if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
+		goto usage;
+	nr = argv[1][0] - '0';
+	at = &subslots[nr];
+	if (!at->is_active) {
+		fprintf(stderr, "error: subslot %d is not active\n", nr);
+		return;
+	}
+	if (at->play_buffer) {
+		fprintf(stderr, "error: file play already in progress\n");
+		return;
+	}
+	rc = read_binary_file(argv[2], at->is_efr, &at->play_buffer,
+				&at->play_buf_total);
+	if (rc < 0)
+		return;		/* error msg already printed */
+	at->play_buf_ptr = 0;
+	at->play_wait_align = true;
+}