From b435e7b56a6a31900251a17f0bbe8a15d032fca0 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 4 Nov 2021 16:14:18 +0530 Subject: [PATCH] update wifi monitor - rename loss method to lost - add method to get queued packet count Co-authored-by: anecdata <16617689+anecdata@users.noreply.github.com> --- ports/espressif/common-hal/wifi/Monitor.c | 14 +++++--- ports/espressif/common-hal/wifi/Monitor.h | 2 +- shared-bindings/wifi/Monitor.c | 39 ++++++++++++++--------- shared-bindings/wifi/Monitor.h | 4 ++- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ports/espressif/common-hal/wifi/Monitor.c b/ports/espressif/common-hal/wifi/Monitor.c index e6e7175c51..b0ce341d71 100644 --- a/ports/espressif/common-hal/wifi/Monitor.c +++ b/ports/espressif/common-hal/wifi/Monitor.c @@ -66,7 +66,7 @@ static void wifi_monitor_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type) { if (self->queue) { // send packet if (xQueueSendFromISR(self->queue, &packet, NULL) != pdTRUE) { - self->loss++; + self->lost++; free(packet.payload); ESP_LOGE(TAG, "packet queue full"); } @@ -138,10 +138,14 @@ mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self) { return mp_obj_new_int_from_uint(self->queue_length); } -mp_obj_t common_hal_wifi_monitor_get_loss(wifi_monitor_obj_t *self) { - size_t loss = self->loss; - self->loss = 0; - return mp_obj_new_int_from_uint(loss); +mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self) { + size_t lost = self->lost; + self->lost = 0; + return mp_obj_new_int_from_uint(lost); +} + +mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self) { + return mp_obj_new_int_from_uint(uxQueueMessagesWaiting(self->queue)); } mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) { diff --git a/ports/espressif/common-hal/wifi/Monitor.h b/ports/espressif/common-hal/wifi/Monitor.h index 84eca71a36..e4e50dddc1 100644 --- a/ports/espressif/common-hal/wifi/Monitor.h +++ b/ports/espressif/common-hal/wifi/Monitor.h @@ -33,7 +33,7 @@ typedef struct { mp_obj_base_t base; uint8_t channel; - size_t loss; + size_t lost; size_t queue_length; QueueHandle_t queue; } wifi_monitor_obj_t; diff --git a/shared-bindings/wifi/Monitor.c b/shared-bindings/wifi/Monitor.c index 8f1c9e2d90..a9998e7410 100644 --- a/shared-bindings/wifi/Monitor.c +++ b/shared-bindings/wifi/Monitor.c @@ -120,27 +120,35 @@ STATIC mp_obj_t wifi_monitor_obj_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_deinit_obj, wifi_monitor_obj_deinit); -STATIC void check_for_deinit(mp_obj_t self_in) { - if (common_hal_wifi_monitor_deinited()) { - raise_deinited_error(); - } -} - -//| def loss(self) -> int: +//| def lost(self) -> int: //| """Returns the packet loss count. The counter resets after each poll.""" //| ... //| -STATIC mp_obj_t wifi_monitor_obj_get_loss(mp_obj_t self_in) { - return common_hal_wifi_monitor_get_loss(self_in); +STATIC mp_obj_t wifi_monitor_obj_get_lost(mp_obj_t self_in) { + return common_hal_wifi_monitor_get_lost(self_in); } -MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_loss_obj, wifi_monitor_obj_get_loss); +MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_lost_obj, wifi_monitor_obj_get_lost); + +//| def queued(self) -> int: +//| """Returns the packet queued count.""" +//| ... +//| +STATIC mp_obj_t wifi_monitor_obj_get_queued(mp_obj_t self_in) { + if (common_hal_wifi_monitor_deinited()) { + return mp_obj_new_int_from_uint(0); + } + return common_hal_wifi_monitor_get_queued(self_in); +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_queued_obj, wifi_monitor_obj_get_queued); //| def packet(self) -> dict: //| """Returns the monitor packet.""" //| ... //| STATIC mp_obj_t wifi_monitor_obj_get_packet(mp_obj_t self_in) { - check_for_deinit(self_in); + if (common_hal_wifi_monitor_deinited()) { + raise_deinited_error(); + } return common_hal_wifi_monitor_get_packet(self_in); } MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_packet_obj, wifi_monitor_obj_get_packet); @@ -148,12 +156,13 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_packet_obj, wifi_monitor_obj_get_packet); STATIC const mp_rom_map_elem_t wifi_monitor_locals_dict_table[] = { // properties { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_monitor_channel_obj) }, - { MP_ROM_QSTR(MP_QSTR_queue), MP_ROM_PTR(&wifi_monitor_queue_obj) }, + { MP_ROM_QSTR(MP_QSTR_queue), MP_ROM_PTR(&wifi_monitor_queue_obj) }, // functions - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&wifi_monitor_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_loss), MP_ROM_PTR(&wifi_monitor_loss_obj) }, - { MP_ROM_QSTR(MP_QSTR_packet), MP_ROM_PTR(&wifi_monitor_packet_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&wifi_monitor_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_lost), MP_ROM_PTR(&wifi_monitor_lost_obj) }, + { MP_ROM_QSTR(MP_QSTR_queued), MP_ROM_PTR(&wifi_monitor_queued_obj) }, + { MP_ROM_QSTR(MP_QSTR_packet), MP_ROM_PTR(&wifi_monitor_packet_obj) }, }; STATIC MP_DEFINE_CONST_DICT(wifi_monitor_locals_dict, wifi_monitor_locals_dict_table); diff --git a/shared-bindings/wifi/Monitor.h b/shared-bindings/wifi/Monitor.h index b6b71c07a7..38c52a05e7 100644 --- a/shared-bindings/wifi/Monitor.h +++ b/shared-bindings/wifi/Monitor.h @@ -41,7 +41,9 @@ mp_obj_t common_hal_wifi_monitor_get_channel(wifi_monitor_obj_t *self); mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self); -mp_obj_t common_hal_wifi_monitor_get_loss(wifi_monitor_obj_t *self); +mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self); + +mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self); mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self);