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>
This commit is contained in:
microDev 2021-11-04 16:14:18 +05:30
parent d5f0323ff7
commit b435e7b56a
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
4 changed files with 37 additions and 22 deletions

View File

@ -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) {

View File

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

View File

@ -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);
@ -152,7 +160,8 @@ STATIC const mp_rom_map_elem_t wifi_monitor_locals_dict_table[] = {
// 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_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);

View File

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