Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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