view rvinterf/asyncshell/tchrec.c @ 1028:71bbddbcc6a1

fc-shell: tch record implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 31 May 2016 00:43:00 +0000
parents
children 194967e11b2b
line wrap: on
line source

/*
 * TCH downlink recording 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;

static FILE *gsm_data_file;
static u_long frame_count;

void
tch_dlbits_handler()
{
	if (!gsm_data_file)
		return;
	fwrite(rvi_msg + 9, 33, 1, gsm_data_file);
	frame_count++;
}

static void
cmd_tch_record_start(filename)
	char *filename;
{
	if (gsm_data_file) {
		printf("error: tch record session already in progress\n");
		return;
	}
	gsm_data_file = fopen(filename, "w");
	if (!gsm_data_file) {
		perror(filename);
		return;
	}
	printf("Starting TCH DL recording\n");
	tch_rx_control(1);
	send_tch_config_req(1);
	frame_count = 0;
}

static void
cmd_tch_record_stop()
{
	if (!gsm_data_file) {
		printf("error: no tch record session in progress\n");
		return;
	}
	fclose(gsm_data_file);
	gsm_data_file = 0;
	printf("TCH DL recording stopped, captured %lu speech frames\n",
		frame_count);
	send_tch_config_req(0);
}

void
cmd_tch_record(argc, argv)
	char **argv;
{
	if (argc < 2) {
		printf("error: too few arguments\n");
		return;
	}
	if (strcmp(argv[1], "stop"))
		cmd_tch_record_start(argv[1]);
	else
		cmd_tch_record_stop();
}

void
show_tch_record_status()
{
	printf("TCH DL recording: %s\n",
		gsm_data_file ? "RUNNING" : "not running");
}