annotate rvinterf/lowlevel/format.c @ 929:ab771ce34fac

rvinterf/lowlevel/format.c: get rid of static fmtbuf
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 05:56:08 +0000
parents 65953c172f24
children bb7a03cc1e43
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
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
17 extern void output_cont();
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
18
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 print_rv_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
927
4e243402f453 rvinterf/lowlevel: use libprint for backslash-escape output
Mychaela Falconia <falcon@freecalypso.org>
parents: 925
diff changeset
22 int i;
929
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
23 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
24 char *dp = fmtbuf;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 strcpy(dp, "RV ");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 dp += 3;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 /* 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
29 for (i = 1; i <= 4; i++) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 sprintf(dp, "%02X", rxpkt[i]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 dp += 2;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /* severity level */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 sprintf(dp, " %d ", rxpkt[5]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 dp = index(dp, '\0');
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
36 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
37 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 print_l1_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 int i, c;
929
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
44 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
45 char *dp = fmtbuf;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 strcpy(dp, "L1: ");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 dp += 4;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 for (i = 1; i < rxpkt_len; i++) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if ((i+1 < rxpkt_len) &&
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *dp = '\0';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (i+2 == rxpkt_len)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 dp = fmtbuf;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *dp++ = '+';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 *dp++ = ' ';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 i++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 c = rxpkt[i];
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
64 switch (c) {
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
65 case '\\':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
66 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
67 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
68 continue;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
69 case '\r':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
70 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
71 *dp++ = 'r';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
72 continue;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
73 case '\n':
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
74 *dp++ = '\\';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
75 *dp++ = 'n';
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
76 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
78 if (c >= ' ' && c <= '~')
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *dp++ = c;
924
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
80 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
81 sprintf(dp, "\\%d", c);
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
82 dp += 2;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
83 } else {
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
84 sprintf(dp, "\\x%02X", c);
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
85 dp += 4;
d452188587b4 rvinterf: begin change to backslash escape output format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
86 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 /* 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
89 *dp = '\0';
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 output_line(fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 print_g23_trace()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
929
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
96 char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */
ab771ce34fac rvinterf/lowlevel/format.c: get rid of static fmtbuf
Mychaela Falconia <falcon@freecalypso.org>
parents: 928
diff changeset
97
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 /* messy logic factored out into libg23 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 format_g23_packet(rxpkt, (int)rxpkt_len, fmtbuf);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 output_line(fmtbuf);
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
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 print_tm_output_raw()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
106 output_line("Rx Test Mode packet");
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
107 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
108 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 print_unknown_packet()
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {
928
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
113 output_line("Rx unknown packet format");
65953c172f24 rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents: 927
diff changeset
114 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
115 }