![](/media/cache/profiles/debfdc81854eac26ec993b55a659c6e1.jpg.50x50_q85.jpg)
mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
EthernetInterface/EthernetInterface.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* EthernetInterface.h */ |
mbedAustin | 11:cada08fc8a70 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
mbedAustin | 11:cada08fc8a70 | 3 | * |
mbedAustin | 11:cada08fc8a70 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mbedAustin | 11:cada08fc8a70 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
mbedAustin | 11:cada08fc8a70 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
mbedAustin | 11:cada08fc8a70 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
mbedAustin | 11:cada08fc8a70 | 8 | * furnished to do so, subject to the following conditions: |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
mbedAustin | 11:cada08fc8a70 | 11 | * substantial portions of the Software. |
mbedAustin | 11:cada08fc8a70 | 12 | * |
mbedAustin | 11:cada08fc8a70 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mbedAustin | 11:cada08fc8a70 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mbedAustin | 11:cada08fc8a70 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mbedAustin | 11:cada08fc8a70 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mbedAustin | 11:cada08fc8a70 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mbedAustin | 11:cada08fc8a70 | 18 | */ |
mbedAustin | 11:cada08fc8a70 | 19 | |
mbedAustin | 11:cada08fc8a70 | 20 | #ifndef ETHERNETINTERFACE_H_ |
mbedAustin | 11:cada08fc8a70 | 21 | #define ETHERNETINTERFACE_H_ |
mbedAustin | 11:cada08fc8a70 | 22 | |
mbedAustin | 11:cada08fc8a70 | 23 | #if !defined(TARGET_LPC1768) && !defined(TARGET_LPC4088) && !defined(TARGET_LPC4088_DM) && !defined(TARGET_K64F) && !defined(TARGET_RZ_A1H) && !defined(TARGET_STM32F4) |
mbedAustin | 11:cada08fc8a70 | 24 | #error The Ethernet Interface library is not supported on this target |
mbedAustin | 11:cada08fc8a70 | 25 | #endif |
mbedAustin | 11:cada08fc8a70 | 26 | |
mbedAustin | 11:cada08fc8a70 | 27 | #include "rtos.h" |
mbedAustin | 11:cada08fc8a70 | 28 | #include "lwip/netif.h" |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | /** Interface using Ethernet to connect to an IP-based network |
mbedAustin | 11:cada08fc8a70 | 31 | * |
mbedAustin | 11:cada08fc8a70 | 32 | */ |
mbedAustin | 11:cada08fc8a70 | 33 | class EthernetInterface { |
mbedAustin | 11:cada08fc8a70 | 34 | public: |
mbedAustin | 11:cada08fc8a70 | 35 | /** Initialize the interface with DHCP. |
mbedAustin | 11:cada08fc8a70 | 36 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
mbedAustin | 11:cada08fc8a70 | 37 | * \return 0 on success, a negative number on failure |
mbedAustin | 11:cada08fc8a70 | 38 | */ |
mbedAustin | 11:cada08fc8a70 | 39 | static int init(); //With DHCP |
mbedAustin | 11:cada08fc8a70 | 40 | |
mbedAustin | 11:cada08fc8a70 | 41 | /** Initialize the interface with a static IP address. |
mbedAustin | 11:cada08fc8a70 | 42 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
mbedAustin | 11:cada08fc8a70 | 43 | * \param ip the IP address to use |
mbedAustin | 11:cada08fc8a70 | 44 | * \param mask the IP address mask |
mbedAustin | 11:cada08fc8a70 | 45 | * \param gateway the gateway to use |
mbedAustin | 11:cada08fc8a70 | 46 | * \return 0 on success, a negative number on failure |
mbedAustin | 11:cada08fc8a70 | 47 | */ |
mbedAustin | 11:cada08fc8a70 | 48 | static int init(const char* ip, const char* mask, const char* gateway); |
mbedAustin | 11:cada08fc8a70 | 49 | |
mbedAustin | 11:cada08fc8a70 | 50 | /** Connect |
mbedAustin | 11:cada08fc8a70 | 51 | * Bring the interface up, start DHCP if needed. |
mbedAustin | 11:cada08fc8a70 | 52 | * \param timeout_ms timeout in ms (default: (15)s). |
mbedAustin | 11:cada08fc8a70 | 53 | * \return 0 on success, a negative number on failure |
mbedAustin | 11:cada08fc8a70 | 54 | */ |
mbedAustin | 11:cada08fc8a70 | 55 | static int connect(unsigned int timeout_ms=15000); |
mbedAustin | 11:cada08fc8a70 | 56 | |
mbedAustin | 11:cada08fc8a70 | 57 | /** Disconnect |
mbedAustin | 11:cada08fc8a70 | 58 | * Bring the interface down |
mbedAustin | 11:cada08fc8a70 | 59 | * \return 0 on success, a negative number on failure |
mbedAustin | 11:cada08fc8a70 | 60 | */ |
mbedAustin | 11:cada08fc8a70 | 61 | static int disconnect(); |
mbedAustin | 11:cada08fc8a70 | 62 | |
mbedAustin | 11:cada08fc8a70 | 63 | /** Get the MAC address of your Ethernet interface |
mbedAustin | 11:cada08fc8a70 | 64 | * \return a pointer to a string containing the MAC address |
mbedAustin | 11:cada08fc8a70 | 65 | */ |
mbedAustin | 11:cada08fc8a70 | 66 | static char* getMACAddress(); |
mbedAustin | 11:cada08fc8a70 | 67 | |
mbedAustin | 11:cada08fc8a70 | 68 | /** Get the IP address of your Ethernet interface |
mbedAustin | 11:cada08fc8a70 | 69 | * \return a pointer to a string containing the IP address |
mbedAustin | 11:cada08fc8a70 | 70 | */ |
mbedAustin | 11:cada08fc8a70 | 71 | static char* getIPAddress(); |
mbedAustin | 11:cada08fc8a70 | 72 | |
mbedAustin | 11:cada08fc8a70 | 73 | /** Get the Gateway address of your Ethernet interface |
mbedAustin | 11:cada08fc8a70 | 74 | * \return a pointer to a string containing the Gateway address |
mbedAustin | 11:cada08fc8a70 | 75 | */ |
mbedAustin | 11:cada08fc8a70 | 76 | static char* getGateway(); |
mbedAustin | 11:cada08fc8a70 | 77 | |
mbedAustin | 11:cada08fc8a70 | 78 | /** Get the Network mask of your Ethernet interface |
mbedAustin | 11:cada08fc8a70 | 79 | * \return a pointer to a string containing the Network mask |
mbedAustin | 11:cada08fc8a70 | 80 | */ |
mbedAustin | 11:cada08fc8a70 | 81 | static char* getNetworkMask(); |
mbedAustin | 11:cada08fc8a70 | 82 | }; |
mbedAustin | 11:cada08fc8a70 | 83 | |
mbedAustin | 11:cada08fc8a70 | 84 | #include "TCPSocketConnection.h" |
mbedAustin | 11:cada08fc8a70 | 85 | #include "TCPSocketServer.h" |
mbedAustin | 11:cada08fc8a70 | 86 | |
mbedAustin | 11:cada08fc8a70 | 87 | #include "Endpoint.h" |
mbedAustin | 11:cada08fc8a70 | 88 | #include "UDPSocket.h" |
mbedAustin | 11:cada08fc8a70 | 89 | |
mbedAustin | 11:cada08fc8a70 | 90 | #endif /* ETHERNETINTERFACE_H_ */ |