Skip to content

Commit 3860991

Browse files
committed
Ping work and start to add socketpool
1 parent c53a72d commit 3860991

File tree

11 files changed

+680
-11
lines changed

11 files changed

+680
-11
lines changed

ports/esp32s2/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ INC += -Iesp-idf/components/esp_rom/include
8585
INC += -Iesp-idf/components/esp_wifi/include
8686
INC += -Iesp-idf/components/xtensa/include
8787
INC += -Iesp-idf/components/esp_timer/include
88+
INC += -Iesp-idf/components/newlib/platform_include
89+
INC += -Iesp-idf/components/lwip/lwip/src/include
90+
INC += -Iesp-idf/components/lwip/port/esp32/include
91+
INC += -Iesp-idf/components/lwip/include/apps/sntp
8892
INC += -Iesp-idf/components/soc/include
8993
INC += -Iesp-idf/components/soc/src/esp32s2/include
9094
INC += -Iesp-idf/components/soc/soc/include

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
#include "py/runtime.h"
3333
#include "shared-bindings/ipaddress/IPv4Address.h"
3434
#include "shared-bindings/wifi/ScannedNetworks.h"
35+
#include "shared-module/ipaddress/__init__.h"
3536

3637
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
38+
#include "esp-idf/components/lwip/include/apps/ping/ping_sock.h"
3739

3840
#include "esp_log.h"
3941
static const char *TAG = "cp radio";
@@ -154,6 +156,29 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
154156
return common_hal_ipaddress_new_ipv4address(ip_info.ip.addr);
155157
}
156158

157-
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address) {
158-
return 0;
159+
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) {
160+
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
161+
ipaddress_ipaddress_to_esp_idf(ip_address, &ping_config.target_addr);
162+
ping_config.count = 1;
163+
164+
size_t timeout_ms = timeout * 1000;
165+
166+
esp_ping_handle_t ping;
167+
esp_ping_new_session(&ping_config, NULL, &ping);
168+
esp_ping_start(ping);
169+
170+
uint32_t received = 0;
171+
uint32_t total_time_ms = 0;
172+
while (received == 0 && total_time_ms < timeout_ms) {
173+
RUN_BACKGROUND_TASKS;
174+
esp_ping_get_profile(ping, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
175+
esp_ping_get_profile(ping, ESP_PING_PROF_REPLY, &received, sizeof(received));
176+
}
177+
uint32_t elapsed_time = 0xffffffff;
178+
if (received > 0) {
179+
esp_ping_get_profile(ping, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
180+
}
181+
esp_ping_delete_session(ping);
182+
183+
return elapsed_time;
159184
}

py/circuitpy_defns.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ endif
228228
ifeq ($(CIRCUITPY_SHARPDISPLAY),1)
229229
SRC_PATTERNS += sharpdisplay/%
230230
endif
231+
ifeq ($(CIRCUITPY_SOCKETPOOL),1)
232+
SRC_PATTERNS += socketpool/%
233+
endif
231234
ifeq ($(CIRCUITPY_STAGE),1)
232235
SRC_PATTERNS += _stage/%
233236
endif

py/circuitpy_mpconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,21 @@ extern const struct _mp_obj_module_t sdioio_module;
573573
#define SDIOIO_MODULE
574574
#endif
575575

576+
576577
#if CIRCUITPY_SHARPDISPLAY
577578
extern const struct _mp_obj_module_t sharpdisplay_module;
578579
#define SHARPDISPLAY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sharpdisplay),(mp_obj_t)&sharpdisplay_module },
579580
#else
580581
#define SHARPDISPLAY_MODULE
581582
#endif
582583

584+
#if CIRCUITPY_SOCKETPOOL
585+
extern const struct _mp_obj_module_t socketpool_module;
586+
#define SOCKETPOOL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_socketpool), (mp_obj_t)&socketpool_module },
587+
#else
588+
#define SOCKETPOOL_MODULE
589+
#endif
590+
583591
#if CIRCUITPY_STAGE
584592
extern const struct _mp_obj_module_t stage_module;
585593
#define STAGE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module },
@@ -764,6 +772,7 @@ extern const struct _mp_obj_module_t wifi_module;
764772
SDCARDIO_MODULE \
765773
SDIOIO_MODULE \
766774
SHARPDISPLAY_MODULE \
775+
SOCKETPOOL_MODULE \
767776
STAGE_MODULE \
768777
STORAGE_MODULE \
769778
STRUCT_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
185185
CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
186186
CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
187187

188+
CIRCUITPY_SOCKETPOOL ?= 0
189+
CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL)
190+
188191
# Currently always off.
189192
CIRCUITPY_STAGE ?= 0
190193
CFLAGS += -DCIRCUITPY_STAGE=$(CIRCUITPY_STAGE)

0 commit comments

Comments
 (0)