@@ -24,7 +24,7 @@ extern "C" {
24
24
#include " socket/include/socket_buffer.h"
25
25
#include " socket/include/m2m_socket_host_if.h"
26
26
#include " driver/source/nmasic.h"
27
- #include " driver/include/m2m_periph.h"
27
+ #include " driver/include/m2m_periph.h"
28
28
}
29
29
30
30
static void wifi_cb (uint8_t u8MsgType, void *pvMsg)
@@ -148,25 +148,24 @@ static void resolve_cb(uint8_t * /* hostName */, uint32_t hostIp)
148
148
WiFi._resolve = hostIp;
149
149
}
150
150
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) {
153
154
// 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
161
159
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
+ }
170
169
171
170
WiFiClass::WiFiClass ()
172
171
{
@@ -761,49 +760,54 @@ void WiFiClass::refresh(void)
761
760
m2m_wifi_handle_events (NULL );
762
761
}
763
762
764
- uint8_t WiFiClass::ping (const char * hostname, uint8_t ttl){
763
+ uint8_t WiFiClass::ping (const char * hostname, uint8_t ttl)
764
+ {
765
765
IPAddress ip;
766
- if (hostByName (hostname, ip) > 0 )
766
+
767
+ if (hostByName (hostname, ip) > 0 ) {
767
768
return ping (ip, ttl);
768
- else
769
+ } else {
769
770
return WL_PING_UNKNOWN_HOST;
770
- };
771
+ }
772
+ }
771
773
772
- uint8_t WiFiClass::ping (const String &hostname, uint8_t ttl){
774
+ uint8_t WiFiClass::ping (const String &hostname, uint8_t ttl)
775
+ {
773
776
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
+ }
808
812
809
813
WiFiClass WiFi;
0 commit comments