mbed OS5
Fork of UIPEthernet by
Embed:
(wiki syntax)
Show/hide line numbers
UIPClient.h
00001 /* 00002 UIPClient.h - Arduino implementation of a UIP wrapper class. 00003 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> 00004 All rights reserved. 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 #ifndef UIPCLIENT_H 00020 #define UIPCLIENT_H 00021 00022 #include "ethernet_comp.h" 00023 //#include "Print.h" 00024 00025 #include "Client.h" 00026 #include "utility/mempool.h" 00027 00028 extern "C" 00029 { 00030 #include "utility/uip.h" 00031 } 00032 #define UIP_SOCKET_DATALEN UIP_TCP_MSS 00033 //#define UIP_SOCKET_NUMPACKETS UIP_RECEIVE_WINDOW/UIP_TCP_MSS+1 00034 00035 #ifndef UIP_SOCKET_NUMPACKETS 00036 #define UIP_SOCKET_NUMPACKETS 5 00037 #endif 00038 #define UIP_CLIENT_CONNECTED 0x10 00039 #define UIP_CLIENT_CLOSE 0x20 00040 #define UIP_CLIENT_REMOTECLOSED 0x40 00041 #define UIP_CLIENT_RESTART 0x80 00042 #define UIP_CLIENT_STATEFLAGS (UIP_CLIENT_CONNECTED | UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED | UIP_CLIENT_RESTART) 00043 #define UIP_CLIENT_SOCKETS ~UIP_CLIENT_STATEFLAGS 00044 00045 typedef uint8_t uip_socket_ptr; 00046 00047 typedef struct 00048 { 00049 uint8_t state; 00050 memhandle packets_in[UIP_SOCKET_NUMPACKETS]; 00051 uint16_t lport; /**< The local TCP port, in network byte order. */ 00052 } uip_userdata_closed_t; 00053 00054 typedef struct 00055 { 00056 uint8_t state; 00057 memhandle packets_in[UIP_SOCKET_NUMPACKETS]; 00058 memhandle packets_out[UIP_SOCKET_NUMPACKETS]; 00059 memaddress out_pos; 00060 #if UIP_CLIENT_TIMER >= 0 00061 unsigned long timer; 00062 #endif 00063 } uip_userdata_t; 00064 00065 class UIPClient : 00066 public Client 00067 { 00068 public: 00069 UIPClient(void); 00070 int connect(IPAddress ip, uint16_t port); 00071 int connect(const char* host, uint16_t port); 00072 int read(uint8_t* buf, size_t size); 00073 void stop(void); 00074 uint8_t connected(void); 00075 operator bool(void); 00076 virtual bool operator ==(const EthernetClient& ); 00077 virtual bool operator !=(const EthernetClient& rhs) { return !this->operator ==(rhs); }; 00078 00079 size_t write(uint8_t); 00080 size_t write(const uint8_t* buf, size_t size); 00081 int available(void); 00082 int read(void); 00083 int peek(void); 00084 void flush(void); 00085 00086 // using Print::write; 00087 00088 private: 00089 UIPClient(struct uip_conn* _conn); 00090 UIPClient(uip_userdata_t* conn_data); 00091 00092 uip_userdata_t* data; 00093 00094 static uip_userdata_t all_data[UIP_CONNS]; 00095 static uip_userdata_t* _allocateData(void); 00096 00097 static size_t _write(uip_userdata_t* , const uint8_t* buf, size_t size); 00098 static int _available(uip_userdata_t* ); 00099 00100 static uint8_t _currentBlock(memhandle* blocks); 00101 static void _eatBlock(memhandle* blocks); 00102 static void _flushBlocks(memhandle* blocks); 00103 00104 #ifdef UIPETHERNET_DEBUG_CLIENT 00105 static void _dumpAllData(void); 00106 #endif 00107 friend class UIPEthernet; 00108 friend class UIPServer; 00109 00110 friend void uipclient_appcall(void); 00111 }; 00112 #endif 00113
Generated on Tue Jul 12 2022 18:10:58 by 1.7.2