changeset 169:e01e3a60c858

rvinterf: background mode implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 20 Nov 2013 02:58:35 +0000
parents 60afcd233b04
children 4b53bd08f345
files rvinterf/rvtdump.c rvinterf/trdump.c
diffstat 2 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/rvtdump.c	Tue Nov 19 06:06:42 2013 +0000
+++ b/rvinterf/rvtdump.c	Wed Nov 20 02:58:35 2013 +0000
@@ -18,6 +18,7 @@
 char *logfname;
 FILE *logF;
 time_t logtime;
+int background;
 
 main(argc, argv)
 	char **argv;
@@ -27,9 +28,12 @@
 	int c;
 	fd_set fds;
 
-	while ((c = getopt(argc, argv, "b:d:l:")) != EOF)
+	while ((c = getopt(argc, argv, "bB:d:l:")) != EOF)
 		switch (c) {
 		case 'b':
+			background++;
+			continue;
+		case 'B':
 			baudrate_name = optarg;
 			continue;
 		case 'd':
@@ -41,9 +45,13 @@
 		case '?':
 		default:
 usage:			fprintf(stderr,
-			"usage: %s [-b baudrate] ttyport\n", argv[0]);
+			"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;
@@ -61,6 +69,17 @@
 		fprintf(logF, "*** Log of decoded RVT output ***\n");
 		setlinebuf(logF);
 	}
+	if (background) {
+		c = fork();
+		if (c < 0) {
+			perror("fork");
+			exit(1);
+		}
+		if (c) {
+			printf("rvtdump forked into background (pid %d)\n", c);
+			exit(0);
+		}
+	}
 	for (;;) {
 		FD_ZERO(&fds);
 		FD_SET(target_fd, &fds);
@@ -84,7 +103,8 @@
 
 print_item()
 {
-	printf("%s\n", pr_item);
+	if (!background)
+		printf("%s\n", pr_item);
 	if (logF)
 		log_item();
 }
--- a/rvinterf/trdump.c	Tue Nov 19 06:06:42 2013 +0000
+++ b/rvinterf/trdump.c	Wed Nov 20 02:58:35 2013 +0000
@@ -111,6 +111,23 @@
 }
 
 void
+print_etm_output_raw()
+{
+	int i;
+	char *dp;
+
+	dp = pr_item;
+	strcpy(dp, "ETM:");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	print_item();
+}
+
+void
 print_unknown_packet()
 {
 	int i;
@@ -142,6 +159,9 @@
 	case RVT_L23_HEADER:
 		print_g23_trace();
 		return;
+	case RVT_TM_HEADER:
+		print_etm_output_raw();
+		return;
 	default:
 	unknown:
 		print_unknown_packet();