WIZnetInterface using namespace
Dependents: DualNetworkInterface-Basic
Fork of WIZnetInterface by
EthernetInterface.hpp
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.hpp" 00021 /** Interface using Wiznet chip to connect to an IP-based network 00022 * 00023 */ 00024 00025 namespace wiznet_space { 00026 00027 class EthernetInterface: public WIZnet_Chip { 00028 public: 00029 00030 #if not defined(TARGET_WIZwiki_W7500) 00031 /** 00032 * Constructor 00033 * 00034 * \param mosi mbed pin to use for SPI 00035 * \param miso mbed pin to use for SPI 00036 * \param sclk mbed pin to use for SPI 00037 * \param cs chip select of the WIZnet_Chip 00038 * \param reset reset pin of the WIZnet_Chip 00039 */ 00040 EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); 00041 EthernetInterface(SPI* spi, PinName cs, PinName reset); 00042 #endif 00043 00044 /** Initialize the interface with DHCP. 00045 * Initialize the interface and configure it to use DHCP (no connection at this point). 00046 * \return 0 on success, a negative number on failure 00047 */ 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 * \return 0 on success, a negative number on failure 00056 */ 00057 int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); 00058 00059 /** Connect 00060 * Bring the interface up, start DHCP if needed. 00061 * \return 0 on success, a negative number on failure 00062 */ 00063 int connect(); 00064 00065 /** Disconnect 00066 * Bring the interface down 00067 * \return 0 on success, a negative number on failure 00068 */ 00069 int disconnect(); 00070 00071 /** Get IP address & MAC address 00072 * 00073 * @ returns ip address 00074 */ 00075 char* getIPAddress(); 00076 char* getNetworkMask(); 00077 char* getGateway(); 00078 char* getMACAddress(); 00079 00080 int IPrenew(int timeout_ms = 15*1000); 00081 00082 private: 00083 char ip_string[20]; 00084 char mask_string[20]; 00085 char gw_string[20]; 00086 char mac_string[20]; 00087 bool ip_set; 00088 }; 00089 00090 } 00091 00092 #include "TCPSocketConnection.hpp" 00093 #include "TCPSocketServer.hpp" 00094 #include "UDPSocket.hpp"
Generated on Wed Jul 13 2022 05:21:37 by 1.7.2