Skip to content

Commit

Permalink
update wifi monitor
Browse files Browse the repository at this point in the history
- rename loss method to lost
- add method to get queued packet count

Co-authored-by: anecdata <[email protected]>
  • Loading branch information
microdev1 and anecdata committed Nov 4, 2021
1 parent d5f0323 commit b435e7b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
14 changes: 9 additions & 5 deletions ports/espressif/common-hal/wifi/Monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/wifi/Monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 23 additions & 14 deletions shared-bindings/wifi/Monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,49 @@ 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 lost(self) -> int:
//| """Returns the packet loss count. The counter resets after each poll."""
//| ...
//|
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_lost_obj, wifi_monitor_obj_get_lost);

//| def loss(self) -> int:
//| """Returns the packet loss count. The counter resets after each poll."""
//| def queued(self) -> int:
//| """Returns the packet queued count."""
//| ...
//|
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_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_loss_obj, wifi_monitor_obj_get_loss);
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);

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);

Expand Down
4 changes: 3 additions & 1 deletion shared-bindings/wifi/Monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b435e7b

Please sign in to comment.