FreeCalypso > hg > freecalypso-sw
annotate rvinterf/lowlevel/packettx.c @ 173:f42854da4563
rvinterf: beginning of refactoring
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 22 Nov 2013 05:56:07 +0000 |
parents | |
children | 3256dc6e84ae |
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> |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <unistd.h> |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "pktmux.h" |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "txpkt.h" |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 extern int target_fd; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 send_pkt_to_target(pkt, pktlen) |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 u_char *pkt; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 { |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 u_char buf[MAX_PKT_TO_TARGET*2+2]; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 u_char *cp, *dp, *endp; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 int c; |
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 endp = pkt + pktlen; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 dp = buf; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 *dp++ = STX; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 for (cp = pkt; cp < endp; cp++) { |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 c = *cp; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 if (c == STX || c == DLE) |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 *dp++ = DLE; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 *dp++ = c; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 } |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 *dp++ = STX; |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 write(target_fd, buf, dp - buf); |
f42854da4563
rvinterf: beginning of refactoring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } |