posilani dat

Dependencies:   FatFileSystemCpp mbed PowerControl USBHostLite

Committer:
PavelKumpan
Date:
Tue May 23 18:42:14 2017 +0000
Revision:
26:5674b8978551
Parent:
7:805c16a071d0
Recreated communication protocol.

Who changed what in which revision?

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