Skip to content

Commit f82e0bc

Browse files
ethernet lib: cosmetics clang
1 parent 01e36de commit f82e0bc

File tree

2 files changed

+74
-65
lines changed

2 files changed

+74
-65
lines changed

libraries/Ethernet/src/Ethernet.cpp

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,117 +3,118 @@
33
#if DT_HAS_COMPAT_STATUS_OKAY(ethernet_phy)
44

55
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);
88
}
99

1010
int EthernetClass::begin(uint8_t *mac, IPAddress ip) {
11-
IPAddress dns = ip;
12-
dns[3] = 1;
11+
IPAddress dns = ip;
12+
dns[3] = 1;
1313

14-
auto ret = begin(mac, ip, dns);
15-
return ret;
14+
auto ret = begin(mac, ip, dns);
15+
return ret;
1616
}
1717

1818
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;
2121

22-
auto ret = begin(mac, ip, dns, gateway);
23-
return ret;
22+
auto ret = begin(mac, ip, dns, gateway);
23+
return ret;
2424
}
2525

2626
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;
3030
}
3131

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);
3435

35-
if (!NetworkInterface::setLocalIPFull(ip, subnet, gateway)) {
36-
return 0;
37-
}
36+
if (!NetworkInterface::setLocalIPFull(ip, subnet, gateway)) {
37+
return 0;
38+
}
3839

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+
}
4243

43-
return 1;
44+
return 1;
4445
}
4546

4647
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;
5152
}
5253

5354
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+
}
6869

6970
int EthernetClass::disconnect() {
70-
return NetworkInterface::disconnect();
71+
return NetworkInterface::disconnect();
7172
}
7273

7374
void EthernetClass::end() {
74-
disconnect();
75+
disconnect();
7576
}
7677

7778
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+
}
8182
}
8283

8384
void EthernetClass::MACAddress(uint8_t *mac_address) {
84-
setMACAddress(mac_address);
85+
setMACAddress(mac_address);
8586
}
8687

8788
IPAddress EthernetClass::localIP() {
88-
return NetworkInterface::localIP();
89+
return NetworkInterface::localIP();
8990
}
9091

9192
IPAddress EthernetClass::subnetMask() {
92-
return NetworkInterface::subnetMask();
93+
return NetworkInterface::subnetMask();
9394
}
9495

9596
IPAddress EthernetClass::gatewayIP() {
96-
return NetworkInterface::gatewayIP();
97+
return NetworkInterface::gatewayIP();
9798
}
9899

99100
IPAddress EthernetClass::dnsServerIP() {
100-
return NetworkInterface::dnsServerIP();
101+
return NetworkInterface::dnsServerIP();
101102
}
102103

103104
void EthernetClass::setLocalIP(const IPAddress local_ip) {
104-
NetworkInterface::setLocalIP(local_ip);
105+
NetworkInterface::setLocalIP(local_ip);
105106
}
106107

107108
void EthernetClass::setSubnetMask(const IPAddress subnet) {
108-
NetworkInterface::setSubnetMask(subnet);
109+
NetworkInterface::setSubnetMask(subnet);
109110
}
110111

111112
void EthernetClass::setGatewayIP(const IPAddress gateway) {
112-
NetworkInterface::setGatewayIP(gateway);
113+
NetworkInterface::setGatewayIP(gateway);
113114
}
114115

115116
void EthernetClass::setDnsServerIP(const IPAddress dns_server) {
116-
NetworkInterface::setDnsServerIP(dns_server);
117+
NetworkInterface::setDnsServerIP(dns_server);
117118
}
118119

119120
EthernetClass Ethernet;

libraries/Ethernet/src/Ethernet.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55
#if DT_HAS_COMPAT_STATUS_OKAY(ethernet_phy)
66

77
enum EthernetLinkStatus {
8-
Unknown,
9-
LinkON,
10-
LinkOFF
8+
Unknown,
9+
LinkON,
10+
LinkOFF
1111
};
1212

1313
enum EthernetHardwareStatus {
14-
EthernetNoHardware,
15-
EthernetOk
14+
EthernetNoHardware,
15+
EthernetOk
1616
};
1717

18-
class EthernetClass: public NetworkInterface
19-
{
18+
class EthernetClass : public NetworkInterface {
2019
public:
21-
EthernetClass() {}
22-
virtual ~EthernetClass() {}
20+
EthernetClass() {
21+
}
22+
23+
virtual ~EthernetClass() {
24+
}
2325

24-
int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
26+
int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000,
27+
unsigned long responseTimeout = 4000);
2528
int maintain();
2629
EthernetLinkStatus linkStatus();
2730
EthernetHardwareStatus hardwareStatus();
@@ -30,20 +33,25 @@ class EthernetClass: public NetworkInterface
3033
int begin(uint8_t *mac, IPAddress ip);
3134
int begin(uint8_t *mac, IPAddress ip, IPAddress dns);
3235
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway);
33-
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
36+
int begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet,
37+
unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
3438

3539
int begin(IPAddress ip) {
3640
return begin(nullptr, ip);
3741
}
42+
3843
int begin(IPAddress ip, IPAddress dns) {
3944
return begin(nullptr, ip, dns);
4045
}
46+
4147
int begin(IPAddress ip, IPAddress dns, IPAddress gateway) {
4248
return begin(nullptr, ip, dns, gateway);
4349
}
50+
4451
int begin(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {
4552
return begin(nullptr, ip, dns, gateway, subnet);
4653
}
54+
4755
void init(uint8_t sspin = 10);
4856

4957
int disconnect(void);

0 commit comments

Comments
 (0)