This performs an ethernet sniff test. Copied from an existing ethernet sniff test and updated to work properly with the LISA, supporting output of content to the USB console. See also: http://mbed.org/users/rolf/code/ethsnif/

Dependencies:   C027-REVB mbed

Fork of ethsnif by Rolf Meyer

Files at this revision

API Documentation at this revision

Comitter:
dixter1
Date:
Sat Dec 14 00:53:08 2013 +0000
Parent:
0:29e2df9de9f1
Commit message:
First Version C027 Ethernet Sniff Test to Validate Ethernet Capability.

Changed in this revision

C027-REVB.lib Show annotated file Show diff for this revision Revisions of this file
hexview.h 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
diff -r 29e2df9de9f1 -r a7a52d202638 C027-REVB.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C027-REVB.lib	Sat Dec 14 00:53:08 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dixter1/code/C027-REVB/#db7c445289f5
diff -r 29e2df9de9f1 -r a7a52d202638 hexview.h
--- a/hexview.h	Fri Sep 04 12:24:03 2009 +0000
+++ b/hexview.h	Sat Dec 14 00:53:08 2013 +0000
@@ -22,8 +22,8 @@
             printf(" ");
         }
         if((i%16) == 15) {
-            printf("\n");
+            printf("\n\r");
         }
     }
-    printf("\n\n\n");
+    printf("\n\r\n\r\n\r");
 }
\ No newline at end of file
diff -r 29e2df9de9f1 -r a7a52d202638 main.cpp
--- a/main.cpp	Fri Sep 04 12:24:03 2009 +0000
+++ b/main.cpp	Sat Dec 14 00:53:08 2013 +0000
@@ -1,43 +1,26 @@
 #include "mbed.h"
+#include "C027.h"
 #include "Ethernet.h"
 #include "hexview.h"
 
 using namespace mbed;
 
-DigitalOut led4(LED4);
+DigitalOut led4(LED);
 
 Ethernet eth;
-
-/*
-__packed struct eth {
-    unsigned char    dst[6];
-    unsigned char    src[6];
-    unsigned short   type;
-};
-
-void show(char *buffer, int size) {
-    eth *e = (eth *)buffer;
-    printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
-            e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5]);
-    printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
-            e->src[0], e->src[1], e->src[2], e->src[3], e->src[4], e->src[5]);
-  
-    printf("Type %hd\n", eth->type);
-    hexview(buffer, size);
-}
-*/
+Serial pc(USBTX, USBRX);
 
 unsigned short htons(unsigned short n) {               // Host short to network shor
   return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);      // Byte swapping
 }
 
 void show(char *buf, int size) {
-    printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+    pc.printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n\r",
             buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
-    printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+    pc.printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n\r",
             buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
   
-    printf("Type %hd\n", htons((short)buf[12]));
+    pc.printf("Type %hd\n\r", htons((short)buf[12]));
     
     hexview(buf, size);
 }
@@ -46,16 +29,31 @@
 int main() {
     char buffer[0x600];
     int size = 0;
+    int led_toggle_count = 5;
+    
+ #if 0
+    while(1) {
+        led4 = !led4;
+        wait(0.2);
+    }
+#else
+    while( led_toggle_count-- > 0 )
+    {
+        led4 = !led4;
+        wait(0.2);
+    }
+#endif
+
+   // open the PC serial port and (use the same baudrate)
+    pc.baud(MDMBAUD);
+    
+    pc.printf( "Start ETHERNET Sniff Testing\n\r");
     
     while(1) {
         if((size = eth.receive()) != 0) {
+            led4=!led4;
             eth.read(buffer, size);
             show(buffer, size);
         }
-        
-        led4 = 1;
-        wait(0.2);
-        led4 = 0;
-        wait(0.2);
     }
 }