diff rvinterf/lowlevel/packettx.c @ 191:cf8583923dc4

rvinterf: workaround for sleeping targets
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 25 Nov 2013 04:41:36 +0000
parents 3256dc6e84ae
children 2f285f20d617
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));
 }