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
main.cpp
- Committer:
- cbayley
- Date:
- 2012-07-15
- Revision:
- 1:2ca85ee43b49
- Parent:
- 0:cb9d37ec851e
- Child:
- 2:60e6df8211f2
File content as of revision 1:2ca85ee43b49:
// Relay bytes received as SPI slave to PC-USB-Serial #include "mbed.h" #include "Terminal.h" #include "MODSERIAL.h" #define SHOW_HEX 1 Terminal pc(USBTX,NC); //Serial r8(NC,p10); //Serial wt(NC,p14); MODSERIAL wt(NC,p10,2048); MODSERIAL r8(NC,p14,2048); //Serial pc(USBTX,NC); DigitalOut ledCTS(LED1); DigitalOut ledRTS(LED2); //DigitalOut ledOV(LED4); Timeout toCTSLed; Timeout toRTSLed; /*InterruptIn nCTS(p11); InterruptIn nRTS(p12); */ DigitalIn nCTS(p18); DigitalIn nRTS(p19); #define HEX_PANE 0 #define ASC_PANE 60 #define BAUD (115200) #define RED (0xff0000) #define LT_RED (0xffa0a0) #define BLUE (0x0000ff) #define LT_BLUE (0xa0a0ff) #define GREEN (0x00ff00) #define YELLOW (0xffff00) #define WHITE (0xffffff) #define COLOR_IN_ASC BLUE #define COLOR_IN_HEX BLUE #define COLOR_OUT_ASC RED #define COLOR_OUT_HEX RED void offCTSLed(void) { ledCTS = 0; } void onCTSLed(void) { ledCTS = 1; toCTSLed.attach(offCTSLed,0.1); } void offRTSLed(void) { ledRTS = 0; } void onRTSLed(void) { ledRTS = 1; toRTSLed.attach(offRTSLed,0.1); } void ctsFall(void) { onCTSLed(); } void rtsFall(void) { onRTSLed(); } // This function is called when a character goes into the RX buffer. void rxCallbackWT(MODSERIAL_IRQ_INFO *q) { //led3 = !led3; pc.foreground(COLOR_IN_ASC); pc.putc(wt.getc()); } void rxCallbackR8(MODSERIAL_IRQ_INFO *q) { //led3 = !led3; pc.foreground(COLOR_OUT_ASC); pc.putc(r8.getc()); } int main() { char c=0; int col=0,row=0; pc.baud(BAUD); wt.baud(BAUD); r8.baud(BAUD); nCTS.mode(PullUp); nRTS.mode(PullUp); /*nCTS.fall(ctsFall); nRTS.fall(rtsFall); */ // wt.attach(&rxCallbackWT, MODSERIAL::RxIrq); // r8.attach(&rxCallbackR8, MODSERIAL::RxIrq); pc.printf("\033[49m"); pc.cls(); pc.foreground(GREEN); //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() || wt.readable() ) { if ( r8.readable() ) { c = r8.getc(); 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.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(" "); } if ( col++ > 15) { static int alt = 0; col = 0; if ( row < 40 ) row += 2; else { pc.printf("\033[49m"); pc.printf("\033[2S"); } if (alt++ % 2) pc.printf("\033[48;5;249m"); else pc.printf("\033[48;5;253m"); } } } }