annotate rvinterf/lowlevel/format.c @ 950:bdd92dba7dd9

doc/Rvinterf-tools: document rvinterf -X option
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 07 Jun 2023 07:51:49 +0000
parents fab04df64690
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the decoding of Rx packets
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * into human-readable form.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
925
85d144f9fe56 rvinterf/lowlevel/format.c: forgot to add #include <ctype.h>
Mychaela Falconia <falcon@freecalypso.org>
parents: 924
diff changeset
7 #include <ctype.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../include/pktmux.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../include/limits.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern u_char rxpkt[];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern size_t rxpkt_len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
942
fab04df64690 rvinterf/lowlevel: replace libg23 with libprint
Mychaela Falconia <falcon@freecalypso.org>
parents: 932
diff changeset
17 extern void output_line();
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
18 extern void output_cont();
942
fab04df64690 rvinterf/lowlevel: replace libg23 with libprint
Mychaela Falconia <falcon@freecalypso.org>
parents: 932
diff changeset
19 extern void output_cont_logpref();
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
20
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 print_rv_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
927
4e243402f453 rvinterf/lowlevel: use libprint for backslash-escape output
Mychaela Falconia <falcon@freecalypso.org>
parents: 925
diff changeset
24 int i;
929
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
25 char fmtbuf[MAX_PKT_FROM_TARGET*4];
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
26 char *dp = fmtbuf;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 strcpy(dp, "RV ");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 dp += 3;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 /* the SWE static ID is sent MSB first */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 for (i = 1; i <= 4; i++) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sprintf(dp, "%02X", rxpkt[i]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dp += 2;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /* severity level */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 sprintf(dp, " %d ", rxpkt[5]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 dp = index(dp, '\0');
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
38 safe_print_trace(rxpkt + 6, (int)rxpkt_len - 6, dp);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 print_l1_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 int i, c;
929
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
46 char fmtbuf[MAX_PKT_FROM_TARGET*4+1];
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
47 char *dp = fmtbuf;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 strcpy(dp, "L1: ");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 dp += 4;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 for (i = 1; i < rxpkt_len; i++) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if ((i+1 < rxpkt_len) &&
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *dp = '\0';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (i+2 == rxpkt_len)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 dp = fmtbuf;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 *dp++ = '+';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *dp++ = ' ';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 i++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 c = rxpkt[i];
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
66 switch (c) {
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
67 case '\\':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
68 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
69 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
70 continue;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
71 case '\r':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
72 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
73 *dp++ = 'r';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
74 continue;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
75 case '\n':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
76 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
77 *dp++ = 'n';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
78 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
80 if (c >= ' ' && c <= '~')
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 *dp++ = c;
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
82 else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) {
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
83 sprintf(dp, "\\%d", c);
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
84 dp += 2;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
85 } else {
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
86 sprintf(dp, "\\x%02X", c);
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
87 dp += 4;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
88 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 /* will get here only if no newline sequence at the end */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 *dp = '\0';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 print_g23_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
942
fab04df64690 rvinterf/lowlevel: replace libg23 with libprint
Mychaela Falconia <falcon@freecalypso.org>
parents: 932
diff changeset
98 format_gpf_packet(rxpkt, (unsigned) rxpkt_len, "", output_line,
fab04df64690 rvinterf/lowlevel: replace libg23 with libprint
Mychaela Falconia <falcon@freecalypso.org>
parents: 932
diff changeset
99 output_cont_logpref);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 print_tm_output_raw()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
931
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
105 int i;
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
106 char fmtbuf[MAX_PKT_FROM_TARGET*3+1];
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
107 char *dp = fmtbuf;
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
108
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
109 strcpy(dp, "TM:");
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
110 dp += 3;
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
111 for (i = 1; i < rxpkt_len; i++) {
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
112 sprintf(dp, " %02X", rxpkt[i]);
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
113 dp += 3;
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
114 }
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
115 *dp = '\0';
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
116 output_line(fmtbuf);
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
117 }
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
118
bb7a03cc1e43 rvtdump, tfc139: restore old 'TM:' output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 929
diff changeset
119 void
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 print_unknown_packet()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 {
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
122 output_line("Rx unknown packet format");
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
123 packet_hex_dump(rxpkt, (unsigned) rxpkt_len, output_cont);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }