UIPEthernet library for Arduino IDE, Eclipse with arduino plugin and MBED/SMeshStudio (AVR,STM32F,ESP8266,Intel ARC32,Nordic nRF51,Teensy boards,Realtek Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet W5100 Ethernet library API. Compiled and tested on Nucleo-F302R8. Master repository is: https://github.com/UIPEthernet/UIPEthernet/

Committer:
cassyarduino
Date:
Tue Jan 23 15:08:43 2018 +0100
Revision:
39:deeb00b81cc9
Parent:
33:7ba5d53df0f2
Release: 2.0.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cassyarduino 0:e3fb1267e3c3 1 /*
cassyarduino 0:e3fb1267e3c3 2 UIPUdp.h - Arduino implementation of a uIP wrapper class
cassyarduino 0:e3fb1267e3c3 3 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
cassyarduino 0:e3fb1267e3c3 4 All rights reserved.
cassyarduino 4:5c7337d5ba8e 5
cassyarduino 0:e3fb1267e3c3 6 This program is free software: you can redistribute it and/or modify
cassyarduino 0:e3fb1267e3c3 7 it under the terms of the GNU General Public License as published by
cassyarduino 0:e3fb1267e3c3 8 the Free Software Foundation, either version 3 of the License, or
cassyarduino 0:e3fb1267e3c3 9 (at your option) any later version.
cassyarduino 4:5c7337d5ba8e 10
cassyarduino 0:e3fb1267e3c3 11 This program is distributed in the hope that it will be useful,
cassyarduino 0:e3fb1267e3c3 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
cassyarduino 0:e3fb1267e3c3 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cassyarduino 0:e3fb1267e3c3 14 GNU General Public License for more details.
cassyarduino 4:5c7337d5ba8e 15
cassyarduino 0:e3fb1267e3c3 16 You should have received a copy of the GNU General Public License
cassyarduino 0:e3fb1267e3c3 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
cassyarduino 0:e3fb1267e3c3 18 */
cassyarduino 4:5c7337d5ba8e 19
cassyarduino 0:e3fb1267e3c3 20 #ifndef UIPUDP_H
cassyarduino 0:e3fb1267e3c3 21 #define UIPUDP_H
cassyarduino 4:5c7337d5ba8e 22
cassyarduino 0:e3fb1267e3c3 23 #include "ethernet_comp.h"
cassyarduino 0:e3fb1267e3c3 24 #if defined(ARDUINO)
cassyarduino 0:e3fb1267e3c3 25 #include <Arduino.h>
cassyarduino 33:7ba5d53df0f2 26 #if defined(__RFduino__)
cassyarduino 33:7ba5d53df0f2 27 #include "Print.h"
cassyarduino 33:7ba5d53df0f2 28 #else
cassyarduino 33:7ba5d53df0f2 29 #include "Print.h"
cassyarduino 33:7ba5d53df0f2 30 #endif
cassyarduino 33:7ba5d53df0f2 31 #if defined(__STM32F3__) || defined(STM32F3) || defined(__RFduino__)
cassyarduino 19:e416943f7119 32 #include "mbed/Udp.h"
cassyarduino 19:e416943f7119 33 #else
cassyarduino 19:e416943f7119 34 #include <Udp.h>
cassyarduino 19:e416943f7119 35 #endif
cassyarduino 0:e3fb1267e3c3 36 #endif
cassyarduino 8:b9332109461d 37 #if defined(__MBED__)
cassyarduino 8:b9332109461d 38 #include <mbed.h>
cassyarduino 8:b9332109461d 39 #include "mbed/Print.h"
cassyarduino 8:b9332109461d 40 #include "mbed/Udp.h"
cassyarduino 8:b9332109461d 41 #endif
cassyarduino 0:e3fb1267e3c3 42 #include "utility/mempool.h"
cassyarduino 0:e3fb1267e3c3 43 extern "C" {
cassyarduino 0:e3fb1267e3c3 44 #include "utility/uip.h"
cassyarduino 0:e3fb1267e3c3 45 }
cassyarduino 4:5c7337d5ba8e 46
cassyarduino 0:e3fb1267e3c3 47 #define UIP_UDP_MAXDATALEN 1500
cassyarduino 0:e3fb1267e3c3 48 #define UIP_UDP_PHYH_LEN UIP_LLH_LEN+UIP_IPUDPH_LEN
cassyarduino 0:e3fb1267e3c3 49 #define UIP_UDP_MAXPACKETSIZE UIP_UDP_MAXDATALEN+UIP_UDP_PHYH_LEN
cassyarduino 4:5c7337d5ba8e 50
cassyarduino 0:e3fb1267e3c3 51 typedef struct {
cassyarduino 0:e3fb1267e3c3 52 memaddress out_pos;
cassyarduino 0:e3fb1267e3c3 53 memhandle packet_next;
cassyarduino 0:e3fb1267e3c3 54 memhandle packet_in;
cassyarduino 0:e3fb1267e3c3 55 memhandle packet_out;
cassyarduino 0:e3fb1267e3c3 56 bool send;
cassyarduino 0:e3fb1267e3c3 57 } uip_udp_userdata_t;
cassyarduino 4:5c7337d5ba8e 58
cassyarduino 33:7ba5d53df0f2 59 #if defined(ARDUINO) && !defined(STM32F3) && !defined(__RFduino__)
cassyarduino 10:cd62b2205c2a 60 class UIPUDP : public UDP {
cassyarduino 10:cd62b2205c2a 61 #endif
cassyarduino 33:7ba5d53df0f2 62 #if defined(__MBED__) || defined(STM32F3) || defined(__RFduino__)
cassyarduino 10:cd62b2205c2a 63 class UIPUDP : public Print, public UDP {
cassyarduino 10:cd62b2205c2a 64 #endif
cassyarduino 0:e3fb1267e3c3 65 private:
cassyarduino 0:e3fb1267e3c3 66 struct uip_udp_conn *_uip_udp_conn;
cassyarduino 4:5c7337d5ba8e 67
cassyarduino 0:e3fb1267e3c3 68 uip_udp_userdata_t appdata;
cassyarduino 4:5c7337d5ba8e 69
cassyarduino 0:e3fb1267e3c3 70 public:
cassyarduino 4:5c7337d5ba8e 71 UIPUDP(void); // Constructor
cassyarduino 4:5c7337d5ba8e 72 virtual uint8_t begin(uint16_t);// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
cassyarduino 4:5c7337d5ba8e 73 virtual void stop(void); // Finish with the UDP socket
cassyarduino 4:5c7337d5ba8e 74
cassyarduino 0:e3fb1267e3c3 75 // Sending UDP packets
cassyarduino 4:5c7337d5ba8e 76
cassyarduino 0:e3fb1267e3c3 77 // Start building up a packet to send to the remote host specific in ip and port
cassyarduino 0:e3fb1267e3c3 78 // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
cassyarduino 4:5c7337d5ba8e 79 virtual int beginPacket(IPAddress ip, uint16_t port);
cassyarduino 0:e3fb1267e3c3 80 // Start building up a packet to send to the remote host specific in host and port
cassyarduino 0:e3fb1267e3c3 81 // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
cassyarduino 4:5c7337d5ba8e 82 virtual int beginPacket(const char *host, uint16_t port);
cassyarduino 0:e3fb1267e3c3 83 // Finish off this packet and send it
cassyarduino 0:e3fb1267e3c3 84 // Returns 1 if the packet was sent successfully, 0 if there was an error
cassyarduino 4:5c7337d5ba8e 85 virtual int endPacket(void);
cassyarduino 0:e3fb1267e3c3 86 // Write a single byte into the packet
cassyarduino 4:5c7337d5ba8e 87 virtual size_t write(uint8_t);
cassyarduino 0:e3fb1267e3c3 88 // Write size bytes from buffer into the packet
cassyarduino 4:5c7337d5ba8e 89 virtual size_t write(const uint8_t *buffer, size_t size);
cassyarduino 9:312e0937630f 90
cassyarduino 8:b9332109461d 91 using Print::write;
cassyarduino 9:312e0937630f 92
cassyarduino 0:e3fb1267e3c3 93 // Start processing the next available incoming packet
cassyarduino 0:e3fb1267e3c3 94 // Returns the size of the packet in bytes, or 0 if no packets are available
cassyarduino 4:5c7337d5ba8e 95 virtual int parsePacket(void);
cassyarduino 0:e3fb1267e3c3 96 // Number of bytes remaining in the current packet
cassyarduino 4:5c7337d5ba8e 97 virtual int available(void);
cassyarduino 0:e3fb1267e3c3 98 // Read a single byte from the current packet
cassyarduino 4:5c7337d5ba8e 99 virtual int read(void);
cassyarduino 0:e3fb1267e3c3 100 // Read up to len bytes from the current packet and place them into buffer
cassyarduino 0:e3fb1267e3c3 101 // Returns the number of bytes read, or 0 if none are available
cassyarduino 4:5c7337d5ba8e 102 virtual int read(unsigned char* buffer, size_t len);
cassyarduino 0:e3fb1267e3c3 103 // Read up to len characters from the current packet and place them into buffer
cassyarduino 0:e3fb1267e3c3 104 // Returns the number of characters read, or 0 if none are available
cassyarduino 4:5c7337d5ba8e 105 virtual int read(char* buffer, size_t len)
cassyarduino 0:e3fb1267e3c3 106 {
cassyarduino 0:e3fb1267e3c3 107 return read((unsigned char*) buffer, len);
cassyarduino 0:e3fb1267e3c3 108 }
cassyarduino 0:e3fb1267e3c3 109 ;
cassyarduino 0:e3fb1267e3c3 110 // Return the next byte from the current packet without moving on to the next byte
cassyarduino 4:5c7337d5ba8e 111 virtual int peek(void);
cassyarduino 4:5c7337d5ba8e 112 virtual void flush(void); // Finish reading the current packet
cassyarduino 4:5c7337d5ba8e 113
cassyarduino 0:e3fb1267e3c3 114 // Return the IP address of the host who sent the current incoming packet
cassyarduino 4:5c7337d5ba8e 115 virtual IPAddress remoteIP(void);
cassyarduino 4:5c7337d5ba8e 116
cassyarduino 0:e3fb1267e3c3 117 // Return the port of the host who sent the current incoming packet
cassyarduino 4:5c7337d5ba8e 118 virtual uint16_t remotePort(void);
cassyarduino 4:5c7337d5ba8e 119
cassyarduino 0:e3fb1267e3c3 120 private:
cassyarduino 4:5c7337d5ba8e 121
cassyarduino 0:e3fb1267e3c3 122 friend void uipudp_appcall(void);
cassyarduino 4:5c7337d5ba8e 123
cassyarduino 0:e3fb1267e3c3 124 friend class UIPEthernetClass;
cassyarduino 0:e3fb1267e3c3 125 static void _send(uip_udp_userdata_t *data);
cassyarduino 4:5c7337d5ba8e 126
cassyarduino 0:e3fb1267e3c3 127 };
cassyarduino 4:5c7337d5ba8e 128
cassyarduino 0:e3fb1267e3c3 129 #endif