-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.h
26 lines (26 loc) · 1.06 KB
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void hexDump(unsigned char *buf, uint16_t len) {
char alphabet[17] = "0123456789abcdef";
Serial.print(F(" +------------------------------------------------+ +----------------+\n"));
Serial.print(F(" |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f | | ASCII |\n"));
for (uint16_t i = 0; i < len; i += 16) {
if (i % 128 == 0)
Serial.print(F(" +------------------------------------------------+ +----------------+\n"));
char s[] = "| | | |\n";
uint8_t ix = 1, iy = 52;
for (uint8_t j = 0; j < 16; j++) {
if (i + j < len) {
uint8_t c = buf[i + j];
s[ix++] = alphabet[(c >> 4) & 0x0F];
s[ix++] = alphabet[c & 0x0F];
ix++;
if (c > 31 && c < 128) s[iy++] = c;
else s[iy++] = '.';
}
}
uint8_t index = i / 16;
if (i < 256) Serial.write(' ');
Serial.print(index, HEX); Serial.write('.');
Serial.print(s);
}
Serial.print(F(" +------------------------------------------------+ +----------------+\n"));
}