From 2a563cc8bada8dd0e8b34825f7ee27d3c2d129b8 Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Thu, 30 Jun 2022 15:10:16 -0700 Subject: [PATCH 1/4] first cut at wifi.radio.tx_power --- ports/espressif/common-hal/wifi/Radio.c | 10 ++++++++++ shared-bindings/wifi/Radio.c | 21 +++++++++++++++++++++ shared-bindings/wifi/Radio.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index b6b155a71c..4aa9f9cfdd 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -139,6 +139,16 @@ void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t esp_wifi_set_mac(ESP_IF_WIFI_STA, mac); } +uint8_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self) { + int8_t tx_power; + esp_wifi_get_max_tx_power(&tx_power); + return tx_power; +} + +void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const uint8_t tx_power) { + esp_wifi_set_max_tx_power(tx_power); +} + mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) { uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_AP, mac); diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 42a4c53161..70ee16a090 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -138,6 +138,27 @@ MP_PROPERTY_GETSET(wifi_radio_mac_address_obj, (mp_obj_t)&wifi_radio_get_mac_address_obj, (mp_obj_t)&wifi_radio_set_mac_address_obj); +//| tx_power: int +//| """Set TX WiFi power.""" +//| +STATIC mp_obj_t wifi_radio_get_tx_power(mp_obj_t self_in) { + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_int(common_hal_wifi_radio_get_tx_power(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_tx_power_obj, wifi_radio_get_tx_power); + +STATIC mp_obj_t wifi_radio_set_tx_power(mp_obj_t self_in, mp_obj_t tx_power_in) { + mp_int_t tx_power = mp_obj_get_int(tx_power_in); + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_wifi_radio_set_tx_power(self, tx_power); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_tx_power_obj, wifi_radio_set_tx_power); + +MP_PROPERTY_GETSET(wifi_radio_tx_power_obj, + (mp_obj_t)&wifi_radio_get_tx_power_obj, + (mp_obj_t)&wifi_radio_set_tx_power_obj); + //| mac_address_ap: ReadableBuffer //| """MAC address for the AP. When the address is altered after interface is started //| the changes would only be reflected once the interface restarts.""" diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index b2593ba8ff..e89e22ebe9 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -82,6 +82,9 @@ extern void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint8_t *mac); +extern uint8_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const uint8_t power); + extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self); From d13f24648e4456b1565fb61f8afa6112b8fff4cc Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Thu, 30 Jun 2022 15:27:57 -0700 Subject: [PATCH 2/4] first cut at wifi.radio.tx_power --- shared-bindings/wifi/Radio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 70ee16a090..7420c592cf 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -570,6 +570,7 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mac_address), MP_ROM_PTR(&wifi_radio_mac_address_obj) }, { MP_ROM_QSTR(MP_QSTR_mac_address_ap), MP_ROM_PTR(&wifi_radio_mac_address_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_tx_power), MP_ROM_PTR(&wifi_radio_tx_power_obj) }, { MP_ROM_QSTR(MP_QSTR_start_scanning_networks), MP_ROM_PTR(&wifi_radio_start_scanning_networks_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_scanning_networks), MP_ROM_PTR(&wifi_radio_stop_scanning_networks_obj) }, From 698d563dcfee91bd67254cc9b2ba55b39693e8f4 Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Thu, 30 Jun 2022 15:33:03 -0700 Subject: [PATCH 3/4] adust wifi.radio.tx_power to be x4 (in db) as mentioned in #6540 --- ports/espressif/common-hal/wifi/Radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 4aa9f9cfdd..bc6e12dfd3 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -142,11 +142,11 @@ void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t uint8_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self) { int8_t tx_power; esp_wifi_get_max_tx_power(&tx_power); - return tx_power; + return tx_power / 4; } void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const uint8_t tx_power) { - esp_wifi_set_max_tx_power(tx_power); + esp_wifi_set_max_tx_power(tx_power * 4); } mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) { From 2d7793e140ce3b1f3ccfceb73eb1f95091212a48 Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Fri, 1 Jul 2022 09:49:59 -0700 Subject: [PATCH 4/4] update tx_power description per dhalbert suggestion --- shared-bindings/wifi/Radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 7420c592cf..a0a4df2548 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -139,7 +139,7 @@ MP_PROPERTY_GETSET(wifi_radio_mac_address_obj, (mp_obj_t)&wifi_radio_set_mac_address_obj); //| tx_power: int -//| """Set TX WiFi power.""" +//| """Wifi transmission power, in dBm.""" //| STATIC mp_obj_t wifi_radio_get_tx_power(mp_obj_t self_in) { wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);