|
59 | 59 | #define NETIF_STA (&cyw43_state.netif[CYW43_ITF_STA])
|
60 | 60 | #define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP])
|
61 | 61 |
|
| 62 | +static inline uint32_t nw_get_le32(const uint8_t *buf) { |
| 63 | + return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; |
| 64 | +} |
| 65 | + |
| 66 | +static inline void nw_put_le32(uint8_t *buf, uint32_t x) { |
| 67 | + buf[0] = x; |
| 68 | + buf[1] = x >> 8; |
| 69 | + buf[2] = x >> 16; |
| 70 | + buf[3] = x >> 24; |
| 71 | +} |
| 72 | + |
62 | 73 | NORETURN static void ro_attribute(int attr) {
|
63 | 74 | mp_raise_msg_varg(&mp_type_AttributeError, MP_ERROR_TEXT("'%s' object has no attribute '%q'"), "Radio", attr);
|
64 | 75 | }
|
@@ -96,12 +107,19 @@ void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t
|
96 | 107 | }
|
97 | 108 |
|
98 | 109 | mp_float_t common_hal_wifi_radio_get_tx_power(wifi_radio_obj_t *self) {
|
99 |
| - return MICROPY_FLOAT_CONST(0.); |
| 110 | + uint8_t buf[13]; |
| 111 | + memcpy(buf, "qtxpower\x00\x00\x00\x00\x00", 13); |
| 112 | + cyw43_ioctl(&cyw43_state, CYW43_IOCTL_GET_VAR, 13, buf, CYW43_ITF_STA); |
| 113 | + return nw_get_le32(buf) * MICROPY_FLOAT_CONST(0.25); |
100 | 114 | }
|
101 | 115 |
|
102 | 116 | void common_hal_wifi_radio_set_tx_power(wifi_radio_obj_t *self, const mp_float_t tx_power) {
|
103 |
| - ro_attribute(MP_QSTR_tx_power); |
104 |
| - |
| 117 | + mp_int_t dbm_times_four = (int)(4 * tx_power); |
| 118 | + uint8_t buf[9 + 4]; |
| 119 | + memcpy(buf, "qtxpower\x00", 9); |
| 120 | + nw_put_le32(buf + 9, dbm_times_four); |
| 121 | + cyw43_ioctl(&cyw43_state, CYW43_IOCTL_SET_VAR, 9 + 4, buf, CYW43_ITF_STA); |
| 122 | + cyw43_ioctl(&cyw43_state, CYW43_IOCTL_SET_VAR, 9 + 4, buf, CYW43_ITF_AP); |
105 | 123 | }
|
106 | 124 |
|
107 | 125 | mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) {
|
|
0 commit comments