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 /* Copyright (C) 2012 mbed.org, MIT License
apatel336 0:c0dc3a76f3d4 2 *
apatel336 0:c0dc3a76f3d4 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
apatel336 0:c0dc3a76f3d4 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
apatel336 0:c0dc3a76f3d4 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
apatel336 0:c0dc3a76f3d4 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
apatel336 0:c0dc3a76f3d4 7 * furnished to do so, subject to the following conditions:
apatel336 0:c0dc3a76f3d4 8 *
apatel336 0:c0dc3a76f3d4 9 * The above copyright notice and this permission notice shall be included in all copies or
apatel336 0:c0dc3a76f3d4 10 * substantial portions of the Software.
apatel336 0:c0dc3a76f3d4 11 *
apatel336 0:c0dc3a76f3d4 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
apatel336 0:c0dc3a76f3d4 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
apatel336 0:c0dc3a76f3d4 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
apatel336 0:c0dc3a76f3d4 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
apatel336 0:c0dc3a76f3d4 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
apatel336 0:c0dc3a76f3d4 17 */
apatel336 0:c0dc3a76f3d4 18
apatel336 0:c0dc3a76f3d4 19 #ifndef UDPSOCKET_H
apatel336 0:c0dc3a76f3d4 20 #define UDPSOCKET_H
apatel336 0:c0dc3a76f3d4 21
apatel336 0:c0dc3a76f3d4 22 #include "Endpoint.h"
apatel336 0:c0dc3a76f3d4 23 #include "Socket.h"
apatel336 0:c0dc3a76f3d4 24
apatel336 0:c0dc3a76f3d4 25 #include <cstdint>
apatel336 0:c0dc3a76f3d4 26
apatel336 0:c0dc3a76f3d4 27 /**
apatel336 0:c0dc3a76f3d4 28 UDP Socket
apatel336 0:c0dc3a76f3d4 29 */
apatel336 0:c0dc3a76f3d4 30 class UDPSocket: public Socket {
apatel336 0:c0dc3a76f3d4 31
apatel336 0:c0dc3a76f3d4 32 public:
apatel336 0:c0dc3a76f3d4 33 /** Instantiate an UDP Socket.
apatel336 0:c0dc3a76f3d4 34 */
apatel336 0:c0dc3a76f3d4 35 UDPSocket();
apatel336 0:c0dc3a76f3d4 36
apatel336 0:c0dc3a76f3d4 37 /** Init the UDP Client Socket without binding it to any specific port
apatel336 0:c0dc3a76f3d4 38 \return 0 on success, -1 on failure.
apatel336 0:c0dc3a76f3d4 39 */
apatel336 0:c0dc3a76f3d4 40 int init(void);
apatel336 0:c0dc3a76f3d4 41
apatel336 0:c0dc3a76f3d4 42 /** Bind a UDP Server Socket to a specific port
apatel336 0:c0dc3a76f3d4 43 \param port The port to listen for incoming connections on
apatel336 0:c0dc3a76f3d4 44 \return 0 on success, -1 on failure.
apatel336 0:c0dc3a76f3d4 45 */
apatel336 0:c0dc3a76f3d4 46 int bind(int port = -1);
apatel336 0:c0dc3a76f3d4 47
apatel336 0:c0dc3a76f3d4 48 /** Send a packet to a remote endpoint
apatel336 0:c0dc3a76f3d4 49 \param remote The remote endpoint
apatel336 0:c0dc3a76f3d4 50 \param packet The packet to be sent
apatel336 0:c0dc3a76f3d4 51 \param length The length of the packet to be sent
apatel336 0:c0dc3a76f3d4 52 \return the number of written bytes on success (>=0) or -1 on failure
apatel336 0:c0dc3a76f3d4 53 */
apatel336 0:c0dc3a76f3d4 54 int sendTo(Endpoint &remote, char *packet, int length);
apatel336 0:c0dc3a76f3d4 55
apatel336 0:c0dc3a76f3d4 56 /** Receive a packet from a remote endpoint
apatel336 0:c0dc3a76f3d4 57 \param remote The remote endpoint
apatel336 0:c0dc3a76f3d4 58 \param buffer The buffer for storing the incoming packet data. If a packet
apatel336 0:c0dc3a76f3d4 59 is too long to fit in the supplied buffer, excess bytes are discarded
apatel336 0:c0dc3a76f3d4 60 \param length The length of the buffer
apatel336 0:c0dc3a76f3d4 61 \return the number of received bytes on success (>=0) or -1 on failure
apatel336 0:c0dc3a76f3d4 62 */
apatel336 0:c0dc3a76f3d4 63 int receiveFrom(Endpoint &remote, char *buffer, int length);
apatel336 0:c0dc3a76f3d4 64
apatel336 0:c0dc3a76f3d4 65 private:
apatel336 0:c0dc3a76f3d4 66 bool confEndpoint(Endpoint & ep);
apatel336 0:c0dc3a76f3d4 67 bool readEndpoint(Endpoint & ep);
apatel336 0:c0dc3a76f3d4 68 bool endpoint_configured;
apatel336 0:c0dc3a76f3d4 69 bool endpoint_read;
apatel336 0:c0dc3a76f3d4 70
apatel336 0:c0dc3a76f3d4 71 };
apatel336 0:c0dc3a76f3d4 72
apatel336 0:c0dc3a76f3d4 73 #include "def.h"
apatel336 0:c0dc3a76f3d4 74
apatel336 0:c0dc3a76f3d4 75 #endif