FreeCalypso > hg > freecalypso-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
190:405f5b46cdc4 | 191:cf8583923dc4 |
---|---|
1 /* | 1 /* |
2 * This module handles the lowest level of serial packet Tx | 2 * This module handles the lowest level of serial packet Tx |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <sys/time.h> | |
6 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | |
9 #include <strings.h> | |
7 #include <stdlib.h> | 10 #include <stdlib.h> |
8 #include <unistd.h> | 11 #include <unistd.h> |
9 #include "../pktmux.h" | 12 #include "../pktmux.h" |
10 #include "../limits.h" | 13 #include "../limits.h" |
11 | 14 |
12 extern int target_fd; | 15 extern int target_fd; |
16 extern int wakeup_after_sec; | |
17 | |
18 static u_char wakeup_shot[64]; | |
19 static struct timeval last_tx; | |
13 | 20 |
14 send_pkt_to_target(pkt, pktlen) | 21 send_pkt_to_target(pkt, pktlen) |
15 u_char *pkt; | 22 u_char *pkt; |
16 { | 23 { |
17 u_char buf[MAX_PKT_TO_TARGET*2+2]; | 24 u_char buf[MAX_PKT_TO_TARGET*2+2]; |
18 u_char *cp, *dp, *endp; | 25 u_char *cp, *dp, *endp; |
19 int c; | 26 int c; |
27 struct timeval curtime, timediff; | |
20 | 28 |
29 gettimeofday(&curtime, 0); | |
30 if (wakeup_after_sec) { | |
31 timersub(&curtime, &last_tx, &timediff); | |
32 if (timediff.tv_sec >= wakeup_after_sec) { | |
33 write(target_fd, wakeup_shot, sizeof wakeup_shot); | |
34 usleep(100000); | |
35 } | |
36 } | |
21 endp = pkt + pktlen; | 37 endp = pkt + pktlen; |
22 dp = buf; | 38 dp = buf; |
23 *dp++ = STX; | 39 *dp++ = STX; |
24 for (cp = pkt; cp < endp; cp++) { | 40 for (cp = pkt; cp < endp; cp++) { |
25 c = *cp; | 41 c = *cp; |
27 *dp++ = DLE; | 43 *dp++ = DLE; |
28 *dp++ = c; | 44 *dp++ = c; |
29 } | 45 } |
30 *dp++ = STX; | 46 *dp++ = STX; |
31 write(target_fd, buf, dp - buf); | 47 write(target_fd, buf, dp - buf); |
48 bcopy(&curtime, &last_tx, sizeof(struct timeval)); | |
32 } | 49 } |