Tool to dump contents of a data buffer in traditional terminal format. Some VT100 color commands used.
Diff: PrintBuffer.cpp
- Revision:
- 2:e7f3ba216a14
- Parent:
- 1:8073086de8b7
- Child:
- 3:4a6123f2a4c9
--- a/PrintBuffer.cpp Tue May 13 18:47:41 2014 +0000 +++ b/PrintBuffer.cpp Thu Jan 29 19:18:27 2015 +0000 @@ -2,7 +2,18 @@ #include "PrintBuffer.h" extern RawSerial pc; -const char ESC = 0x1b; //ascii escape +//const char ESC = 0x1b; //ascii escape + +#define DOBLACK "\033[0;30;2m" +#define DORED "\033[0;31;2m" +#define DOGREEN "\033[0;32;2m" +#define DOYELLOW "\033[0;33;2m" +#define DOBLUE "\033[0;34;2m" +#define DOMAGENTA "\033[0;35;2m" +#define DOCYAN "\033[0;36;2m" +#define DOWHITE "\033[0;37;2m" +#define DODEFAULT "\033[0;39;2m" +#define DONONE "\033[0m" // Constructor PrintBuffer::PrintBuffer(const char* name) { @@ -13,7 +24,7 @@ // many 16 byte lines to print. int PrintBuffer::dump(const char* title, int BufferLines, int BufferOffset, const char buffer[]) { - pc.printf("\n%c[8;35;2m%s - lines: %d starting at: 0x%04x%c[0m\n", ESC, title, BufferLines, BufferOffset, ESC); + pc.printf("\n%s%s - lines: %d starting at: 0x%04x%s\n", DOMAGENTA, title, BufferLines, BufferOffset, DONONE); for(int i = BufferOffset; i < BufferLines * 16 + BufferOffset; i = i + 16) { pc.printf("%04x ", i); for(int s = 0; s < 8; s++) { @@ -26,7 +37,7 @@ pc.printf(" "); for(int s = 0; s < 8; s++) { if((buffer[s + i] < 0x20) || (buffer[s + i] > 0x7f)) { - pc.printf("."); + pc.printf("%s.%s", DOCYAN, DONONE); } else { pc.printf("%c", buffer[s + i]); } @@ -34,7 +45,7 @@ pc.printf(" "); for(int s = 0; s < 8; s++) { if((buffer[s + i + 8] < 0x20) || (buffer[s + i + 8] > 0x7f)) { - pc.printf("."); + pc.printf("%s.%s", DOCYAN, DONONE); } else { pc.printf("%c", buffer[s + i + 8]); } @@ -50,7 +61,7 @@ // many 16 byte lines to print. int PrintBuffer::dump_t(const char* title, int BufferLines, int BufferOffset, const uint8_t buffer[]) { - pc.printf("\n%c[8;35;2m%s - lines: %d starting at: 0x%04x%c[0m\n", ESC, title, BufferLines, BufferOffset, ESC); + pc.printf("\n%s%s - lines: %d starting at: 0x%04x%s\n", DOMAGENTA, title, BufferLines, BufferOffset, DONONE); for(int i = BufferOffset; i < BufferLines * 16 + BufferOffset; i = i + 16) { pc.printf("%04x ", i); for(int s = 0; s < 8; s++) { @@ -63,7 +74,7 @@ pc.printf(" "); for(int s = 0; s < 8; s++) { if((buffer[s + i] < 0x20) || (buffer[s + i] > 0x7f)) { - pc.printf("."); + pc.printf("%s.%s", DOCYAN, DONONE); } else { pc.printf("%c", buffer[s + i]); } @@ -71,7 +82,44 @@ pc.printf(" "); for(int s = 0; s < 8; s++) { if((buffer[s + i + 8] < 0x20) || (buffer[s + i + 8] > 0x7f)) { - pc.printf("."); + pc.printf("%s.%s", DOCYAN, DONONE); + } else { + pc.printf("%c", buffer[s + i + 8]); + } + } + pc.printf("\n"); + } + pc.printf("\n"); + return(0); +} + +//--------------------------------------------------------------------------------------------------------------------------------------// +// Used for doing a hex and ascii dump of the buffer. BufferLines tells PrintBuffer how +// many 16 byte lines to print. + +int PrintBuffer::dump_uc(const char* title, int BufferLines, int BufferOffset, const unsigned char buffer[]) { + pc.printf("\n%s%s - lines: %d starting at: 0x%04x%s\n", DOMAGENTA, title, BufferLines, BufferOffset, DONONE); + for(int i = BufferOffset; i < BufferLines * 16 + BufferOffset; i = i + 16) { + pc.printf("%04x ", i); + for(int s = 0; s < 8; s++) { + pc.printf("%02x ", buffer [s + i]); + } + pc.printf(" "); + for(int s = 0; s < 8; s++) { + pc.printf("%02x ", buffer[s + i + 8]); + } + pc.printf(" "); + for(int s = 0; s < 8; s++) { + if((buffer[s + i] < 0x20) || (buffer[s + i] > 0x7f)) { + pc.printf("%s.%s", DOCYAN, DONONE); + } else { + pc.printf("%c", buffer[s + i]); + } + } + pc.printf(" "); + for(int s = 0; s < 8; s++) { + if((buffer[s + i + 8] < 0x20) || (buffer[s + i + 8] > 0x7f)) { + pc.printf("%s.%s", DOCYAN, DONONE); } else { pc.printf("%c", buffer[s + i + 8]); }