view rvinterf/old/before-rvinterf/rvtdump.c @ 1014:961efadd530a default tip

fc-shell TCH DL handler: add support for CSD modes TCH DL capture mechanism in FC Tourmaline firmware has been extended to support CSD modes in addition to speech - add the necessary support on the host tools side. It needs to be noted that this mechanism in its present state does NOT provide the debug utility value that was sought: as we learned only after the code was implemented, TI's DSP has a misfeature in that the buffer we are reading (a_dd_0[]) is zeroed out when the IDS block is enabled, i.e., we are reading all zeros and not the real DL bits we were after. But since the code has already been written, we are keeping it - perhaps we can do some tests with IDS disabled.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Nov 2024 06:27:43 +0000
parents e7502631a0f9
children
line wrap: on
line source

/*
 * This program reads bytes from a serial port, parses them assuming
 * TI's RVT MUX format, and prints every decoded packet.
 */

#include <sys/types.h>
#include <sys/errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

extern int target_fd;
extern char *baudrate_name;

extern char pr_item[];
extern int sendsock_fd;

char *logfname;
FILE *logF;
time_t logtime;
int background, sendsock_enable;

main(argc, argv)
	char **argv;
{
	extern char *optarg;
	extern int optind;
	int c, maxfd;
	fd_set fds;

	while ((c = getopt(argc, argv, "bB:d:l:s")) != EOF)
		switch (c) {
		case 'b':
			background++;
			continue;
		case 'B':
			baudrate_name = optarg;
			continue;
		case 'd':
			target_fd = atoi(optarg);
			continue;
		case 'l':
			logfname = optarg;
			continue;
		case 's':
			sendsock_enable++;
			continue;
		case '?':
		default:
usage:			fprintf(stderr,
			"usage: %s [options] ttyport\n", argv[0]);
			exit(1);
		}
	if (background && !logfname) {
		fprintf(stderr, "%s: -b is meaningless without -l\n", argv[0]);
		exit(1);
	}
	if (target_fd <= 0) {
		if (argc - optind != 1)
			goto usage;
		open_target_serial(argv[optind]);
	}

	set_serial_nonblock(0);
	setlinebuf(stdout);
	if (logfname) {
		logF = fopen(logfname, "w");
		if (!logF) {
			perror(logfname);
			exit(1);
		}
		fprintf(logF, "*** Log of decoded RVT output ***\n");
		setlinebuf(logF);
	}
	if (sendsock_enable)
		create_send_socket();
	if (background) {
		c = fork();
		if (c < 0) {
			perror("fork");
			exit(1);
		}
		if (c) {
			printf("rvtdump forked into background (pid %d)\n", c);
			exit(0);
		}
	}
	maxfd = target_fd;
	if (sendsock_fd > maxfd)
		maxfd = sendsock_fd;
	for (;;) {
		FD_ZERO(&fds);
		FD_SET(target_fd, &fds);
		if (sendsock_enable)
			FD_SET(sendsock_fd, &fds);
		c = select(maxfd+1, &fds, 0, 0, 0);
		time(&logtime);
		if (c < 0) {
			if (errno == EINTR)
				continue;
			perror("select");
			exit(1);
		}
		if (FD_ISSET(target_fd, &fds))
			process_serial_rx();
		if (FD_ISSET(sendsock_fd, &fds))
			handle_sendsock();
	}
}

handle_rx_packet()
{
	print_rx_packet();
}

print_item()
{
	if (!background)
		printf("%s\n", pr_item);
	if (logF)
		log_item();
}