mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
extmod/modnetwork: Add network.hostname() and network.country().
This provides a standard interface to setting the global networking config for all interfaces and interface types. For ports that already use either a static hostname (mimxrt, rp2) they will now use the configured value. The default is configured by the port (or optionally the board). For interfaces that previously supported .config(hostname), this is still supported but now implemented using the global network.hostname. Similarly, pyb.country and rp2.country are now deprecated, but the methods still exist (and forward to network.hostname). Because ESP32/ESP8266 do not use extmod/modnetwork.c they are not affected by this commit. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
fc4c47f7bc
commit
a377302623
@@ -29,25 +29,11 @@
|
||||
#include "modrp2.h"
|
||||
|
||||
#if MICROPY_PY_NETWORK_CYW43
|
||||
#include "lib/cyw43-driver/src/cyw43_country.h"
|
||||
#include "extmod/modnetwork.h"
|
||||
#endif
|
||||
|
||||
extern uint32_t cyw43_country_code;
|
||||
|
||||
STATIC mp_obj_t rp2_country(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
char code[2] = {cyw43_country_code, cyw43_country_code >> 8};
|
||||
return mp_obj_new_str(code, 2);
|
||||
} else {
|
||||
size_t len;
|
||||
const char *str = mp_obj_str_get_data(args[0], &len);
|
||||
if (len != 2) {
|
||||
mp_raise_ValueError(NULL);
|
||||
}
|
||||
cyw43_country_code = CYW43_COUNTRY(str[0], str[1], 0);
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_country_obj, 0, 1, rp2_country);
|
||||
#if MICROPY_PY_NETWORK_CYW43
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = {
|
||||
@@ -57,7 +43,8 @@ STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_StateMachine), MP_ROM_PTR(&rp2_state_machine_type) },
|
||||
|
||||
#if MICROPY_PY_NETWORK_CYW43
|
||||
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&rp2_country_obj) },
|
||||
// Deprecated (use network.country instead).
|
||||
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) },
|
||||
#endif
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(rp2_module_globals, rp2_module_globals_table);
|
||||
|
||||
Reference in New Issue
Block a user