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

Files at this revision

API Documentation at this revision

Comitter:
cbayley
Date:
Fri Jul 13 03:39:47 2012 +0000
Child:
1:2ca85ee43b49
Commit message:
Version 1

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Fri Jul 13 03:39:47 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODSERIAL/#af2af4c61c2f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Terminal.lib	Fri Jul 13 03:39:47 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Terminal/#85184c13476c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 13 03:39:47 2012 +0000
@@ -0,0 +1,163 @@
+// 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 BAUD (115200)
+
+#define RED     (0xff0000)
+#define LT_RED  (0xffa0a0)
+#define BLUE    (0x0000ff)
+#define LT_BLUE (0xa0a0ff)
+#define GREEN   (0x00ff00)
+#define YELLOW  (0xffff00)
+
+
+#define COLOR_IN_ASC    BLUE
+#define COLOR_IN_HEX    GREEN
+#define COLOR_OUT_ASC   RED
+#define COLOR_OUT_HEX   YELLOW
+
+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;
+    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.foreground(GREEN);
+    pc.printf("\n==== Snoop dog ready... ===\n");
+
+    while(1)
+    {
+    //}
+        ledCTS = !nCTS;
+        ledRTS = !nRTS;
+    
+        if ( r8.readable()  )
+        {
+            while ( r8.readable() /*&& c != '\r' */)
+            {
+                c = r8.getc();
+                #if SHOW_HEX
+                    pc.foreground(COLOR_OUT_HEX);
+                    pc.printf("%02X",c);
+                #endif
+                if (c >=0x20 && c<=0x80)
+                {
+                    pc.foreground(COLOR_OUT_ASC);
+                    pc.putc(c);
+                }
+                else if ( /*c == '\r' ||*/ c== '\n' )
+                    pc.putc(c);
+                else
+                    pc.putc(' ');
+               
+
+                
+            }
+            c=NULL;
+        }
+        if ( wt.readable() )
+        {   
+            while ( wt.readable() /*&& c!='\r'*/ )
+            {
+                c = wt.getc();
+                #if SHOW_HEX
+                    pc.foreground(COLOR_IN_HEX);
+                    pc.printf("%02X",c);
+                #endif
+                if (c >=0x20 && c<=0x80)
+                {
+                    pc.foreground(COLOR_IN_ASC);
+                    pc.putc(c);
+                }
+                else if ( /*c == '\r' ||*/ c== '\n' )
+                    pc.putc(c);
+                else
+                    pc.putc(' ');
+                    
+            }
+            c=NULL;
+        }    
+    }
+    //*/
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jul 13 03:39:47 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4c0c40fd0593
\ No newline at end of file