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.
UipEthernet.h
00001 /* 00002 UipEthernet.h - Arduino implementation of a UIP wrapper class. 00003 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> 00004 All rights reserved. 00005 00006 Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com> 00007 00008 This program is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 #ifndef UIPETHERNET_h 00022 #define UIPETHERNET_h 00023 00024 //#define UIPETHERNET_DEBUG 00025 //#define UIPETHERNET_DEBUG_CHKSUM 00026 //#define UIPETHERNET_DEBUG_UDP 00027 //#define UIPETHERNET_DEBUG_CLIENT 00028 #include "mbed.h" 00029 #include "DhcpClient.h" 00030 #include "IpAddress.h" 00031 #include "utility/Enc28j60Eth.h" 00032 #include "TcpClient.h" 00033 #include "TcpServer.h" 00034 #include "UdpSocket.h" 00035 00036 extern "C" 00037 { 00038 #include "utility/uip_timer.h" 00039 #include "utility/uip.h" 00040 #include "utility/util.h" 00041 } 00042 00043 class UipEthernet 00044 { 00045 public: 00046 static UipEthernet* ethernet; 00047 static IpAddress dnsServerAddress; 00048 Enc28j60Eth enc28j60Eth; 00049 00050 UipEthernet (const uint8_t mac[6], PinName mosi, PinName miso, PinName sck, PinName cs); 00051 00052 int connect(unsigned long timeout = 60); 00053 void disconnect(); 00054 void set_network(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4); 00055 void set_network(IpAddress ip); 00056 void set_network(IpAddress ip, IpAddress dns); 00057 void set_network(IpAddress ip, IpAddress dns, IpAddress gateway); 00058 void set_network(IpAddress ip, IpAddress dns, IpAddress gateway, IpAddress subnet); 00059 void set_network(const char *ip_address, const char *netmask, const char *gateway); 00060 void tick(); 00061 IpAddress localIP(); 00062 IpAddress subnetMask(); 00063 IpAddress gatewayIP(); 00064 IpAddress dnsServerIP(); 00065 const char* get_ip_address(); 00066 void get_ip_address(SocketAddress* addr); 00067 const char* get_netmask(); 00068 void get_netmask(SocketAddress* addr); 00069 const char* get_gateway(); 00070 void get_gateway(SocketAddress* addr); 00071 static uint16_t chksum(uint16_t sum, const uint8_t* data, uint16_t len); 00072 static uint16_t ipchksum(); 00073 bool stoip4(const char *ip4addr, size_t len, void *dest); 00074 private: 00075 uint8_t *const _mac; 00076 IpAddress _ip; 00077 IpAddress _dns; 00078 IpAddress _gateway; 00079 IpAddress _subnet; 00080 static memhandle inPacket; 00081 static memhandle uipPacket; 00082 static uint8_t uipHeaderLen; 00083 static uint8_t packetState; 00084 DhcpClient dhcpClient; 00085 Timer periodicTimer; 00086 void init(const uint8_t* mac); 00087 bool network_send(); 00088 friend class TcpServer; 00089 friend class TcpClient; 00090 friend class UdpSocket; 00091 #if UIP_UDP 00092 uint16_t upper_layer_chksum(uint8_t proto); 00093 #endif 00094 friend uint16_t uip_ipchksum(); 00095 friend uint16_t uip_tcpchksum(); 00096 friend uint16_t uip_udpchksum(); 00097 friend void uipclient_appcall(); 00098 friend void uipudp_appcall(); 00099 00100 #if UIP_CONF_IPV6 00101 uint16_t uip_icmp6chksum (); 00102 #endif 00103 }; 00104 00105 #endif
Generated on Sun Feb 26 2023 10:14:24 by
1.7.2