Skip to content

Commit 932e4ee

Browse files
committed
Make whitespace and code style consistency to #68
1 parent edbbc07 commit 932e4ee

File tree

2 files changed

+66
-63
lines changed

2 files changed

+66
-63
lines changed

examples/WiFiPing/WiFiPing.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,19 @@ void setup() {
5757
}
5858

5959
void loop() {
60-
6160
Serial.print("Pinging ");
6261
Serial.print(hostName);
6362
Serial.print(": ");
64-
63+
6564
pingResult = WiFi.ping(hostName);
66-
65+
6766
if (pingResult == WL_PING_SUCCESS) {
6867
Serial.println("SUCCESS!");
6968
} else {
7069
Serial.print("FAILED! Error code: ");
71-
Serial.println(pingResult);
72-
};
73-
70+
Serial.println(pingResult);
71+
}
72+
7473
delay(3000);
7574
}
7675

src/WiFi.cpp

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424
#include "socket/include/socket_buffer.h"
2525
#include "socket/include/m2m_socket_host_if.h"
2626
#include "driver/source/nmasic.h"
27-
#include "driver/include/m2m_periph.h"
27+
#include "driver/include/m2m_periph.h"
2828
}
2929

3030
static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
@@ -148,25 +148,24 @@ static void resolve_cb(uint8_t * /* hostName */, uint32_t hostIp)
148148
WiFi._resolve = hostIp;
149149
}
150150

151-
static void ping_cb(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode) {
152-
if (PING_ERR_SUCCESS == u8ErrorCode){
151+
static void ping_cb(uint32 u32IPAddr, uint32 /*u32RTT*/, uint8 u8ErrorCode)
152+
{
153+
if (PING_ERR_SUCCESS == u8ErrorCode) {
153154
// Ensure this ICMP reply comes from requested IP address
154-
if (WiFi._resolve == u32IPAddr)
155-
WiFi._resolve = WL_PING_SUCCESS;
156-
else
157-
// Another network device replied to the our ICMP request
158-
WiFi._resolve = WL_PING_DEST_UNREACHABLE;
159-
}
160-
else if (PING_ERR_DEST_UNREACH == u8ErrorCode) {
155+
if (WiFi._resolve == u32IPAddr) {
156+
WiFi._resolve = WL_PING_SUCCESS;
157+
} else {
158+
// Another network device replied to the our ICMP request
161159
WiFi._resolve = WL_PING_DEST_UNREACHABLE;
162-
}
163-
else if (PING_ERR_TIMEOUT == u8ErrorCode) {
164-
WiFi._resolve = WL_PING_TIMEOUT;
165-
}
166-
else {
167-
WiFi._resolve = WL_PING_ERROR;
168-
};
169-
};
160+
}
161+
} else if (PING_ERR_DEST_UNREACH == u8ErrorCode) {
162+
WiFi._resolve = WL_PING_DEST_UNREACHABLE;
163+
} else if (PING_ERR_TIMEOUT == u8ErrorCode) {
164+
WiFi._resolve = WL_PING_TIMEOUT;
165+
} else {
166+
WiFi._resolve = WL_PING_ERROR;
167+
}
168+
}
170169

171170
WiFiClass::WiFiClass()
172171
{
@@ -761,49 +760,54 @@ void WiFiClass::refresh(void)
761760
m2m_wifi_handle_events(NULL);
762761
}
763762

764-
uint8_t WiFiClass::ping(const char* hostname, uint8_t ttl){
763+
uint8_t WiFiClass::ping(const char* hostname, uint8_t ttl)
764+
{
765765
IPAddress ip;
766-
if (hostByName(hostname, ip) > 0)
766+
767+
if (hostByName(hostname, ip) > 0) {
767768
return ping(ip, ttl);
768-
else
769+
} else {
769770
return WL_PING_UNKNOWN_HOST;
770-
};
771+
}
772+
}
771773

772-
uint8_t WiFiClass::ping(const String &hostname, uint8_t ttl){
774+
uint8_t WiFiClass::ping(const String &hostname, uint8_t ttl)
775+
{
773776
return ping(hostname.c_str(), ttl);
774-
};
775-
776-
uint8_t WiFiClass::ping(IPAddress host, uint8_t ttl) {
777-
778-
// Network led ON (rev A then rev B).
779-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 0);
780-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 0);
781-
782-
uint32_t dstHost = (uint32_t)host;
783-
_resolve = dstHost;
784-
785-
if (m2m_ping_req((uint32_t)host, ttl, &ping_cb) < 0) {
786-
// Network led OFF (rev A then rev B).
787-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
788-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
789-
// Error sending ping request
790-
return WL_PING_ERROR;
791-
};
792-
793-
// Wait for connection or timeout:
794-
unsigned long start = millis();
795-
while (_resolve == dstHost && millis() - start < 5000) {
796-
m2m_wifi_handle_events(NULL);
797-
};
798-
799-
// Network led OFF (rev A then rev B).
800-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
801-
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
802-
803-
if (_resolve == dstHost)
804-
return WL_PING_TIMEOUT;
805-
else
806-
return (wl_ping_result_t)_resolve;
807-
};
777+
}
778+
779+
uint8_t WiFiClass::ping(IPAddress host, uint8_t ttl)
780+
{
781+
// Network led ON (rev A then rev B).
782+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 0);
783+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 0);
784+
785+
uint32_t dstHost = (uint32_t)host;
786+
_resolve = dstHost;
787+
788+
if (m2m_ping_req((uint32_t)host, ttl, &ping_cb) < 0) {
789+
// Network led OFF (rev A then rev B).
790+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
791+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
792+
// Error sending ping request
793+
return WL_PING_ERROR;
794+
}
795+
796+
// Wait for success or timeout:
797+
unsigned long start = millis();
798+
while (_resolve == dstHost && millis() - start < 5000) {
799+
m2m_wifi_handle_events(NULL);
800+
}
801+
802+
// Network led OFF (rev A then rev B).
803+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
804+
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
805+
806+
if (_resolve == dstHost) {
807+
return WL_PING_TIMEOUT;
808+
} else {
809+
return _resolve;
810+
}
811+
}
808812

809813
WiFiClass WiFi;

0 commit comments

Comments
 (0)