esp32: Add 'config' function to network.LAN, reusing network.WLAN.

pull/5041/head
Eric Poulsen 2019-08-27 10:11:03 -07:00 zatwierdzone przez Damien George
rodzic afc8596c15
commit 5635b96461
3 zmienionych plików z 36 dodań i 14 usunięć

Wyświetl plik

@ -550,17 +550,24 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
// get the config for the interface
bool is_wifi = self->if_id == WIFI_IF_AP || self->if_id == WIFI_IF_STA;
wifi_config_t cfg;
ESP_EXCEPTIONS(esp_wifi_get_config(self->if_id, &cfg));
if (is_wifi) {
ESP_EXCEPTIONS(esp_wifi_get_config(self->if_id, &cfg));
}
#define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
if (kwargs->used != 0) {
if (!is_wifi) {
goto unknown;
}
for (size_t i = 0; i < kwargs->alloc; i++) {
if (mp_map_slot_is_filled(kwargs, i)) {
int req_if = -1;
#define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
switch ((uintptr_t)kwargs->table[i].key) {
case QS(MP_QSTR_mac): {
mp_buffer_info_t bufinfo;
@ -612,7 +619,6 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
default:
goto unknown;
}
#undef QS
// We post-check interface requirements to save on code size
if (req_if >= 0) {
@ -633,20 +639,34 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
}
int req_if = -1;
mp_obj_t val;
mp_obj_t val = mp_const_none;
#define QS(x) (uintptr_t)MP_OBJ_NEW_QSTR(x)
switch ((uintptr_t)args[1]) {
case QS(MP_QSTR_mac): {
uint8_t mac[6];
ESP_EXCEPTIONS(esp_wifi_get_mac(self->if_id, mac));
return mp_obj_new_bytes(mac, sizeof(mac));
switch (self->if_id) {
case WIFI_IF_AP: // fallthrough intentional
case WIFI_IF_STA:
ESP_EXCEPTIONS(esp_wifi_get_mac(self->if_id, mac));
return mp_obj_new_bytes(mac, sizeof(mac));
case ESP_IF_ETH:
esp_eth_get_mac(mac);
return mp_obj_new_bytes(mac, sizeof(mac));
default:
goto unknown;
}
}
case QS(MP_QSTR_essid):
if (self->if_id == WIFI_IF_STA) {
val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
} else {
val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
switch (self->if_id) {
case WIFI_IF_STA:
val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
break;
case WIFI_IF_AP:
val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
break;
default:
req_if = WIFI_IF_AP;
}
break;
case QS(MP_QSTR_hidden):
@ -670,6 +690,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
default:
goto unknown;
}
#undef QS
// We post-check interface requirements to save on code size
@ -682,8 +703,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
unknown:
mp_raise_ValueError("unknown config param");
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config);
STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) },

Wyświetl plik

@ -31,6 +31,7 @@ enum { PHY_LAN8720, PHY_TLK110 };
MP_DECLARE_CONST_FUN_OBJ_KW(get_lan_obj);
MP_DECLARE_CONST_FUN_OBJ_1(ppp_make_new_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj);
MP_DECLARE_CONST_FUN_OBJ_KW(esp_config_obj);
void usocket_events_deinit(void);

Wyświetl plik

@ -205,6 +205,7 @@ STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&lan_active_obj) },
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&lan_isconnected_obj) },
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lan_status_obj) },
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) },
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
};