FreeCalypso > hg > freecalypso-tools
comparison rvinterf/lowlevel/format.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 | d452188587b4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This module implements the decoding of Rx packets | |
3 * into human-readable form. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include "../include/pktmux.h" | |
11 #include "../include/limits.h" | |
12 | |
13 extern u_char rxpkt[]; | |
14 extern size_t rxpkt_len; | |
15 | |
16 static char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ | |
17 | |
18 void | |
19 print_rv_trace() | |
20 { | |
21 int i, c; | |
22 char *dp; | |
23 | |
24 dp = fmtbuf; | |
25 strcpy(dp, "RV "); | |
26 dp += 3; | |
27 /* the SWE static ID is sent MSB first */ | |
28 for (i = 1; i <= 4; i++) { | |
29 sprintf(dp, "%02X", rxpkt[i]); | |
30 dp += 2; | |
31 } | |
32 /* severity level */ | |
33 sprintf(dp, " %d ", rxpkt[5]); | |
34 dp = index(dp, '\0'); | |
35 for (i = 6; i < rxpkt_len; i++) { | |
36 c = rxpkt[i]; | |
37 if (c & 0x80) { | |
38 *dp++ = 'M'; | |
39 *dp++ = '-'; | |
40 c &= 0x7F; | |
41 } | |
42 if (c < 0x20) { | |
43 *dp++ = '^'; | |
44 *dp++ = c + '@'; | |
45 } else if (c == 0x7F) { | |
46 *dp++ = '^'; | |
47 *dp++ = '?'; | |
48 } else | |
49 *dp++ = c; | |
50 } | |
51 *dp = '\0'; | |
52 output_line(fmtbuf); | |
53 } | |
54 | |
55 void | |
56 print_l1_trace() | |
57 { | |
58 int i, c; | |
59 char *dp; | |
60 | |
61 dp = fmtbuf; | |
62 strcpy(dp, "L1: "); | |
63 dp += 4; | |
64 for (i = 1; i < rxpkt_len; i++) { | |
65 if ((i+1 < rxpkt_len) && | |
66 (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' || | |
67 rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) { | |
68 *dp = '\0'; | |
69 output_line(fmtbuf); | |
70 if (i+2 == rxpkt_len) | |
71 return; | |
72 dp = fmtbuf; | |
73 *dp++ = '+'; | |
74 *dp++ = ' '; | |
75 i++; | |
76 continue; | |
77 } | |
78 c = rxpkt[i]; | |
79 if (c & 0x80) { | |
80 *dp++ = 'M'; | |
81 *dp++ = '-'; | |
82 c &= 0x7F; | |
83 } | |
84 if (c < 0x20) { | |
85 *dp++ = '^'; | |
86 *dp++ = c + '@'; | |
87 } else if (c == 0x7F) { | |
88 *dp++ = '^'; | |
89 *dp++ = '?'; | |
90 } else | |
91 *dp++ = c; | |
92 } | |
93 /* will get here only if no newline sequence at the end */ | |
94 *dp = '\0'; | |
95 output_line(fmtbuf); | |
96 } | |
97 | |
98 void | |
99 print_g23_trace() | |
100 { | |
101 /* messy logic factored out into libg23 */ | |
102 format_g23_packet(rxpkt, (int)rxpkt_len, fmtbuf); | |
103 output_line(fmtbuf); | |
104 } | |
105 | |
106 void | |
107 print_tm_output_raw() | |
108 { | |
109 int i; | |
110 char *dp; | |
111 | |
112 dp = fmtbuf; | |
113 strcpy(dp, "TM:"); | |
114 dp += 3; | |
115 for (i = 1; i < rxpkt_len; i++) { | |
116 sprintf(dp, " %02X", rxpkt[i]); | |
117 dp += 3; | |
118 } | |
119 *dp = '\0'; | |
120 output_line(fmtbuf); | |
121 } | |
122 | |
123 void | |
124 print_unknown_packet() | |
125 { | |
126 int i; | |
127 char *dp; | |
128 | |
129 dp = fmtbuf; | |
130 strcpy(dp, "UNK:"); | |
131 dp += 4; | |
132 for (i = 0; i < rxpkt_len; i++) { | |
133 sprintf(dp, " %02X", rxpkt[i]); | |
134 dp += 3; | |
135 } | |
136 *dp = '\0'; | |
137 output_line(fmtbuf); | |
138 } |