FreeCalypso > hg > freecalypso-tools
diff rvinterf/asyncshell/tchplay.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 971906d7763d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/tchplay.c Sat Jun 11 00:13:35 2016 +0000 @@ -0,0 +1,118 @@ +/* + * TCH uplink play-from-file 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; + +extern void async_msg_output(); + +static FILE *gsm_data_file; +static int queued_frames; + +#define QUEUE_LIMIT 3 + +static void +sync_msgout(msg) + char *msg; +{ + printf("%s\n", msg); +} + +static void +fill_uplink(msgout) + void (*msgout)(); +{ + u_char readbytes[33], sendpkt[35]; + int cc; + + sendpkt[0] = RVT_TCH_HEADER; + sendpkt[1] = TCH_ULBITS_REQ; + while (queued_frames < QUEUE_LIMIT) { + cc = fread(readbytes, 1, 33, gsm_data_file); + if (cc < 33) { + if (cc) + msgout("TCH UL: extra bytes at the end of the file"); + msgout("TCH UL: file play finished"); + gsm_data_file = 0; + return; + } + if ((readbytes[0] & 0xF0) != 0xD0) { + msgout("TCH UL: bad file input, play aborted"); + gsm_data_file = 0; + return; + } + gsm0610_libgsm_to_tidsp(readbytes, sendpkt + 2); + send_pkt_to_target(sendpkt, 35); + queued_frames++; + } +} + +void +tch_ulbits_conf() +{ + if (queued_frames > 0) + queued_frames--; + if (gsm_data_file) + fill_uplink(async_msg_output); +} + +static void +cmd_tch_play_start(filename) + char *filename; +{ + if (gsm_data_file) { + printf("error: tch play session already in progress\n"); + return; + } + gsm_data_file = fopen(filename, "r"); + if (!gsm_data_file) { + perror(filename); + return; + } + printf("Starting TCH UL play from file\n"); + tch_rx_control(1); + fill_uplink(sync_msgout); +} + +static void +cmd_tch_play_stop() +{ + if (!gsm_data_file) { + printf("error: no tch play session in progress\n"); + return; + } + fclose(gsm_data_file); + gsm_data_file = 0; + printf("TCH UL play from file terminated\n"); +} + +void +cmd_tch_play(argc, argv) + char **argv; +{ + if (argc < 2) { + printf("error: too few arguments\n"); + return; + } + if (strcmp(argv[1], "stop")) + cmd_tch_play_start(argv[1]); + else + cmd_tch_play_stop(); +} + +void +show_tch_play_status() +{ + printf("TCH UL play from file: %s\n", + gsm_data_file ? "RUNNING" : "not running"); + printf("Outstanding UL frames: %d\n", queued_frames); +}