Control a robot over the internet using UDP and a Wifly module (WiFi).

Dependencies:   Motor TextLCD WiflyInterface mbed-rtos mbed

Committer:
apatel336
Date:
Thu Oct 17 13:27:56 2013 +0000
Revision:
0:c0dc3a76f3d4
Initial Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
apatel336 0:c0dc3a76f3d4 1 /* WiflyInterface.h */
apatel336 0:c0dc3a76f3d4 2 /* Copyright (C) 2012 mbed.org, MIT License
apatel336 0:c0dc3a76f3d4 3 *
apatel336 0:c0dc3a76f3d4 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
apatel336 0:c0dc3a76f3d4 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
apatel336 0:c0dc3a76f3d4 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
apatel336 0:c0dc3a76f3d4 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
apatel336 0:c0dc3a76f3d4 8 * furnished to do so, subject to the following conditions:
apatel336 0:c0dc3a76f3d4 9 *
apatel336 0:c0dc3a76f3d4 10 * The above copyright notice and this permission notice shall be included in all copies or
apatel336 0:c0dc3a76f3d4 11 * substantial portions of the Software.
apatel336 0:c0dc3a76f3d4 12 *
apatel336 0:c0dc3a76f3d4 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
apatel336 0:c0dc3a76f3d4 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
apatel336 0:c0dc3a76f3d4 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
apatel336 0:c0dc3a76f3d4 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
apatel336 0:c0dc3a76f3d4 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
apatel336 0:c0dc3a76f3d4 18 */
apatel336 0:c0dc3a76f3d4 19
apatel336 0:c0dc3a76f3d4 20 #ifndef WIFLYINTERFACE_H_
apatel336 0:c0dc3a76f3d4 21 #define WIFLYINTERFACE_H_
apatel336 0:c0dc3a76f3d4 22
apatel336 0:c0dc3a76f3d4 23 #include "Wifly.h"
apatel336 0:c0dc3a76f3d4 24
apatel336 0:c0dc3a76f3d4 25 /** Interface using Wifly to connect to an IP-based network
apatel336 0:c0dc3a76f3d4 26 *
apatel336 0:c0dc3a76f3d4 27 */
apatel336 0:c0dc3a76f3d4 28 class WiflyInterface: public Wifly {
apatel336 0:c0dc3a76f3d4 29 public:
apatel336 0:c0dc3a76f3d4 30
apatel336 0:c0dc3a76f3d4 31 /**
apatel336 0:c0dc3a76f3d4 32 * Constructor
apatel336 0:c0dc3a76f3d4 33 *
apatel336 0:c0dc3a76f3d4 34 * \param tx mbed pin to use for tx line of Serial interface
apatel336 0:c0dc3a76f3d4 35 * \param rx mbed pin to use for rx line of Serial interface
apatel336 0:c0dc3a76f3d4 36 * \param reset reset pin of the wifi module ()
apatel336 0:c0dc3a76f3d4 37 * \param tcp_status connection status pin of the wifi module (GPIO 6)
apatel336 0:c0dc3a76f3d4 38 * \param ssid ssid of the network
apatel336 0:c0dc3a76f3d4 39 * \param phrase WEP or WPA key
apatel336 0:c0dc3a76f3d4 40 * \param sec Security type (NONE, WEP_128 or WPA)
apatel336 0:c0dc3a76f3d4 41 */
apatel336 0:c0dc3a76f3d4 42 WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec = NONE);
apatel336 0:c0dc3a76f3d4 43
apatel336 0:c0dc3a76f3d4 44 /** Initialize the interface with DHCP.
apatel336 0:c0dc3a76f3d4 45 * Initialize the interface and configure it to use DHCP (no connection at this point).
apatel336 0:c0dc3a76f3d4 46 * \return 0 on success, a negative number on failure
apatel336 0:c0dc3a76f3d4 47 */
apatel336 0:c0dc3a76f3d4 48 int init(); //With DHCP
apatel336 0:c0dc3a76f3d4 49
apatel336 0:c0dc3a76f3d4 50 /** Initialize the interface with a static IP address.
apatel336 0:c0dc3a76f3d4 51 * Initialize the interface and configure it with the following static configuration (no connection at this point).
apatel336 0:c0dc3a76f3d4 52 * \param ip the IP address to use
apatel336 0:c0dc3a76f3d4 53 * \param mask the IP address mask
apatel336 0:c0dc3a76f3d4 54 * \param gateway the gateway to use
apatel336 0:c0dc3a76f3d4 55 * \return 0 on success, a negative number on failure
apatel336 0:c0dc3a76f3d4 56 */
apatel336 0:c0dc3a76f3d4 57 int init(const char* ip, const char* mask, const char* gateway);
apatel336 0:c0dc3a76f3d4 58
apatel336 0:c0dc3a76f3d4 59 /** Connect
apatel336 0:c0dc3a76f3d4 60 * Bring the interface up, start DHCP if needed.
apatel336 0:c0dc3a76f3d4 61 * \return 0 on success, a negative number on failure
apatel336 0:c0dc3a76f3d4 62 */
apatel336 0:c0dc3a76f3d4 63 int connect();
apatel336 0:c0dc3a76f3d4 64
apatel336 0:c0dc3a76f3d4 65 /** Disconnect
apatel336 0:c0dc3a76f3d4 66 * Bring the interface down
apatel336 0:c0dc3a76f3d4 67 * \return 0 on success, a negative number on failure
apatel336 0:c0dc3a76f3d4 68 */
apatel336 0:c0dc3a76f3d4 69 int disconnect();
apatel336 0:c0dc3a76f3d4 70
apatel336 0:c0dc3a76f3d4 71 /** Get IP address
apatel336 0:c0dc3a76f3d4 72 *
apatel336 0:c0dc3a76f3d4 73 * @ returns ip address
apatel336 0:c0dc3a76f3d4 74 */
apatel336 0:c0dc3a76f3d4 75 char* getIPAddress();
apatel336 0:c0dc3a76f3d4 76
apatel336 0:c0dc3a76f3d4 77 private:
apatel336 0:c0dc3a76f3d4 78 char ip_string[20];
apatel336 0:c0dc3a76f3d4 79 bool ip_set;
apatel336 0:c0dc3a76f3d4 80 };
apatel336 0:c0dc3a76f3d4 81
apatel336 0:c0dc3a76f3d4 82 #include "TCPSocketConnection.h"
apatel336 0:c0dc3a76f3d4 83 #include "TCPSocketServer.h"
apatel336 0:c0dc3a76f3d4 84 #include "UDPSocket.h"
apatel336 0:c0dc3a76f3d4 85
apatel336 0:c0dc3a76f3d4 86 #endif /* WIFLYINTERFACE_H_ */