annotate rvinterf/lowlevel/packettx.c @ 271:cd043e690621

imei-luhn utility written
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 07 Feb 2014 05:00:24 +0000
parents 2f285f20d617
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module handles the lowest level of serial packet Tx
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
6 #include <sys/time.h>
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
8 #include <string.h>
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
9 #include <strings.h>
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
256
2f285f20d617 rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 191
diff changeset
12 #include "../include/pktmux.h"
2f285f20d617 rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 191
diff changeset
13 #include "../include/limits.h"
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern int target_fd;
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
16 extern int wakeup_after_sec;
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
17
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
18 static u_char wakeup_shot[64];
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
19 static struct timeval last_tx;
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 send_pkt_to_target(pkt, pktlen)
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 u_char *pkt;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 {
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 u_char buf[MAX_PKT_TO_TARGET*2+2];
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 u_char *cp, *dp, *endp;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 int c;
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
27 struct timeval curtime, timediff;
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
29 gettimeofday(&curtime, 0);
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
30 if (wakeup_after_sec) {
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
31 timersub(&curtime, &last_tx, &timediff);
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
32 if (timediff.tv_sec >= wakeup_after_sec) {
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
33 write(target_fd, wakeup_shot, sizeof wakeup_shot);
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
34 usleep(100000);
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
35 }
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
36 }
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 endp = pkt + pktlen;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 dp = buf;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 *dp++ = STX;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 for (cp = pkt; cp < endp; cp++) {
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 c = *cp;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 if (c == STX || c == DLE)
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 *dp++ = DLE;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 *dp++ = c;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 }
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 *dp++ = STX;
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 write(target_fd, buf, dp - buf);
191
cf8583923dc4 rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 174
diff changeset
48 bcopy(&curtime, &last_tx, sizeof(struct timeval));
173
f42854da4563 rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 }