Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "Ethernet.h" 00003 #include "hexview.h" 00004 00005 using namespace mbed; 00006 00007 DigitalOut led4(LED4); 00008 00009 Ethernet eth; 00010 00011 /* 00012 __packed struct eth { 00013 unsigned char dst[6]; 00014 unsigned char src[6]; 00015 unsigned short type; 00016 }; 00017 00018 void show(char *buffer, int size) { 00019 eth *e = (eth *)buffer; 00020 printf("Destination: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n", 00021 e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5]); 00022 printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n", 00023 e->src[0], e->src[1], e->src[2], e->src[3], e->src[4], e->src[5]); 00024 00025 printf("Type %hd\n", eth->type); 00026 hexview(buffer, size); 00027 } 00028 */ 00029 00030 unsigned short htons(unsigned short n) { // Host short to network shor 00031 return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); // Byte swapping 00032 } 00033 00034 void show(char *buf, int size) { 00035 printf("Destination: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n", 00036 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 00037 printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n", 00038 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); 00039 00040 printf("Type %hd\n", htons((short)buf[12])); 00041 00042 hexview(buf, size); 00043 } 00044 00045 00046 int main() { 00047 char buffer[0x600]; 00048 int size = 0; 00049 00050 while(1) { 00051 if((size = eth.receive()) != 0) { 00052 eth.read(buffer, size); 00053 show(buffer, size); 00054 } 00055 00056 led4 = 1; 00057 wait(0.2); 00058 led4 = 0; 00059 wait(0.2); 00060 } 00061 }
Generated on Sat Jul 23 2022 10:50:17 by
1.7.2