mbed OS5

Fork of UIPEthernet by Zoltan Hudak

Committer:
hudakz
Date:
Fri Jun 30 19:51:28 2017 +0000
Revision:
8:4acb22344932
Parent:
4:d774541a34da
'UIPEthernet' renamed to 'uIPEthernet'; 'UIPEthernetClass' renamed to 'UIPEthernet'; added IPAddress::toString() to support printing; added print support for debugging; bugs preventing offline build with GCC ARM toolchain fixed.

Who changed what in which revision?

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