FreeCalypso > hg > freecalypso-sw
view rvinterf/asyncshell/tchplay.c @ 1030:194967e11b2b
fc-shell: tch record and tch play reworked for libgsm-compatible file format
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 31 May 2016 18:39:06 +0000 |
parents | 333015c662bc |
children |
line wrap: on
line source
/* * 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); }