M2X Ethernet demo using Seeed Ethernet W5200 Shield

Dependencies:   LM75B M2XStreamClient jsonlite mbed-rtos mbed Nucleo_Sensor_Shield

Fork of m2x-seeed_ethernet_demo by Sean Newton

Committer:
dangriffin
Date:
Wed Dec 17 20:45:13 2014 +0000
Revision:
11:40d8cfc941ed
Parent:
7:a94ba2e0cd04
Use the public Nucleo Sensor Shield library.

Who changed what in which revision?

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