Ping works!

This commit is contained in:
Scott Shawcroft 2020-08-11 14:50:37 -07:00
parent 3860991111
commit 7bdd243bf6
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
9 changed files with 28 additions and 17 deletions

View File

@ -28,6 +28,7 @@
#include <string.h>
#include "common-hal/wifi/__init__.h"
#include "lib/utils/interrupt_char.h"
#include "py/runtime.h"
#include "shared-bindings/ipaddress/IPv4Address.h"

View File

@ -24,6 +24,9 @@
* THE SOFTWARE.
*/
#include "common-hal/wifi/__init__.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
#include "shared-bindings/wifi/Radio.h"
#include "py/runtime.h"
@ -148,3 +151,14 @@ void wifi_reset(void) {
radio->netif = NULL;
ESP_ERROR_CHECK(esp_netif_deinit());
}
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address) {
if (!MP_OBJ_IS_TYPE(ip_address, &ipaddress_ipv4address_type)) {
mp_raise_ValueError(translate("Only IPv4 addresses supported"));
}
mp_obj_t packed = common_hal_ipaddress_ipv4address_get_packed(ip_address);
size_t len;
const char* bytes = mp_obj_str_get_data(packed, &len);
IP_ADDR4(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]);
}

View File

@ -29,6 +29,10 @@
#include "py/obj.h"
#include "lwip/api.h"
void wifi_reset(void);
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address);
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI___INIT___H

View File

@ -31,7 +31,7 @@
extern const mp_obj_type_t ipaddress_ipv4address_type;
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value);
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value);
void common_hal_ipaddress_ipv4address_construct(ipaddress_ipv4address_obj_t* self, uint8_t* buf, size_t len);
mp_obj_t common_hal_ipaddress_ipv4address_get_packed(ipaddress_ipv4address_obj_t* self);

View File

@ -43,8 +43,8 @@
//|
STATIC mp_obj_t ipaddress_ip_address(mp_obj_t ip_in) {
mp_int_t value;
if (mp_obj_get_int_maybe(ip_in, &value)) {
uint32_t value;
if (mp_obj_get_int_maybe(ip_in, (mp_int_t*) &value)) {
// We're done.
} else if (MP_OBJ_IS_STR(ip_in)) {
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) {
}
size_t last_period = 0;
value = 0;
for (size_t i = 0; i < 4; i++) {
mp_obj_t octet = mp_parse_num_integer((const char*) str_data + last_period, period_index[i] - last_period, 10, NULL);
last_period = period_index[i] + 1;
value |= MP_OBJ_SMALL_INT_VALUE(octet) << (24 - i * 8);
mp_int_t int_octet = MP_OBJ_SMALL_INT_VALUE(octet);
value |= int_octet << (i * 8);
}
} else {
mp_raise_ValueError(translate("Only raw int supported for ip."));

View File

@ -29,6 +29,6 @@
#include "shared-module/ipaddress/__init__.h"
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value);
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_IPADDRESS___INIT___H

View File

@ -180,7 +180,7 @@ STATIC mp_obj_t wifi_radio_ping(size_t n_args, const mp_obj_t *pos_args, mp_map_
mp_int_t time_ms = common_hal_wifi_radio_ping(self, args[ARG_ip].u_obj, timeout);
return mp_obj_new_float(time_ms / 1000);
return mp_obj_new_float(time_ms / 1000.0);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_ping_obj, 1, wifi_radio_ping);

View File

@ -27,14 +27,9 @@
#include "shared-bindings/ipaddress/__init__.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
mp_obj_t common_hal_ipaddress_new_ipv4address(mp_int_t value) {
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value) {
ipaddress_ipv4address_obj_t* self = m_new_obj(ipaddress_ipv4address_obj_t);
self->base.type = &ipaddress_ipv4address_type;
common_hal_ipaddress_ipv4address_construct(self, (uint8_t*) &value, 4);
return self;
}
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address) {
// FIX THIS TOMORROW!
}

View File

@ -31,10 +31,6 @@
#include "py/obj.h"
#include "lwip/api.h"
mp_obj_t common_hal_ipaddress_new_ipv4(uint32_t value);
void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_address);
#endif // MICROPY_INCLUDED_SHARED_MODULE_IPADDRESS___INIT___H