|
3 | 3 | #if DT_HAS_COMPAT_STATUS_OKAY(ethernet_phy) |
4 | 4 |
|
5 | 5 | int EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { |
6 | | - setMACAddress(mac); |
7 | | - return NetworkInterface::begin(true, 0); |
| 6 | + setMACAddress(mac); |
| 7 | + return NetworkInterface::begin(true, 0); |
8 | 8 | } |
9 | 9 |
|
10 | 10 | int EthernetClass::begin(uint8_t *mac, IPAddress ip) { |
11 | | - IPAddress dns = ip; |
12 | | - dns[3] = 1; |
| 11 | + IPAddress dns = ip; |
| 12 | + dns[3] = 1; |
13 | 13 |
|
14 | | - auto ret = begin(mac, ip, dns); |
15 | | - return ret; |
| 14 | + auto ret = begin(mac, ip, dns); |
| 15 | + return ret; |
16 | 16 | } |
17 | 17 |
|
18 | 18 | int EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns) { |
19 | | - IPAddress gateway = ip; |
20 | | - gateway[3] = 1; |
| 19 | + IPAddress gateway = ip; |
| 20 | + gateway[3] = 1; |
21 | 21 |
|
22 | | - auto ret = begin(mac, ip, dns, gateway); |
23 | | - return ret; |
| 22 | + auto ret = begin(mac, ip, dns, gateway); |
| 23 | + return ret; |
24 | 24 | } |
25 | 25 |
|
26 | 26 | int EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway) { |
27 | | - IPAddress subnet(255, 255, 255, 0); |
28 | | - auto ret = begin(mac, ip, dns, gateway, subnet); |
29 | | - return ret; |
| 27 | + IPAddress subnet(255, 255, 255, 0); |
| 28 | + auto ret = begin(mac, ip, dns, gateway, subnet); |
| 29 | + return ret; |
30 | 30 | } |
31 | 31 |
|
32 | | -int EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { |
33 | | - setMACAddress(mac); |
| 32 | +int EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, |
| 33 | + IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { |
| 34 | + setMACAddress(mac); |
34 | 35 |
|
35 | | - if (!NetworkInterface::setLocalIPFull(ip, subnet, gateway)) { |
36 | | - return 0; |
37 | | - } |
| 36 | + if (!NetworkInterface::setLocalIPFull(ip, subnet, gateway)) { |
| 37 | + return 0; |
| 38 | + } |
38 | 39 |
|
39 | | - if (!net_if_is_up(netif)) { |
40 | | - net_if_up(netif); |
41 | | - } |
| 40 | + if (!net_if_is_up(netif)) { |
| 41 | + net_if_up(netif); |
| 42 | + } |
42 | 43 |
|
43 | | - return 1; |
| 44 | + return 1; |
44 | 45 | } |
45 | 46 |
|
46 | 47 | EthernetLinkStatus EthernetClass::linkStatus() { |
47 | | - if ((hardwareStatus() == EthernetOk) && net_if_is_up(netif)) { |
48 | | - return LinkON; |
49 | | - } |
50 | | - return LinkOFF; |
| 48 | + if ((hardwareStatus() == EthernetOk) && net_if_is_up(netif)) { |
| 49 | + return LinkON; |
| 50 | + } |
| 51 | + return LinkOFF; |
51 | 52 | } |
52 | 53 |
|
53 | 54 | EthernetHardwareStatus EthernetClass::hardwareStatus() { |
54 | | - const struct device *const dev = DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ethernet_phy)); |
55 | | - if (device_is_ready(dev)) { |
56 | | - for (int i = 1; i < 3; i++) { |
57 | | - auto _if = net_if_get_by_index(i); |
58 | | - if (!net_eth_type_is_wifi(_if)) { |
59 | | - netif = _if; |
60 | | - break; |
61 | | - } |
62 | | - } |
63 | | - return EthernetOk; |
64 | | - } else { |
65 | | - return EthernetNoHardware; |
66 | | - } |
67 | | -} |
| 55 | + const struct device *const dev = DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ethernet_phy)); |
| 56 | + if (device_is_ready(dev)) { |
| 57 | + for (int i = 1; i < 3; i++) { |
| 58 | + auto _if = net_if_get_by_index(i); |
| 59 | + if (!net_eth_type_is_wifi(_if)) { |
| 60 | + netif = _if; |
| 61 | + break; |
| 62 | + } |
| 63 | + } |
| 64 | + return EthernetOk; |
| 65 | + } else { |
| 66 | + return EthernetNoHardware; |
| 67 | + } |
| 68 | +} |
68 | 69 |
|
69 | 70 | int EthernetClass::disconnect() { |
70 | | - return NetworkInterface::disconnect(); |
| 71 | + return NetworkInterface::disconnect(); |
71 | 72 | } |
72 | 73 |
|
73 | 74 | void EthernetClass::end() { |
74 | | - disconnect(); |
| 75 | + disconnect(); |
75 | 76 | } |
76 | 77 |
|
77 | 78 | void EthernetClass::setMACAddress(const uint8_t *mac_address) { |
78 | | - if (mac_address != nullptr) { |
79 | | - NetworkInterface::setMACAddress(mac_address); |
80 | | - } |
| 79 | + if (mac_address != nullptr) { |
| 80 | + NetworkInterface::setMACAddress(mac_address); |
| 81 | + } |
81 | 82 | } |
82 | 83 |
|
83 | 84 | void EthernetClass::MACAddress(uint8_t *mac_address) { |
84 | | - setMACAddress(mac_address); |
| 85 | + setMACAddress(mac_address); |
85 | 86 | } |
86 | 87 |
|
87 | 88 | IPAddress EthernetClass::localIP() { |
88 | | - return NetworkInterface::localIP(); |
| 89 | + return NetworkInterface::localIP(); |
89 | 90 | } |
90 | 91 |
|
91 | 92 | IPAddress EthernetClass::subnetMask() { |
92 | | - return NetworkInterface::subnetMask(); |
| 93 | + return NetworkInterface::subnetMask(); |
93 | 94 | } |
94 | 95 |
|
95 | 96 | IPAddress EthernetClass::gatewayIP() { |
96 | | - return NetworkInterface::gatewayIP(); |
| 97 | + return NetworkInterface::gatewayIP(); |
97 | 98 | } |
98 | 99 |
|
99 | 100 | IPAddress EthernetClass::dnsServerIP() { |
100 | | - return NetworkInterface::dnsServerIP(); |
| 101 | + return NetworkInterface::dnsServerIP(); |
101 | 102 | } |
102 | 103 |
|
103 | 104 | void EthernetClass::setLocalIP(const IPAddress local_ip) { |
104 | | - NetworkInterface::setLocalIP(local_ip); |
| 105 | + NetworkInterface::setLocalIP(local_ip); |
105 | 106 | } |
106 | 107 |
|
107 | 108 | void EthernetClass::setSubnetMask(const IPAddress subnet) { |
108 | | - NetworkInterface::setSubnetMask(subnet); |
| 109 | + NetworkInterface::setSubnetMask(subnet); |
109 | 110 | } |
110 | 111 |
|
111 | 112 | void EthernetClass::setGatewayIP(const IPAddress gateway) { |
112 | | - NetworkInterface::setGatewayIP(gateway); |
| 113 | + NetworkInterface::setGatewayIP(gateway); |
113 | 114 | } |
114 | 115 |
|
115 | 116 | void EthernetClass::setDnsServerIP(const IPAddress dns_server) { |
116 | | - NetworkInterface::setDnsServerIP(dns_server); |
| 117 | + NetworkInterface::setDnsServerIP(dns_server); |
117 | 118 | } |
118 | 119 |
|
119 | 120 | EthernetClass Ethernet; |
|
0 commit comments