FreeCalypso > hg > freecalypso-reveng
comparison pircharge/pktsort.c @ 228:fec90990f613
pirchgdbg started
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 19 Dec 2017 02:58:38 +0000 |
parents | |
children | 84a4f6ef2d28 |
comparison
equal
deleted
inserted
replaced
227:bb86424f78e6 | 228:fec90990f613 |
---|---|
1 /* | |
2 * Here we sort out incoming packets from the target relayed via rvinterf. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdlib.h> | |
10 #include <rvinterf/pktmux.h> | |
11 #include <rvinterf/limits.h> | |
12 #include <rvinterf/localsock.h> | |
13 #include <rvinterf/localtypes.h> | |
14 #include <rvinterf/etm.h> | |
15 #include <rvinterf/exitcodes.h> | |
16 | |
17 extern u_char rvi_msg[]; | |
18 extern int rvi_msg_len; | |
19 | |
20 void | |
21 print_rv_trace() | |
22 { | |
23 char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ | |
24 int i, c; | |
25 char *dp; | |
26 | |
27 dp = fmtbuf; | |
28 strcpy(dp, "RV "); | |
29 dp += 3; | |
30 /* the SWE static ID is sent MSB first */ | |
31 for (i = 1; i <= 4; i++) { | |
32 sprintf(dp, "%02X", rvi_msg[i+1]); | |
33 dp += 2; | |
34 } | |
35 /* severity level */ | |
36 sprintf(dp, " %d ", rvi_msg[6]); | |
37 dp = index(dp, '\0'); | |
38 for (i = 7; i < rvi_msg_len; i++) { | |
39 c = rvi_msg[i]; | |
40 if (c & 0x80) { | |
41 *dp++ = 'M'; | |
42 *dp++ = '-'; | |
43 c &= 0x7F; | |
44 } | |
45 if (c < 0x20) { | |
46 *dp++ = '^'; | |
47 *dp++ = c + '@'; | |
48 } else if (c == 0x7F) { | |
49 *dp++ = '^'; | |
50 *dp++ = '?'; | |
51 } else | |
52 *dp++ = c; | |
53 } | |
54 *dp = '\0'; | |
55 printf("%s\n", fmtbuf); | |
56 } | |
57 | |
58 void | |
59 rvt_packet_rx() | |
60 { | |
61 u32 useid; | |
62 | |
63 if (rvi_msg_len < 7) { | |
64 fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n"); | |
65 exit(ERROR_RVINTERF); | |
66 } | |
67 print_rv_trace(); | |
68 useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8 | |
69 | rvi_msg[5]; | |
70 if (useid != 0x000A0010) | |
71 return; | |
72 if (rvi_msg_len != 22) | |
73 return; | |
74 if (strncmp(rvi_msg + 7, "IQ EXT: ADC End", 15)) | |
75 return; | |
76 /* ADC End handling will go here */ | |
77 } | |
78 | |
79 void | |
80 process_pkt_from_target() | |
81 { | |
82 switch (rvi_msg[1]) { | |
83 case RVT_RV_HEADER: | |
84 rvt_packet_rx(); | |
85 return; | |
86 case RVT_TM_HEADER: | |
87 /* etm_packet_rx(); */ | |
88 return; | |
89 default: | |
90 fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n", | |
91 rvi_msg[1]); | |
92 exit(ERROR_RVINTERF); | |
93 } | |
94 } |