Control a robot over the internet using UDP and a Ethernet interface.

Dependencies:   EthernetInterface Motor TextLCD mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
apatel336
Date:
Thu Oct 17 13:26:38 2013 +0000
Revision:
0:1496281373a5
Initial Release

Who changed what in which revision?

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