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:
parent
d5f0323ff7
commit
b435e7b56a
|
@ -66,7 +66,7 @@ static void wifi_monitor_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type) {
|
||||||
if (self->queue) {
|
if (self->queue) {
|
||||||
// send packet
|
// send packet
|
||||||
if (xQueueSendFromISR(self->queue, &packet, NULL) != pdTRUE) {
|
if (xQueueSendFromISR(self->queue, &packet, NULL) != pdTRUE) {
|
||||||
self->loss++;
|
self->lost++;
|
||||||
free(packet.payload);
|
free(packet.payload);
|
||||||
ESP_LOGE(TAG, "packet queue full");
|
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);
|
return mp_obj_new_int_from_uint(self->queue_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
size_t loss = self->loss;
|
size_t lost = self->lost;
|
||||||
self->loss = 0;
|
self->lost = 0;
|
||||||
return mp_obj_new_int_from_uint(loss);
|
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) {
|
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) {
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
uint8_t channel;
|
uint8_t channel;
|
||||||
size_t loss;
|
size_t lost;
|
||||||
size_t queue_length;
|
size_t queue_length;
|
||||||
QueueHandle_t queue;
|
QueueHandle_t queue;
|
||||||
} wifi_monitor_obj_t;
|
} wifi_monitor_obj_t;
|
||||||
|
|
|
@ -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 MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_deinit_obj, wifi_monitor_obj_deinit);
|
||||||
|
|
||||||
STATIC void check_for_deinit(mp_obj_t self_in) {
|
//| def lost(self) -> int:
|
||||||
if (common_hal_wifi_monitor_deinited()) {
|
|
||||||
raise_deinited_error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//| def loss(self) -> int:
|
|
||||||
//| """Returns the packet loss count. The counter resets after each poll."""
|
//| """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) {
|
STATIC mp_obj_t wifi_monitor_obj_get_lost(mp_obj_t self_in) {
|
||||||
return common_hal_wifi_monitor_get_loss(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:
|
//| def packet(self) -> dict:
|
||||||
//| """Returns the monitor packet."""
|
//| """Returns the monitor packet."""
|
||||||
//| ...
|
//| ...
|
||||||
//|
|
//|
|
||||||
STATIC mp_obj_t wifi_monitor_obj_get_packet(mp_obj_t self_in) {
|
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);
|
return common_hal_wifi_monitor_get_packet(self_in);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_packet_obj, wifi_monitor_obj_get_packet);
|
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[] = {
|
STATIC const mp_rom_map_elem_t wifi_monitor_locals_dict_table[] = {
|
||||||
// properties
|
// properties
|
||||||
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_monitor_channel_obj) },
|
{ 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
|
// functions
|
||||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&wifi_monitor_deinit_obj) },
|
{ 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_packet), MP_ROM_PTR(&wifi_monitor_packet_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);
|
STATIC MP_DEFINE_CONST_DICT(wifi_monitor_locals_dict, wifi_monitor_locals_dict_table);
|
||||||
|
|
||||||
|
|
|
@ -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_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);
|
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue