Serial UART snooper. Connect RX and TX of the UUT to 2 x RX pins on mbed to inspect the traffic in both directions
Dependencies: MODSERIAL Terminal mbed
Revision 1:2ca85ee43b49, committed 2012-07-15
- Comitter:
- cbayley
- Date:
- Sun Jul 15 21:54:30 2012 +0000
- Parent:
- 0:cb9d37ec851e
- Child:
- 2:60e6df8211f2
- Commit message:
- Version2; HexDump sytle
Changed in this revision
Terminal.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Terminal.lib Fri Jul 13 03:39:47 2012 +0000 +++ b/Terminal.lib Sun Jul 15 21:54:30 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/simon/code/Terminal/#85184c13476c +http://mbed.org/users/simon/code/Terminal/#543e8e498e09
--- a/main.cpp Fri Jul 13 03:39:47 2012 +0000 +++ b/main.cpp Sun Jul 15 21:54:30 2012 +0000 @@ -24,6 +24,8 @@ DigitalIn nCTS(p18); DigitalIn nRTS(p19); +#define HEX_PANE 0 +#define ASC_PANE 60 #define BAUD (115200) @@ -33,12 +35,13 @@ #define LT_BLUE (0xa0a0ff) #define GREEN (0x00ff00) #define YELLOW (0xffff00) +#define WHITE (0xffffff) #define COLOR_IN_ASC BLUE -#define COLOR_IN_HEX GREEN +#define COLOR_IN_HEX BLUE #define COLOR_OUT_ASC RED -#define COLOR_OUT_HEX YELLOW +#define COLOR_OUT_HEX RED void offCTSLed(void) { @@ -87,6 +90,7 @@ int main() { char c=0; + int col=0,row=0; pc.baud(BAUD); wt.baud(BAUD); r8.baud(BAUD); @@ -102,62 +106,85 @@ // wt.attach(&rxCallbackWT, MODSERIAL::RxIrq); // r8.attach(&rxCallbackR8, MODSERIAL::RxIrq); - + pc.printf("\033[49m"); + pc.cls(); pc.foreground(GREEN); - pc.printf("\n==== Snoop dog ready... ===\n"); + //pc.background(WHITE); + pc.locate(0,0); + pc.printf("==== Snoop dog ready... ===\n"); + col = 0; + pc.printf("\033[48;5;249m"); while(1) { //} ledCTS = !nCTS; ledRTS = !nRTS; - if ( r8.readable() ) + if (r8.readable() || wt.readable() ) { - while ( r8.readable() /*&& c != '\r' */) + if ( r8.readable() ) { c = r8.getc(); - #if SHOW_HEX - pc.foreground(COLOR_OUT_HEX); - pc.printf("%02X",c); - #endif + pc.locate(HEX_PANE + col*3,1+row); + pc.foreground(COLOR_OUT_HEX); + pc.printf("%02X ",c); + pc.locate(ASC_PANE + col,1+row); + if (c >=0x20 && c<=0x80) + { + pc.putc(c); + }else{ + pc.putc('.'); + } + }else{ + pc.locate(HEX_PANE + col*3,1+row); + pc.foreground(COLOR_OUT_HEX); + pc.printf(" "); + pc.locate(ASC_PANE + col,1+row); + pc.printf(" "); + } + + if ( wt.readable() ) + { + c = wt.getc(); + pc.locate(HEX_PANE + col*3,2+row); + pc.foreground(COLOR_IN_HEX); + pc.printf("%02X ",c); + pc.locate(ASC_PANE + col,2+row); if (c >=0x20 && c<=0x80) { - pc.foreground(COLOR_OUT_ASC); pc.putc(c); + }else{ + pc.putc('.'); } - else if ( /*c == '\r' ||*/ c== '\n' ) - pc.putc(c); - else - pc.putc(' '); - - - + }else{ + pc.locate(HEX_PANE + col*3,2+row); + pc.foreground(COLOR_IN_HEX); + pc.printf(" "); + pc.locate(ASC_PANE + col,2+row); + pc.printf(" "); } - c=NULL; - } - if ( wt.readable() ) - { - while ( wt.readable() /*&& c!='\r'*/ ) + + + if ( col++ > 15) { - c = wt.getc(); - #if SHOW_HEX - pc.foreground(COLOR_IN_HEX); - pc.printf("%02X",c); - #endif - if (c >=0x20 && c<=0x80) + static int alt = 0; + + col = 0; + if ( row < 40 ) + row += 2; + else { - pc.foreground(COLOR_IN_ASC); - pc.putc(c); + pc.printf("\033[49m"); + pc.printf("\033[2S"); } - else if ( /*c == '\r' ||*/ c== '\n' ) - pc.putc(c); + + if (alt++ % 2) + pc.printf("\033[48;5;249m"); else - pc.putc(' '); - + pc.printf("\033[48;5;253m"); + } - c=NULL; - } + } } - //*/ -} \ No newline at end of file +}