|
22 | 22 | extern "C" {
|
23 | 23 | #include "bsp/include/nm_bsp.h"
|
24 | 24 | #include "socket/include/socket_buffer.h"
|
| 25 | + #include "socket/include/m2m_socket_host_if.h" |
25 | 26 | #include "driver/source/nmasic.h"
|
26 |
| - #include "driver/include/m2m_periph.h" |
| 27 | + #include "driver/include/m2m_periph.h" |
27 | 28 | }
|
28 | 29 |
|
29 | 30 | static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
|
@@ -148,31 +149,23 @@ static void resolve_cb(uint8_t * /* hostName */, uint32_t hostIp)
|
148 | 149 | }
|
149 | 150 |
|
150 | 151 | static void ping_cb(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode) {
|
151 |
| - switch(u8ErrorCode){ |
152 |
| - |
153 |
| - // PING_ERR_SUCCESS |
154 |
| - case 0: { |
155 |
| - // Ensure that reply IP address matches requested IP address |
156 |
| - if (WiFi._resolve == u32IPAddr) |
157 |
| - WiFi._resolve = WL_PING_SUCCESS; |
158 |
| - else |
159 |
| - // Another network device replied to the our ICMP request |
160 |
| - WiFi._resolve = WL_PING_DEST_UNREACHABLE; |
161 |
| - }; break; |
162 |
| - |
163 |
| - // PING_ERR_DEST_UNREACH |
164 |
| - case 1: { |
| 152 | + if (PING_ERR_SUCCESS == u8ErrorCode){ |
| 153 | + // 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) { |
165 | 161 | WiFi._resolve = WL_PING_DEST_UNREACHABLE;
|
166 |
| - }; break; |
167 |
| - |
168 |
| - // PING_ERR_TIMEOUT |
169 |
| - case 2: { |
| 162 | + } |
| 163 | + else if (PING_ERR_TIMEOUT == u8ErrorCode) { |
170 | 164 | WiFi._resolve = WL_PING_TIMEOUT;
|
171 |
| - }; break; |
172 |
| - |
173 |
| - // Unknown error codes |
174 |
| - default: WiFi._resolve = WL_PING_ERROR; |
175 |
| - }; |
| 165 | + } |
| 166 | + else { |
| 167 | + WiFi._resolve = WL_PING_ERROR; |
| 168 | + }; |
176 | 169 | };
|
177 | 170 |
|
178 | 171 | WiFiClass::WiFiClass()
|
@@ -751,19 +744,19 @@ void WiFiClass::refresh(void)
|
751 | 744 | m2m_wifi_handle_events(NULL);
|
752 | 745 | }
|
753 | 746 |
|
754 |
| -wl_ping_result_t WiFiClass::ping(const char* hostname, uint8_t ttl){ |
| 747 | +uint8_t WiFiClass::ping(const char* hostname, uint8_t ttl){ |
755 | 748 | IPAddress ip;
|
756 | 749 | if (hostByName(hostname, ip) > 0)
|
757 | 750 | return ping(ip, ttl);
|
758 | 751 | else
|
759 | 752 | return WL_PING_UNKNOWN_HOST;
|
760 | 753 | };
|
761 | 754 |
|
762 |
| -wl_ping_result_t WiFiClass::ping(const String &hostname, uint8_t ttl){ |
| 755 | +uint8_t WiFiClass::ping(const String &hostname, uint8_t ttl){ |
763 | 756 | return ping(hostname.c_str(), ttl);
|
764 | 757 | };
|
765 | 758 |
|
766 |
| -wl_ping_result_t WiFiClass::ping(IPAddress host, uint8_t ttl) { |
| 759 | +uint8_t WiFiClass::ping(IPAddress host, uint8_t ttl) { |
767 | 760 |
|
768 | 761 | // Network led ON (rev A then rev B).
|
769 | 762 | m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 0);
|
|
0 commit comments