comparison rvinterf/lowlevel/format.c @ 174:3256dc6e84ae

rvinterf: refactored rvtdump compiles and works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 22 Nov 2013 07:41:31 +0000
parents rvinterf/old/trdump.c@f42854da4563
children 2f214bd03119
comparison
equal deleted inserted replaced
173:f42854da4563 174:3256dc6e84ae
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 "../pktmux.h"
11 #include "../limits.h"
12
13 extern u_char rxpkt[];
14 extern size_t rxpkt_len;
15
16 void
17 print_rv_trace()
18 {
19 char buf[MAX_PKT_FROM_TARGET*4];
20 int i, c;
21 char *dp;
22
23 dp = buf;
24 strcpy(dp, "RV ");
25 dp += 3;
26 /* the SWE static ID is sent MSB first */
27 for (i = 1; i <= 4; i++) {
28 sprintf(dp, "%02X", rxpkt[i]);
29 dp += 2;
30 }
31 /* severity level */
32 sprintf(dp, " %d ", rxpkt[5]);
33 dp = index(dp, '\0');
34 for (i = 6; i < rxpkt_len; i++) {
35 c = rxpkt[i];
36 if (c & 0x80) {
37 *dp++ = 'M';
38 *dp++ = '-';
39 c &= 0x7F;
40 }
41 if (c < 0x20) {
42 *dp++ = '^';
43 *dp++ = c + '@';
44 } else if (c == 0x7F) {
45 *dp++ = '^';
46 *dp++ = '?';
47 } else
48 *dp++ = c;
49 }
50 *dp = '\0';
51 output_line(buf);
52 }
53
54 void
55 print_l1_trace()
56 {
57 char buf[MAX_PKT_FROM_TARGET*4+1];
58 int i, c;
59 char *dp;
60
61 dp = buf;
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(buf);
70 if (i+2 == rxpkt_len)
71 return;
72 dp = buf;
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(buf);
96 }
97
98 void
99 print_g23_trace()
100 {
101 char buf[MAX_PKT_FROM_TARGET*3+2];
102 int i;
103 char *dp;
104
105 dp = buf;
106 strcpy(dp, "G23:");
107 dp += 4;
108 for (i = 1; i < rxpkt_len; i++) {
109 sprintf(dp, " %02X", rxpkt[i]);
110 dp += 3;
111 }
112 *dp = '\0';
113 output_line(buf);
114 }
115
116 void
117 print_etm_output_raw()
118 {
119 char buf[MAX_PKT_FROM_TARGET*3+2];
120 int i;
121 char *dp;
122
123 dp = buf;
124 strcpy(dp, "ETM:");
125 dp += 4;
126 for (i = 1; i < rxpkt_len; i++) {
127 sprintf(dp, " %02X", rxpkt[i]);
128 dp += 3;
129 }
130 *dp = '\0';
131 output_line(buf);
132 }
133
134 void
135 print_unknown_packet()
136 {
137 char buf[MAX_PKT_FROM_TARGET*3+5];
138 int i;
139 char *dp;
140
141 dp = buf;
142 strcpy(dp, "UNK:");
143 dp += 4;
144 for (i = 0; i < rxpkt_len; i++) {
145 sprintf(dp, " %02X", rxpkt[i]);
146 dp += 3;
147 }
148 *dp = '\0';
149 output_line(buf);
150 }