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