annotate rvinterf/lowlevel/format.c @ 176:7f727aaf5cd4

rvinterf: beginning of server implementation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 23 Nov 2013 07:40:13 +0000
parents 2f214bd03119
children 2f285f20d617
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
2 * This module implements the decoding of Rx packets
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
3 * into human-readable form.
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
8 #include <string.h>
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
9 #include <strings.h>
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
10 #include "../pktmux.h"
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
11 #include "../limits.h"
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern u_char rxpkt[];
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern size_t rxpkt_len;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 void
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 print_rv_trace()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
19 char buf[MAX_PKT_FROM_TARGET*4];
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
20 int i, c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
21 char *dp;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
23 dp = buf;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
24 strcpy(dp, "RV ");
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
25 dp += 3;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 /* the SWE static ID is sent MSB first */
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
27 for (i = 1; i <= 4; i++) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
28 sprintf(dp, "%02X", rxpkt[i]);
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
29 dp += 2;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
30 }
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 /* severity level */
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
32 sprintf(dp, " %d ", rxpkt[5]);
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
33 dp = index(dp, '\0');
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
34 for (i = 6; i < rxpkt_len; i++) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
35 c = rxpkt[i];
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
36 if (c & 0x80) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
37 *dp++ = 'M';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
38 *dp++ = '-';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
39 c &= 0x7F;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
40 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
41 if (c < 0x20) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
42 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
43 *dp++ = c + '@';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
44 } else if (c == 0x7F) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
45 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
46 *dp++ = '?';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
47 } else
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
48 *dp++ = c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
49 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
50 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
51 output_line(buf);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 void
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 print_l1_trace()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 {
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
57 char buf[MAX_PKT_FROM_TARGET*4+1];
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
58 int i, c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
59 char *dp;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
60
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
61 dp = buf;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
62 strcpy(dp, "L1: ");
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
63 dp += 4;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
64 for (i = 1; i < rxpkt_len; i++) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
65 if ((i+1 < rxpkt_len) &&
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
66 (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
67 rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
68 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
69 output_line(buf);
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
70 if (i+2 == rxpkt_len)
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
71 return;
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
72 dp = buf;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
73 *dp++ = '+';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
74 *dp++ = ' ';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
75 i++;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
76 continue;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
77 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
78 c = rxpkt[i];
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
79 if (c & 0x80) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
80 *dp++ = 'M';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
81 *dp++ = '-';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
82 c &= 0x7F;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
83 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
84 if (c < 0x20) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
85 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
86 *dp++ = c + '@';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
87 } else if (c == 0x7F) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
88 *dp++ = '^';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
89 *dp++ = '?';
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
90 } else
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
91 *dp++ = c;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
92 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
93 /* will get here only if no newline sequence at the end */
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
94 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
95 output_line(buf);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 void
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
99 print_etm_output_raw()
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
100 {
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
101 char buf[MAX_PKT_FROM_TARGET*3+2];
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
102 int i;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
103 char *dp;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
104
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
105 dp = buf;
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
106 strcpy(dp, "ETM:");
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
107 dp += 4;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
108 for (i = 1; i < rxpkt_len; i++) {
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
109 sprintf(dp, " %02X", rxpkt[i]);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
110 dp += 3;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
111 }
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
112 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
113 output_line(buf);
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
114 }
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
115
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
116 void
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
117 print_unknown_packet()
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
118 {
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
119 char buf[MAX_PKT_FROM_TARGET*3+5];
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
120 int i;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
121 char *dp;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
122
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
123 dp = buf;
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
124 strcpy(dp, "UNK:");
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
125 dp += 4;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
126 for (i = 0; i < rxpkt_len; i++) {
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
127 sprintf(dp, " %02X", rxpkt[i]);
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
128 dp += 3;
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
129 }
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
130 *dp = '\0';
174
3256dc6e84ae rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
131 output_line(buf);
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
132 }