|
23 | 23 | #define ethernet_h_
|
24 | 24 |
|
25 | 25 | #include "Arduino.h"
|
| 26 | +#include "EthernetInterface.h" |
26 | 27 | #include "SocketHelpers.h"
|
27 | 28 | #include "api/IPAddress.h"
|
28 |
| - |
29 | 29 | #include "netsocket/NetworkInterface.h"
|
30 |
| -#include "EthernetInterface.h" |
31 | 30 |
|
32 |
| -enum EthernetLinkStatus { |
33 |
| - Unknown, |
34 |
| - LinkON, |
35 |
| - LinkOFF |
36 |
| -}; |
| 31 | +enum EthernetLinkStatus { Unknown, LinkON, LinkOFF, LinkConnecting, LinkError }; |
37 | 32 |
|
38 |
| -enum EthernetHardwareStatus { |
39 |
| - EthernetNoHardware, |
40 |
| - EthernetMbed = 6 |
41 |
| -}; |
| 33 | +enum EthernetHardwareStatus { EthernetNoHardware, EthernetMbed = 6 }; |
42 | 34 |
|
43 | 35 | namespace arduino {
|
44 | 36 |
|
45 | 37 | enum { // compatibility with Arduino ::maintain()
|
46 |
| - DHCP_CHECK_NONE = 0, |
47 |
| - DHCP_CHECK_RENEW_FAIL = 1, |
48 |
| - DHCP_CHECK_RENEW_OK = 2, |
49 |
| - DHCP_CHECK_REBIND_FAIL = 3, |
50 |
| - DHCP_CHECK_REBIND_OK = 4 |
| 38 | + DHCP_CHECK_NONE = 0, |
| 39 | + DHCP_CHECK_RENEW_FAIL = 1, |
| 40 | + DHCP_CHECK_RENEW_OK = 2, |
| 41 | + DHCP_CHECK_REBIND_FAIL = 3, |
| 42 | + DHCP_CHECK_REBIND_OK = 4 |
51 | 43 | };
|
52 | 44 |
|
53 |
| -typedef void *(*voidPrtFuncPtr)(void); |
54 |
| - |
55 | 45 | class EthernetClass : public MbedSocketClass {
|
| 46 | + public: |
| 47 | + // Initialise the Ethernet shield to use the provided MAC address and |
| 48 | + // gain the rest of the configuration through DHCP. |
| 49 | + // Returns 0 if the DHCP configuration failed, and 1 if it succeeded |
| 50 | + EthernetClass(EthernetInterface *_if) : eth_if(_if){}; |
| 51 | + EthernetClass(){}; |
| 52 | + |
| 53 | + void begin(uint8_t *mac = nullptr); |
| 54 | + EthernetLinkStatus linkStatus(); |
| 55 | + EthernetHardwareStatus hardwareStatus(); |
| 56 | + |
| 57 | + // Manual configuration |
| 58 | + void begin(uint8_t *mac, IPAddress ip); |
| 59 | + void begin(uint8_t *mac, IPAddress ip, IPAddress dns); |
| 60 | + void begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway); |
| 61 | + void begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet); |
| 62 | + |
| 63 | + void begin(IPAddress ip) { begin(nullptr, ip); } |
| 64 | + void begin(IPAddress ip, IPAddress dns) { begin(nullptr, ip, dns); } |
| 65 | + void begin(IPAddress ip, IPAddress dns, IPAddress gateway) { begin(nullptr, ip, dns, gateway); } |
| 66 | + void begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { begin(nullptr, ip, dns, gateway, subnet); } |
| 67 | + |
| 68 | + void MACAddress(uint8_t *mac_address); |
| 69 | + |
| 70 | + int disconnect(void); |
| 71 | + void end(void); |
| 72 | + |
| 73 | + uint8_t status(); |
| 74 | + unsigned long getTime(); |
| 75 | + |
| 76 | + void setDnsServerIP(const IPAddress dns_server) { _dnsServer1 = socketAddressFromIpAddress(dns_server, 0); } |
| 77 | + |
| 78 | + friend class EthernetClient; |
| 79 | + friend class EthernetServer; |
| 80 | + friend class EthernetUDP; |
| 81 | + |
| 82 | + NetworkInterface *getNetwork(); |
| 83 | + |
| 84 | + constexpr static int maintain() { return DHCP_CHECK_NONE; } |
56 | 85 |
|
57 |
| -public: |
58 |
| - // Initialise the Ethernet shield to use the provided MAC address and |
59 |
| - // gain the rest of t
5
he co
10BC0
nfiguration through DHCP. |
60 |
| - // Returns 0 if the DHCP configuration failed, and 1 if it succeeded |
61 |
| - EthernetClass(EthernetInterface *_if) |
62 |
| - : eth_if(_if){}; |
63 |
| - EthernetClass(){}; |
64 |
| - |
65 |
| - EthernetClass(voidPrtFuncPtr _cb) |
66 |
| - : _initializerCallback(_cb){}; |
67 |
| - |
68 |
| - int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); |
69 |
| - EthernetLinkStatus linkStatus(); |
70 |
| - EthernetHardwareStatus hardwareStatus(); |
71 |
| - |
72 |
| - // Manual configuration |
73 |
| - int begin(uint8_t *mac, IPAddress ip); |
74 |
| - int begin(uint8_t *mac, IPAddress ip, IPAddress dns); |
75 |
| - int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway); |
76 |
| - int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); |
77 |
| - |
78 |
| - int begin(IPAddress ip) { |
79 |
| - return begin(nullptr, ip); |
80 |
| - } |
81 |
| - int begin(IPAddress ip, IPAddress dns) { |
82 |
| - return begin(nullptr, ip, dns); |
83 |
| - } |
84 |
| - int begin(IPAddress ip, IPAddress dns, IPAddress gateway) { |
85 |
| - return begin(nullptr, ip, dns, gateway); |
86 |
| - } |
87 |
| - int begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { |
88 |
| - return begin(nullptr, ip, dns, gateway, subnet); |
89 |
| - } |
90 |
| - void init(uint8_t sspin = 10); |
91 |
| - |
92 |
| - void MACAddress(uint8_t *mac_address); |
93 |
| - |
94 |
| - int disconnect(void); |
95 |
| - void end(void); |
96 |
| - |
97 |
| - uint8_t status(); |
98 |
| - unsigned long getTime(); |
99 |
| - |
100 |
| - void setMACAddress(const uint8_t *mac_address); |
101 |
| - void setLocalIP(const IPAddress local_ip); |
102 |
| - void setSubnetMask(const IPAddress subnet); |
103 |
| - void setGatewayIP(const IPAddress gateway); |
104 |
| - void setDnsServerIP(const IPAddress dns_server) { |
105 |
| - _dnsServer1 = socketAddressFromIpAddress(dns_server, 0); |
106 |
| - } |
107 |
| - void setRetransmissionTimeout(uint16_t milliseconds); |
108 |
| - void setRetransmissionCount(uint8_t num); |
109 |
| - |
110 |
| - friend class EthernetClient; |
111 |
| - friend class EthernetServer; |
112 |
| - friend class EthernetUDP; |
113 |
| - |
114 |
| - NetworkInterface *getNetwork(); |
115 |
| - |
116 |
| - constexpr static int maintain () { return DHCP_CHECK_NONE; } |
117 |
| - |
118 |
| -private: |
119 |
| - volatile EthernetLinkStatus _currentNetworkStatus = Unknown; |
120 |
| - EthernetInterface net; |
121 |
| - EthernetInterface *eth_if = &net; |
122 |
| - voidPrtFuncPtr _initializerCallback; |
123 |
| - arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress); |
| 86 | + private: |
| 87 | + volatile EthernetLinkStatus _currentNetworkStatus = Unknown; |
| 88 | + EthernetInterface net; |
| 89 | + EthernetInterface *eth_if = &net; |
124 | 90 | };
|
125 | 91 |
|
126 |
| -} |
| 92 | +} // namespace arduino |
127 | 93 |
|
128 | 94 | extern arduino::EthernetClass Ethernet;
|
129 | 95 |
|
|
0 commit comments