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 UIPClient.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 0:5350a66d5279 6 This program is free software: you can redistribute it and/or modify
hudakz 0:5350a66d5279 7 it under the terms of the GNU General Public License as published by
hudakz 0:5350a66d5279 8 the Free Software Foundation, either version 3 of the License, or
hudakz 0:5350a66d5279 9 (at your option) any later version.
hudakz 0:5350a66d5279 10
hudakz 0:5350a66d5279 11 This program is distributed in the hope that it will be useful,
hudakz 0:5350a66d5279 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 0:5350a66d5279 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 0:5350a66d5279 14 GNU General Public License for more details.
hudakz 0:5350a66d5279 15
hudakz 0:5350a66d5279 16 You should have received a copy of the GNU General Public License
hudakz 0:5350a66d5279 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
hudakz 0:5350a66d5279 18 */
hudakz 0:5350a66d5279 19 #ifndef UIPCLIENT_H
hudakz 4:d774541a34da 20 #define UIPCLIENT_H
hudakz 0:5350a66d5279 21
hudakz 4:d774541a34da 22 #include "ethernet_comp.h"
hudakz 4:d774541a34da 23 //#include "Print.h"
hudakz 8:4acb22344932 24
hudakz 4:d774541a34da 25 #include "Client.h"
hudakz 4:d774541a34da 26 #include "utility/mempool.h"
hudakz 4:d774541a34da 27
hudakz 8:4acb22344932 28 extern "C"
hudakz 8:4acb22344932 29 {
hudakz 8:4acb22344932 30 #include "utility/uip.h"
hudakz 4:d774541a34da 31 }
hudakz 8:4acb22344932 32 #define UIP_SOCKET_DATALEN UIP_TCP_MSS
hudakz 8:4acb22344932 33 //#define UIP_SOCKET_NUMPACKETS UIP_RECEIVE_WINDOW/UIP_TCP_MSS+1
hudakz 0:5350a66d5279 34
hudakz 4:d774541a34da 35 #ifndef UIP_SOCKET_NUMPACKETS
hudakz 8:4acb22344932 36 #define UIP_SOCKET_NUMPACKETS 5
hudakz 4:d774541a34da 37 #endif
hudakz 8:4acb22344932 38 #define UIP_CLIENT_CONNECTED 0x10
hudakz 8:4acb22344932 39 #define UIP_CLIENT_CLOSE 0x20
hudakz 4:d774541a34da 40 #define UIP_CLIENT_REMOTECLOSED 0x40
hudakz 8:4acb22344932 41 #define UIP_CLIENT_RESTART 0x80
hudakz 8:4acb22344932 42 #define UIP_CLIENT_STATEFLAGS (UIP_CLIENT_CONNECTED | UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED | UIP_CLIENT_RESTART)
hudakz 8:4acb22344932 43 #define UIP_CLIENT_SOCKETS ~UIP_CLIENT_STATEFLAGS
hudakz 0:5350a66d5279 44
hudakz 0:5350a66d5279 45 typedef uint8_t uip_socket_ptr;
hudakz 0:5350a66d5279 46
hudakz 8:4acb22344932 47 typedef struct
hudakz 8:4acb22344932 48 {
hudakz 8:4acb22344932 49 uint8_t state;
hudakz 8:4acb22344932 50 memhandle packets_in[UIP_SOCKET_NUMPACKETS];
hudakz 8:4acb22344932 51 uint16_t lport; /**< The local TCP port, in network byte order. */
hudakz 0:5350a66d5279 52 } uip_userdata_closed_t;
hudakz 0:5350a66d5279 53
hudakz 8:4acb22344932 54 typedef struct
hudakz 8:4acb22344932 55 {
hudakz 8:4acb22344932 56 uint8_t state;
hudakz 8:4acb22344932 57 memhandle packets_in[UIP_SOCKET_NUMPACKETS];
hudakz 8:4acb22344932 58 memhandle packets_out[UIP_SOCKET_NUMPACKETS];
hudakz 8:4acb22344932 59 memaddress out_pos;
hudakz 4:d774541a34da 60 #if UIP_CLIENT_TIMER >= 0
hudakz 8:4acb22344932 61 unsigned long timer;
hudakz 4:d774541a34da 62 #endif
hudakz 0:5350a66d5279 63 } uip_userdata_t;
hudakz 0:5350a66d5279 64
hudakz 8:4acb22344932 65 class UIPClient :
hudakz 8:4acb22344932 66 public Client
hudakz 8:4acb22344932 67 {
hudakz 0:5350a66d5279 68 public:
hudakz 8:4acb22344932 69 UIPClient(void);
hudakz 8:4acb22344932 70 int connect(IPAddress ip, uint16_t port);
hudakz 8:4acb22344932 71 int connect(const char* host, uint16_t port);
hudakz 8:4acb22344932 72 int read(uint8_t* buf, size_t size);
hudakz 8:4acb22344932 73 void stop(void);
hudakz 8:4acb22344932 74 uint8_t connected(void);
hudakz 8:4acb22344932 75 operator bool(void);
hudakz 8:4acb22344932 76 virtual bool operator ==(const EthernetClient& );
hudakz 8:4acb22344932 77 virtual bool operator !=(const EthernetClient& rhs) { return !this->operator ==(rhs); };
hudakz 0:5350a66d5279 78
hudakz 8:4acb22344932 79 size_t write(uint8_t);
hudakz 8:4acb22344932 80 size_t write(const uint8_t* buf, size_t size);
hudakz 8:4acb22344932 81 int available(void);
hudakz 8:4acb22344932 82 int read(void);
hudakz 8:4acb22344932 83 int peek(void);
hudakz 8:4acb22344932 84 void flush(void);
hudakz 4:d774541a34da 85
hudakz 4:d774541a34da 86 // using Print::write;
hudakz 4:d774541a34da 87
hudakz 0:5350a66d5279 88 private:
hudakz 8:4acb22344932 89 UIPClient(struct uip_conn* _conn);
hudakz 8:4acb22344932 90 UIPClient(uip_userdata_t* conn_data);
hudakz 4:d774541a34da 91
hudakz 8:4acb22344932 92 uip_userdata_t* data;
hudakz 0:5350a66d5279 93
hudakz 8:4acb22344932 94 static uip_userdata_t all_data[UIP_CONNS];
hudakz 8:4acb22344932 95 static uip_userdata_t* _allocateData(void);
hudakz 0:5350a66d5279 96
hudakz 8:4acb22344932 97 static size_t _write(uip_userdata_t* , const uint8_t* buf, size_t size);
hudakz 8:4acb22344932 98 static int _available(uip_userdata_t* );
hudakz 0:5350a66d5279 99
hudakz 8:4acb22344932 100 static uint8_t _currentBlock(memhandle* blocks);
hudakz 8:4acb22344932 101 static void _eatBlock(memhandle* blocks);
hudakz 8:4acb22344932 102 static void _flushBlocks(memhandle* blocks);
hudakz 4:d774541a34da 103
hudakz 4:d774541a34da 104 #ifdef UIPETHERNET_DEBUG_CLIENT
hudakz 8:4acb22344932 105 static void _dumpAllData(void);
hudakz 4:d774541a34da 106 #endif
hudakz 8:4acb22344932 107 friend class UIPEthernet;
hudakz 8:4acb22344932 108 friend class UIPServer;
hudakz 0:5350a66d5279 109
hudakz 8:4acb22344932 110 friend void uipclient_appcall(void);
hudakz 0:5350a66d5279 111 };
hudakz 0:5350a66d5279 112 #endif
hudakz 8:4acb22344932 113