KL25 driver for Tango Control System

Dependencies:   mbed

Committer:
jskl
Date:
Thu Aug 28 07:50:06 2014 +0000
Revision:
2:9fe6f1e273b4
Parent:
0:5d27c333afa6
Fixed bugs in JSON format replies

Who changed what in which revision?

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