FreeCalypso > hg > freecalypso-tools
annotate rvinterf/libprint/hexdump.c @ 995:74024eb17e04
fc-loadtool help: improve language regarding 16 MiB flash chips
In FC project history, 16 MiB flash originally meant Pirelli DP-L10.
Then we got FCDEV3B with the same flash (our own design), but now we are
discovering more Calypso devices that used such large flash, both late
Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID
devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to
migrate to more generic or neutral language in associated documentation,
without giving elevated status to specific examples that drove our
early project history.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 21:11:12 +0000 |
parents | 65953c172f24 |
children |
rev | line source |
---|---|
928
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function contained in this module implements hex dump functionality: |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * an arbitrary binary packet is dumped in hex, line by line, calling an output |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * function for each line. |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 void |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 packet_hex_dump(src, srclen, outfunc) |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char *src; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 unsigned srclen; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 void (*outfunc)(); |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char *sp = src; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unsigned remain = srclen; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned offset = 0; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned chunk; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char line[80], *dp; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int i, c; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 while (remain) { |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 sprintf(line, "%04X: ", offset); |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 dp = line + 7; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 chunk = remain; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (chunk > 16) |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 chunk = 16; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 for (i = 0; i < 16; i++) { |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (i < chunk) |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 sprintf(dp, "%02X ", sp[i]); |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 else |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 strcpy(dp, " "); |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 dp += 3; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (i == 7 || i == 15) |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 *dp++ = ' '; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 for (i = 0; i < chunk; i++) { |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 c = sp[i]; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (c < ' ' || c > '~') |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 c = '.'; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 *dp++ = c; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 *dp = '\0'; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 outfunc(line); |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 sp += chunk; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 remain -= chunk; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 offset += chunk; |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
65953c172f24
rvinterf/lowlevel: new hex dump format
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |