Skip to content

Commit 7bdd243

Browse files
committed
Ping works!
1 parent 3860991 commit 7bdd243

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <string.h>
3030

31+
#include "common-hal/wifi/__init__.h"
3132
#include "lib/utils/interrupt_char.h"
3233
#include "py/runtime.h"
3334
#include "shared-bindings/ipaddress/IPv4Address.h"

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "common-hal/wifi/__init__.h"
28+
29+
#include "shared-bindings/ipaddress/IPv4Address.h"
2730
#include "shared-bindings/wifi/Radio.h"
2831

2932
#include "py/runtime.h"
@@ -148,3 +151,14 @@ void wifi_reset(void) {
148151
radio->netif = NULL;
149152
ESP_ERROR_CHECK(esp_netif_deinit());
150153
}
154+
155+
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address) {
156+
if (!MP_OBJ_IS_TYPE(ip_address, &ipaddress_ipv4address_type)) {
157+
mp_raise_ValueError(translate("Only IPv4 addresses supported"));
158+
}
159+
mp_obj_t packed = common_hal_ipaddress_ipv4address_get_packed(ip_address);
160+
size_t len;
161+
const char* bytes = mp_obj_str_get_data(packed, &len);
162+
163+
IP_ADDR4(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]);
164+
}

ports/esp32s2/common-hal/wifi/__init__.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#include "py/obj.h"
3131

32+
#include "lwip/api.h"
33+
3234
void wifi_reset(void);
3335

36+
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address);
37+
3438
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H

shared-bindings/ipaddress/IPv4Address.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
extern const mp_obj_type_t ipaddress_ipv4address_type;
3333

34-
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value);
34+
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value);
3535
void common_hal_ipaddress_ipv4address_construct(ipaddress_ipv4address_obj_t* self, uint8_t* buf, size_t len);
3636
mp_obj_t common_hal_ipaddress_ipv4address_get_packed(ipaddress_ipv4address_obj_t* self);
3737

shared-bindings/ipaddress/__init__.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
//|
4444

4545
STATIC mp_obj_t ipaddress_ip_address(mp_obj_t ip_in) {
46-
mp_int_t value;
47-
if (mp_obj_get_int_maybe(ip_in, &value)) {
46+
uint32_t value;
47+
if (mp_obj_get_int_maybe(ip_in, (mp_int_t*) &value)) {
4848
// We're done.
4949
} else if (MP_OBJ_IS_STR(ip_in)) {
5050
GET_STR_DATA_LEN(ip_in, str_data, str_len);
@@ -63,11 +63,12 @@ STATIC mp_obj_t ipaddress_ip_address(mp_obj_t ip_in) {
6363
}
6464

6565
size_t last_period = 0;
66+
value = 0;
6667
for (size_t i = 0; i < 4; i++) {
6768
mp_obj_t octet = mp_parse_num_integer((const char*) str_data + last_period, period_index[i] - last_period, 10, NULL);
6869
last_period = period_index[i] + 1;
69-
value |= MP_OBJ_SMALL_INT_VALUE(octet) << (24 - i * 8);
70-
70+
mp_int_t int_octet = MP_OBJ_SMALL_INT_VALUE(octet);
71+
value |= int_octet << (i * 8);
7172
}
7273
} else {
7374
mp_raise_ValueError(translate("Only raw int supported for ip."));

shared-bindings/ipaddress/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929

3030
#include "shared-module/ipaddress/__init__.h"
3131

32-
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value);
32+
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value);
3333

3434
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_IPADDRESS___INIT___H

shared-bindings/wifi/Radio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ STATIC mp_obj_t wifi_radio_ping(size_t n_args, const mp_obj_t *pos_args, mp_map_
180180

181181
mp_int_t time_ms = common_hal_wifi_radio_ping(self, args[ARG_ip].u_obj, timeout);
182182

183-
return mp_obj_new_float(time_ms / 1000);
183+
return mp_obj_new_float(time_ms / 1000.0);
184184
}
185185
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_ping_obj, 1, wifi_radio_ping);
186186

shared-module/ipaddress/__init__.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@
2727
#include "shared-bindings/ipaddress/__init__.h"
2828
#include "shared-bindings/ipaddress/IPv4Address.h"
2929

30-
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value) {
30+
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value) {
3131
ipaddress_ipv4address_obj_t* self = m_new_obj(ipaddress_ipv4address_obj_t);
3232
self->base.type = &ipaddress_ipv4address_type;
3333
common_hal_ipaddress_ipv4address_construct(self, (uint8_t*) &value, 4);
3434
return self;
3535
}
36-
37-
38-
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address) {
39-
// FIX THIS TOMORROW!
40-
}

shared-module/ipaddress/__init__.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131

3232
#include "py/obj.h"
3333

34-
#include "lwip/api.h"
35-
3634
mp_obj_t common_hal_ipaddress_new_ipv4(uint32_t value);
3735

38-
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address);
39-
4036
#endif // MICROPY_INCLUDED_SHARED_MODULE_IPADDRESS___INIT___H

0 commit comments

Comments
 (0)