Skip to content

Commit b435e7b

Browse files
microdev1anecdata
andcommitted
update wifi monitor
- rename loss method to lost - add method to get queued packet count Co-authored-by: anecdata <[email protected]>
1 parent d5f0323 commit b435e7b

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

ports/espressif/common-hal/wifi/Monitor.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void wifi_monitor_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type) {
6666
if (self->queue) {
6767
// send packet
6868
if (xQueueSendFromISR(self->queue, &packet, NULL) != pdTRUE) {
69-
self->loss++;
69+
self->lost++;
7070
free(packet.payload);
7171
ESP_LOGE(TAG, "packet queue full");
7272
}
@@ -138,10 +138,14 @@ mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self) {
138138
return mp_obj_new_int_from_uint(self->queue_length);
139139
}
140140

141-
mp_obj_t common_hal_wifi_monitor_get_loss(wifi_monitor_obj_t *self) {
142-
size_t loss = self->loss;
143-
self->loss = 0;
144-
return mp_obj_new_int_from_uint(loss);
141+
mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self) {
142+
size_t lost = self->lost;
143+
self->lost = 0;
144+
return mp_obj_new_int_from_uint(lost);
145+
}
146+
147+
mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self) {
148+
return mp_obj_new_int_from_uint(uxQueueMessagesWaiting(self->queue));
145149
}
146150

147151
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) {

ports/espressif/common-hal/wifi/Monitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
typedef struct {
3434
mp_obj_base_t base;
3535
uint8_t channel;
36-
size_t loss;
36+
size_t lost;
3737
size_t queue_length;
3838
QueueHandle_t queue;
3939
} wifi_monitor_obj_t;

shared-bindings/wifi/Monitor.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,40 +120,49 @@ STATIC mp_obj_t wifi_monitor_obj_deinit(mp_obj_t self_in) {
120120
}
121121
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_deinit_obj, wifi_monitor_obj_deinit);
122122

123-
STATIC void check_for_deinit(mp_obj_t self_in) {
124-
if (common_hal_wifi_monitor_deinited()) {
125-
raise_deinited_error();
126-
}
123+
//| def lost(self) -> int:
124+
//| """Returns the packet loss count. The counter resets after each poll."""
125+
//| ...
126+
//|
127+
STATIC mp_obj_t wifi_monitor_obj_get_lost(mp_obj_t self_in) {
128+
return common_hal_wifi_monitor_get_lost(self_in);
127129
}
130+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_lost_obj, wifi_monitor_obj_get_lost);
128131

129-
//| def loss(self) -> int:
130-
//| """Returns the packet loss count. The counter resets after each poll."""
132+
//| def queued(self) -> int:
133+
//| """Returns the packet queued count."""
131134
//| ...
132135
//|
133-
STATIC mp_obj_t wifi_monitor_obj_get_loss(mp_obj_t self_in) {
134-
return common_hal_wifi_monitor_get_loss(self_in);
136+
STATIC mp_obj_t wifi_monitor_obj_get_queued(mp_obj_t self_in) {
137+
if (common_hal_wifi_monitor_deinited()) {
138+
return mp_obj_new_int_from_uint(0);
139+
}
140+
return common_hal_wifi_monitor_get_queued(self_in);
135141
}
136-
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_loss_obj, wifi_monitor_obj_get_loss);
142+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_queued_obj, wifi_monitor_obj_get_queued);
137143

138144
//| def packet(self) -> dict:
139145
//| """Returns the monitor packet."""
140146
//| ...
141147
//|
142148
STATIC mp_obj_t wifi_monitor_obj_get_packet(mp_obj_t self_in) {
143-
check_for_deinit(self_in);
149+
if (common_hal_wifi_monitor_deinited()) {
150+
raise_deinited_error();
151+
}
144152
return common_hal_wifi_monitor_get_packet(self_in);
145153
}
146154
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_packet_obj, wifi_monitor_obj_get_packet);
147155

148156
STATIC const mp_rom_map_elem_t wifi_monitor_locals_dict_table[] = {
149157
// properties
150158
{ MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&wifi_monitor_channel_obj) },
151-
{ MP_ROM_QSTR(MP_QSTR_queue), MP_ROM_PTR(&wifi_monitor_queue_obj) },
159+
{ MP_ROM_QSTR(MP_QSTR_queue), MP_ROM_PTR(&wifi_monitor_queue_obj) },
152160

153161
// functions
154-
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&wifi_monitor_deinit_obj) },
155-
{ MP_ROM_QSTR(MP_QSTR_loss), MP_ROM_PTR(&wifi_monitor_loss_obj) },
156-
{ MP_ROM_QSTR(MP_QSTR_packet), MP_ROM_PTR(&wifi_monitor_packet_obj) },
162+
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&wifi_monitor_deinit_obj) },
163+
{ MP_ROM_QSTR(MP_QSTR_lost), MP_ROM_PTR(&wifi_monitor_lost_obj) },
164+
{ MP_ROM_QSTR(MP_QSTR_queued), MP_ROM_PTR(&wifi_monitor_queued_obj) },
165+
{ MP_ROM_QSTR(MP_QSTR_packet), MP_ROM_PTR(&wifi_monitor_packet_obj) },
157166
};
158167
STATIC MP_DEFINE_CONST_DICT(wifi_monitor_locals_dict, wifi_monitor_locals_dict_table);
159168

shared-bindings/wifi/Monitor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ mp_obj_t common_hal_wifi_monitor_get_channel(wifi_monitor_obj_t *self);
4141

4242
mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self);
4343

44-
mp_obj_t common_hal_wifi_monitor_get_loss(wifi_monitor_obj_t *self);
44+
mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self);
45+
46+
mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self);
4547

4648
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self);
4749

0 commit comments

Comments
 (0)