changeset 191:cf8583923dc4

rvinterf: workaround for sleeping targets
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 25 Nov 2013 04:41:36 +0000
parents 405f5b46cdc4
children 707aa640b2dc
files rvinterf/lowlevel/packettx.c rvinterf/lowlevel/rvifmain.c
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/packettx.c	Mon Nov 25 03:23:19 2013 +0000
+++ b/rvinterf/lowlevel/packettx.c	Mon Nov 25 04:41:36 2013 +0000
@@ -3,13 +3,20 @@
  */
 
 #include <sys/types.h>
+#include <sys/time.h>
 #include <stdio.h>
+#include <string.h>
+#include <strings.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include "../pktmux.h"
 #include "../limits.h"
 
 extern int target_fd;
+extern int wakeup_after_sec;
+
+static u_char wakeup_shot[64];
+static struct timeval last_tx;
 
 send_pkt_to_target(pkt, pktlen)
 	u_char *pkt;
@@ -17,7 +24,16 @@
 	u_char buf[MAX_PKT_TO_TARGET*2+2];
 	u_char *cp, *dp, *endp;
 	int c;
+	struct timeval curtime, timediff;
 
+	gettimeofday(&curtime, 0);
+	if (wakeup_after_sec) {
+		timersub(&curtime, &last_tx, &timediff);
+		if (timediff.tv_sec >= wakeup_after_sec) {
+			write(target_fd, wakeup_shot, sizeof wakeup_shot);
+			usleep(100000);
+		}
+	}
 	endp = pkt + pktlen;
 	dp = buf;
 	*dp++ = STX;
@@ -29,4 +45,5 @@
 	}
 	*dp++ = STX;
 	write(target_fd, buf, dp - buf);
+	bcopy(&curtime, &last_tx, sizeof(struct timeval));
 }
--- a/rvinterf/lowlevel/rvifmain.c	Mon Nov 25 03:23:19 2013 +0000
+++ b/rvinterf/lowlevel/rvifmain.c	Mon Nov 25 04:41:36 2013 +0000
@@ -5,6 +5,8 @@
 #include <sys/types.h>
 #include <sys/errno.h>
 #include <stdio.h>
+#include <string.h>
+#include <strings.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
@@ -29,6 +31,8 @@
 
 char *socket_pathname = "/tmp/rvinterf_socket";
 
+int wakeup_after_sec;
+
 main(argc, argv)
 	char **argv;
 {
@@ -38,7 +42,7 @@
 	fd_set fds;
 	struct client *cli, **clip;
 
-	while ((c = getopt(argc, argv, "bB:d:l:s:")) != EOF)
+	while ((c = getopt(argc, argv, "bB:d:l:s:w:")) != EOF)
 		switch (c) {
 		case 'b':
 			background++;
@@ -55,6 +59,9 @@
 		case 's':
 			socket_pathname = optarg;
 			continue;
+		case 'w':
+			wakeup_after_sec = strtoul(optarg, 0, 0);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,