mbed OS5
Fork of UIPEthernet by
UIPClient.h@2:049ce85163c5, 2014-12-20 (annotated)
- Committer:
- hudakz
- Date:
- Sat Dec 20 11:08:11 2014 +0000
- Revision:
- 2:049ce85163c5
- Parent:
- 0:5350a66d5279
- Child:
- 4:d774541a34da
02 Name clash with "Ethernet" fixed for LPC1768
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:5350a66d5279 | 1 | /* |
hudakz | 0:5350a66d5279 | 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 | 0:5350a66d5279 | 20 | #define UIPCLIENT_H |
hudakz | 0:5350a66d5279 | 21 | |
hudakz | 0:5350a66d5279 | 22 | #include "ethernet_comp.h" |
hudakz | 0:5350a66d5279 | 23 | #include "Client.h" |
hudakz | 2:049ce85163c5 | 24 | #include "utility/mempool.h" |
hudakz | 0:5350a66d5279 | 25 | |
hudakz | 0:5350a66d5279 | 26 | extern "C" |
hudakz | 0:5350a66d5279 | 27 | { |
hudakz | 2:049ce85163c5 | 28 | #include "utility/uip.h" |
hudakz | 0:5350a66d5279 | 29 | } |
hudakz | 0:5350a66d5279 | 30 | #define UIP_SOCKET_DATALEN UIP_TCP_MSS |
hudakz | 0:5350a66d5279 | 31 | //#define UIP_SOCKET_NUMPACKETS UIP_RECEIVE_WINDOW/UIP_TCP_MSS+1 |
hudakz | 0:5350a66d5279 | 32 | |
hudakz | 0:5350a66d5279 | 33 | #ifndef UIP_SOCKET_NUMPACKETS |
hudakz | 0:5350a66d5279 | 34 | #define UIP_SOCKET_NUMPACKETS 5 |
hudakz | 0:5350a66d5279 | 35 | #endif |
hudakz | 0:5350a66d5279 | 36 | #define UIP_CLIENT_CLOSE 1 |
hudakz | 0:5350a66d5279 | 37 | #define UIP_CLIENT_CLOSED 2 |
hudakz | 0:5350a66d5279 | 38 | #define UIP_CLIENT_RESTART 4 |
hudakz | 0:5350a66d5279 | 39 | |
hudakz | 0:5350a66d5279 | 40 | typedef uint8_t uip_socket_ptr; |
hudakz | 0:5350a66d5279 | 41 | |
hudakz | 0:5350a66d5279 | 42 | typedef struct |
hudakz | 0:5350a66d5279 | 43 | { |
hudakz | 0:5350a66d5279 | 44 | uint8_t state; |
hudakz | 0:5350a66d5279 | 45 | memhandle packets_in[UIP_SOCKET_NUMPACKETS]; |
hudakz | 0:5350a66d5279 | 46 | uint16_t lport; /**< The local TCP port, in network byte order. */ |
hudakz | 0:5350a66d5279 | 47 | } uip_userdata_closed_t; |
hudakz | 0:5350a66d5279 | 48 | |
hudakz | 0:5350a66d5279 | 49 | typedef struct |
hudakz | 0:5350a66d5279 | 50 | { |
hudakz | 0:5350a66d5279 | 51 | uint8_t state; |
hudakz | 0:5350a66d5279 | 52 | memhandle packets_in[UIP_SOCKET_NUMPACKETS]; |
hudakz | 0:5350a66d5279 | 53 | memhandle packets_out[UIP_SOCKET_NUMPACKETS]; |
hudakz | 0:5350a66d5279 | 54 | memaddress out_pos; |
hudakz | 0:5350a66d5279 | 55 | } uip_userdata_t; |
hudakz | 0:5350a66d5279 | 56 | |
hudakz | 0:5350a66d5279 | 57 | class UIPClient : |
hudakz | 0:5350a66d5279 | 58 | public Client |
hudakz | 0:5350a66d5279 | 59 | { |
hudakz | 0:5350a66d5279 | 60 | public: |
hudakz | 0:5350a66d5279 | 61 | UIPClient(void); |
hudakz | 0:5350a66d5279 | 62 | int connect(IPAddress ip, uint16_t port); |
hudakz | 0:5350a66d5279 | 63 | int connect(const char* host, uint16_t port); |
hudakz | 0:5350a66d5279 | 64 | int read(uint8_t* buf, size_t size); |
hudakz | 0:5350a66d5279 | 65 | void stop(void); |
hudakz | 0:5350a66d5279 | 66 | uint8_t connected(void); |
hudakz | 0:5350a66d5279 | 67 | operator bool(void); |
hudakz | 0:5350a66d5279 | 68 | virtual bool operator ==(const EthernetClient& ); |
hudakz | 0:5350a66d5279 | 69 | virtual bool operator !=(const EthernetClient& rhs) { return !this->operator ==(rhs); }; |
hudakz | 0:5350a66d5279 | 70 | |
hudakz | 0:5350a66d5279 | 71 | size_t write(uint8_t); |
hudakz | 0:5350a66d5279 | 72 | size_t write(const uint8_t* buf, size_t size); |
hudakz | 0:5350a66d5279 | 73 | int available(void); |
hudakz | 0:5350a66d5279 | 74 | int read(void); |
hudakz | 0:5350a66d5279 | 75 | int peek(void); |
hudakz | 0:5350a66d5279 | 76 | void flush(void); |
hudakz | 0:5350a66d5279 | 77 | private: |
hudakz | 0:5350a66d5279 | 78 | UIPClient(struct uip_conn* _conn); |
hudakz | 0:5350a66d5279 | 79 | UIPClient(uip_userdata_closed_t* closed_conn); |
hudakz | 0:5350a66d5279 | 80 | |
hudakz | 0:5350a66d5279 | 81 | struct uip_conn* _uip_conn; |
hudakz | 0:5350a66d5279 | 82 | |
hudakz | 0:5350a66d5279 | 83 | uip_userdata_t* data; |
hudakz | 0:5350a66d5279 | 84 | |
hudakz | 0:5350a66d5279 | 85 | static uip_userdata_closed_t* closed_conns[UIP_CONNS]; |
hudakz | 0:5350a66d5279 | 86 | |
hudakz | 0:5350a66d5279 | 87 | static size_t _write(struct uip_conn* , const uint8_t* buf, size_t size); |
hudakz | 0:5350a66d5279 | 88 | static int _available(uip_userdata_t* ); |
hudakz | 0:5350a66d5279 | 89 | |
hudakz | 0:5350a66d5279 | 90 | static memhandle* _currentBlock(memhandle* blocks); |
hudakz | 0:5350a66d5279 | 91 | static void _eatBlock(memhandle* blocks); |
hudakz | 0:5350a66d5279 | 92 | static void _flushBlocks(memhandle* blocks); |
hudakz | 0:5350a66d5279 | 93 | |
hudakz | 0:5350a66d5279 | 94 | friend class UIPEthernetClass; |
hudakz | 0:5350a66d5279 | 95 | friend class UIPServer; |
hudakz | 0:5350a66d5279 | 96 | static void uip_callback(uip_tcp_appstate_t* s); |
hudakz | 0:5350a66d5279 | 97 | }; |
hudakz | 0:5350a66d5279 | 98 | #endif |