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 /* mbed Ethernet class demo 00002 * Copyright (c) 2009 rmeyer 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 */ 00005 00006 #include "mbed.h" 00007 #include "hexview.h" 00008 00009 DigitalOut led(LED4); 00010 Ethernet eth; 00011 00012 unsigned short htons(unsigned short n) { // Host short to network shor 00013 return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); // Byte swapping 00014 } 00015 00016 void show(char *buf, int size) { 00017 printf("ETH: Src: %02hX:%02hX:%02hX:%02hX:%02hX:%02hX ", 00018 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); 00019 printf("Dst: %02hX:%02hX:%02hX:%02hX:%02hX:%02hX ", 00020 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 00021 00022 unsigned int type = (buf[12] << 8) | (buf[13]); 00023 printf("Type: %hd\n", htons( type)); 00024 00025 hexview2(buf, size); 00026 } 00027 00028 00029 int main() { 00030 char buffer[0x300]; 00031 int size = 0; 00032 00033 while(1) { 00034 if((size = eth.receive()) != 0) { 00035 eth.read(buffer, size); 00036 show(buffer, size); 00037 } 00038 00039 led = !led; 00040 wait(0.2); 00041 } 00042 }
Generated on Fri Jul 15 2022 03:13:59 by
1.7.2