FreeCalypso > hg > freecalypso-tools
comparison rvinterf/lowlevel/packettx.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This module handles the lowest level of serial packet Tx | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/time.h> | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <stdlib.h> | |
11 #include <unistd.h> | |
12 #include "../include/pktmux.h" | |
13 #include "../include/limits.h" | |
14 | |
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; | |
20 | |
21 send_pkt_to_target(pkt, pktlen) | |
22 u_char *pkt; | |
23 { | |
24 u_char buf[MAX_PKT_TO_TARGET*2+2]; | |
25 u_char *cp, *dp, *endp; | |
26 int c; | |
27 struct timeval curtime, timediff; | |
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 } | |
37 endp = pkt + pktlen; | |
38 dp = buf; | |
39 *dp++ = STX; | |
40 for (cp = pkt; cp < endp; cp++) { | |
41 c = *cp; | |
42 if (c == STX || c == DLE) | |
43 *dp++ = DLE; | |
44 *dp++ = c; | |
45 } | |
46 *dp++ = STX; | |
47 write(target_fd, buf, dp - buf); | |
48 bcopy(&curtime, &last_tx, sizeof(struct timeval)); | |
49 } |