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.
Fork of WIZnetInterface by
EthernetInterface.h
00001 /* Copyright (C) 2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #pragma once 00020 #include "eth_arch.h" 00021 /** Interface using Wiznet chip to connect to an IP-based network 00022 * 00023 */ 00024 class EthernetInterface: public WIZnet_Chip { 00025 public: 00026 00027 #if (not defined TARGET_WIZwiki_W7500) && (not defined TARGET_WIZwiki_W7500P) && (not defined TARGET_WIZwiki_W7500ECO) 00028 00029 /** 00030 * Constructor 00031 * 00032 * \param mosi mbed pin to use for SPI 00033 * \param miso mbed pin to use for SPI 00034 * \param sclk mbed pin to use for SPI 00035 * \param cs chip select of the WIZnet_Chip 00036 * \param reset reset pin of the WIZnet_Chip 00037 */ 00038 EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); 00039 EthernetInterface(SPI* spi, PinName cs, PinName reset); 00040 #endif 00041 ~EthernetInterface(); 00042 00043 /** Initialize the interface with DHCP. 00044 * Initialize the interface and configure it to use DHCP (no connection at this point). 00045 * \return 0 on success, a negative number on failure 00046 */ 00047 int init(); //With DHCP 00048 int init(uint8_t * mac); //With DHCP 00049 00050 /** Initialize the interface with a static IP address. 00051 * Initialize the interface and configure it with the following static configuration (no connection at this point). 00052 * \param ip the IP address to use 00053 * \param mask the IP address mask 00054 * \param gateway the gateway to use 00055 * \param dnsServer the DNS server to use 00056 * \return 0 on success, a negative number on failure 00057 */ 00058 int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway, const char* dnsServer = NULL); 00059 00060 /** Connect 00061 * Bring the interface up, start DHCP if needed. 00062 * \return 0 on success, a negative number on failure 00063 */ 00064 int connect(const char *hostname = NULL); 00065 00066 /** Disconnect 00067 * Bring the interface down 00068 * \return 0 on success, a negative number on failure 00069 */ 00070 int disconnect(); 00071 00072 /** Get IP address & MAC address 00073 * 00074 * @ returns ip address 00075 */ 00076 char* getIPAddress(); 00077 char* getNetworkMask(); 00078 char* getGateway(); 00079 char* getDNSServer(); 00080 char* getMACAddress(); 00081 int getLeaseTime() { return leaseTime; }; 00082 int getLeaseStart() { return leaseStart; }; 00083 char *getDomainName(void) { return domainName; }; 00084 int IPrenew(int timeout_ms = 15*1000); 00085 00086 private: 00087 char ip_string[20]; 00088 char mask_string[20]; 00089 char gw_string[20]; 00090 char dns_string[20]; 00091 char mac_string[20]; 00092 bool ip_set; 00093 uint32_t leaseStart; 00094 char *domainName; 00095 const char *_hostname; 00096 }; 00097 00098 #include "TCPSocketConnection.h" 00099 #include "TCPSocketServer.h" 00100 #include "UDPSocket.h"
Generated on Tue Jul 12 2022 17:13:34 by
1.7.2
