Fork for fixes
UipEthernet.h@16:269f652b4d0b, 2020-06-05 (annotated)
- Committer:
- hudakz
- Date:
- Fri Jun 05 15:12:21 2020 +0000
- Revision:
- 16:269f652b4d0b
- Parent:
- 15:53715cc81c63
- Child:
- 18:a19f7933d5c7
Library for ENC28J60 Ethernet modules.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 9:a156d3de5647 | 1 | /* |
hudakz | 9:a156d3de5647 | 2 | UipEthernet.h - Arduino implementation of a UIP wrapper class. |
hudakz | 9:a156d3de5647 | 3 | Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> |
hudakz | 9:a156d3de5647 | 4 | All rights reserved. |
hudakz | 9:a156d3de5647 | 5 | |
hudakz | 9:a156d3de5647 | 6 | Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com> |
hudakz | 9:a156d3de5647 | 7 | |
hudakz | 9:a156d3de5647 | 8 | This program is free software: you can redistribute it and/or modify |
hudakz | 9:a156d3de5647 | 9 | it under the terms of the GNU General Public License as published by |
hudakz | 9:a156d3de5647 | 10 | the Free Software Foundation, either version 3 of the License, or |
hudakz | 9:a156d3de5647 | 11 | (at your option) any later version. |
hudakz | 9:a156d3de5647 | 12 | |
hudakz | 9:a156d3de5647 | 13 | This program is distributed in the hope that it will be useful, |
hudakz | 9:a156d3de5647 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hudakz | 9:a156d3de5647 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hudakz | 9:a156d3de5647 | 16 | GNU General Public License for more details. |
hudakz | 9:a156d3de5647 | 17 | |
hudakz | 9:a156d3de5647 | 18 | You should have received a copy of the GNU General Public License |
hudakz | 9:a156d3de5647 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
hudakz | 9:a156d3de5647 | 20 | */ |
hudakz | 11:647d53d146f1 | 21 | #ifndef UIPETHERNET_h |
hudakz | 11:647d53d146f1 | 22 | #define UIPETHERNET_h |
hudakz | 9:a156d3de5647 | 23 | |
hudakz | 9:a156d3de5647 | 24 | //#define UIPETHERNET_DEBUG |
hudakz | 9:a156d3de5647 | 25 | //#define UIPETHERNET_DEBUG_CHKSUM |
hudakz | 9:a156d3de5647 | 26 | //#define UIPETHERNET_DEBUG_UDP |
hudakz | 9:a156d3de5647 | 27 | //#define UIPETHERNET_DEBUG_CLIENT |
hudakz | 9:a156d3de5647 | 28 | #include "mbed.h" |
hudakz | 9:a156d3de5647 | 29 | #include "DhcpClient.h" |
hudakz | 9:a156d3de5647 | 30 | #include "IpAddress.h" |
hudakz | 11:647d53d146f1 | 31 | #include "utility/Enc28j60Eth.h" |
hudakz | 9:a156d3de5647 | 32 | #include "TcpClient.h" |
hudakz | 9:a156d3de5647 | 33 | #include "TcpServer.h" |
hudakz | 9:a156d3de5647 | 34 | #include "UdpSocket.h" |
hudakz | 9:a156d3de5647 | 35 | |
hudakz | 9:a156d3de5647 | 36 | extern "C" |
hudakz | 9:a156d3de5647 | 37 | { |
hudakz | 9:a156d3de5647 | 38 | #include "utility/uip_timer.h" |
hudakz | 9:a156d3de5647 | 39 | #include "utility/uip.h" |
hudakz | 14:7648334eb41b | 40 | #include "utility/util.h" |
hudakz | 9:a156d3de5647 | 41 | } |
hudakz | 9:a156d3de5647 | 42 | |
hudakz | 9:a156d3de5647 | 43 | class UipEthernet |
hudakz | 9:a156d3de5647 | 44 | { |
hudakz | 9:a156d3de5647 | 45 | public: |
hudakz | 9:a156d3de5647 | 46 | static UipEthernet* ethernet; |
hudakz | 9:a156d3de5647 | 47 | static IpAddress dnsServerAddress; |
hudakz | 11:647d53d146f1 | 48 | Enc28j60Eth enc28j60Eth; |
hudakz | 9:a156d3de5647 | 49 | |
hudakz | 9:a156d3de5647 | 50 | UipEthernet (const uint8_t mac[6], PinName mosi, PinName miso, PinName sck, PinName cs); |
hudakz | 9:a156d3de5647 | 51 | |
hudakz | 15:53715cc81c63 | 52 | int connect(unsigned long timeout = 60); |
hudakz | 13:95c00132cd98 | 53 | void disconnect(); |
hudakz | 9:a156d3de5647 | 54 | void set_network(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4); |
hudakz | 9:a156d3de5647 | 55 | void set_network(IpAddress ip); |
hudakz | 9:a156d3de5647 | 56 | void set_network(IpAddress ip, IpAddress dns); |
hudakz | 9:a156d3de5647 | 57 | void set_network(IpAddress ip, IpAddress dns, IpAddress gateway); |
hudakz | 9:a156d3de5647 | 58 | void set_network(IpAddress ip, IpAddress dns, IpAddress gateway, IpAddress subnet); |
hudakz | 11:647d53d146f1 | 59 | void set_network(const char *ip_address, const char *netmask, const char *gateway); |
hudakz | 9:a156d3de5647 | 60 | void tick(); |
hudakz | 9:a156d3de5647 | 61 | IpAddress localIP(); |
hudakz | 9:a156d3de5647 | 62 | IpAddress subnetMask(); |
hudakz | 9:a156d3de5647 | 63 | IpAddress gatewayIP(); |
hudakz | 9:a156d3de5647 | 64 | IpAddress dnsServerIP(); |
hudakz | 9:a156d3de5647 | 65 | const char* get_ip_address(); |
hudakz | 16:269f652b4d0b | 66 | void get_ip_address(SocketAddress* addr); |
hudakz | 9:a156d3de5647 | 67 | const char* get_netmask(); |
hudakz | 16:269f652b4d0b | 68 | void get_netmask(SocketAddress* addr); |
hudakz | 9:a156d3de5647 | 69 | const char* get_gateway(); |
hudakz | 16:269f652b4d0b | 70 | void get_gateway(SocketAddress* addr); |
hudakz | 9:a156d3de5647 | 71 | static uint16_t chksum(uint16_t sum, const uint8_t* data, uint16_t len); |
hudakz | 9:a156d3de5647 | 72 | static uint16_t ipchksum(); |
hudakz | 11:647d53d146f1 | 73 | bool stoip4(const char *ip4addr, size_t len, void *dest); |
hudakz | 9:a156d3de5647 | 74 | private: |
hudakz | 9:a156d3de5647 | 75 | uint8_t *const _mac; |
hudakz | 9:a156d3de5647 | 76 | IpAddress _ip; |
hudakz | 9:a156d3de5647 | 77 | IpAddress _dns; |
hudakz | 9:a156d3de5647 | 78 | IpAddress _gateway; |
hudakz | 9:a156d3de5647 | 79 | IpAddress _subnet; |
hudakz | 9:a156d3de5647 | 80 | static memhandle inPacket; |
hudakz | 9:a156d3de5647 | 81 | static memhandle uipPacket; |
hudakz | 9:a156d3de5647 | 82 | static uint8_t uipHeaderLen; |
hudakz | 9:a156d3de5647 | 83 | static uint8_t packetState; |
hudakz | 9:a156d3de5647 | 84 | DhcpClient dhcpClient; |
hudakz | 9:a156d3de5647 | 85 | Timer periodicTimer; |
hudakz | 9:a156d3de5647 | 86 | void init(const uint8_t* mac); |
hudakz | 9:a156d3de5647 | 87 | bool network_send(); |
hudakz | 9:a156d3de5647 | 88 | friend class TcpServer; |
hudakz | 9:a156d3de5647 | 89 | friend class TcpClient; |
hudakz | 9:a156d3de5647 | 90 | friend class UdpSocket; |
hudakz | 9:a156d3de5647 | 91 | #if UIP_UDP |
hudakz | 9:a156d3de5647 | 92 | uint16_t upper_layer_chksum(uint8_t proto); |
hudakz | 9:a156d3de5647 | 93 | #endif |
hudakz | 9:a156d3de5647 | 94 | friend uint16_t uip_ipchksum(); |
hudakz | 9:a156d3de5647 | 95 | friend uint16_t uip_tcpchksum(); |
hudakz | 9:a156d3de5647 | 96 | friend uint16_t uip_udpchksum(); |
hudakz | 9:a156d3de5647 | 97 | friend void uipclient_appcall(); |
hudakz | 9:a156d3de5647 | 98 | friend void uipudp_appcall(); |
hudakz | 9:a156d3de5647 | 99 | |
hudakz | 9:a156d3de5647 | 100 | #if UIP_CONF_IPV6 |
hudakz | 9:a156d3de5647 | 101 | uint16_t uip_icmp6chksum(); |
hudakz | 9:a156d3de5647 | 102 | #endif |
hudakz | 9:a156d3de5647 | 103 | }; |
hudakz | 11:647d53d146f1 | 104 | |
hudakz | 9:a156d3de5647 | 105 | #endif |