From e2652f8aacf7bbde20ff6b4722df9ace6019b265 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:34:14 +0530 Subject: [PATCH] add packet class --- py/circuitpy_defns.mk | 2 + shared-bindings/wifi/Packet.c | 70 +++++++++++++++++++++++++++++++++ shared-bindings/wifi/Packet.h | 41 +++++++++++++++++++ shared-bindings/wifi/__init__.c | 18 +++++---- 4 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 shared-bindings/wifi/Packet.c create mode 100644 shared-bindings/wifi/Packet.h diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 836f3c7af1..a03b629ca4 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -433,6 +433,7 @@ SRC_COMMON_HAL_ALL = \ watchdog/WatchDogMode.c \ watchdog/WatchDogTimer.c \ watchdog/__init__.c \ + wifi/Monitor.c \ wifi/Network.c \ wifi/Radio.c \ wifi/ScannedNetworks.c \ @@ -475,6 +476,7 @@ $(filter $(SRC_PATTERNS), \ paralleldisplay/ParallelBus.c \ supervisor/RunReason.c \ wifi/AuthMode.c \ + wifi/Packet.c \ ) SRC_BINDINGS_ENUMS += \ diff --git a/shared-bindings/wifi/Packet.c b/shared-bindings/wifi/Packet.c new file mode 100644 index 0000000000..d21c8b0639 --- /dev/null +++ b/shared-bindings/wifi/Packet.c @@ -0,0 +1,70 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/enum.h" + +#include "shared-bindings/wifi/Packet.h" + +MAKE_ENUM_VALUE(wifi_packet_type, packet, CH, PACKET_CH); +MAKE_ENUM_VALUE(wifi_packet_type, packet, LEN, PACKET_LEN); +MAKE_ENUM_VALUE(wifi_packet_type, packet, RAW, PACKET_RAW); +MAKE_ENUM_VALUE(wifi_packet_type, packet, RSSI, PACKET_RSSI); + +//| class Packet: +//| """The packet parameters.""" +//| +//| CH: object +//| """The packet's channel.""" +//| +//| LEN: object +//| """The packet's length.""" +//| +//| RAW: object +//| """The packet's payload.""" +//| +//| RSSI: object +//| """The packet's rssi.""" +//| +MAKE_ENUM_MAP(wifi_packet) { + MAKE_ENUM_MAP_ENTRY(packet, CH), + MAKE_ENUM_MAP_ENTRY(packet, LEN), + MAKE_ENUM_MAP_ENTRY(packet, RAW), + MAKE_ENUM_MAP_ENTRY(packet, RSSI), +}; +STATIC MP_DEFINE_CONST_DICT(wifi_packet_locals_dict, wifi_packet_locals_table); + +MAKE_PRINTER(wifi, wifi_packet); + +const mp_obj_type_t wifi_packet_type = { + { &mp_type_type }, + .name = MP_QSTR_Packet, + .print = wifi_packet_print, + .locals_dict = (mp_obj_t)&wifi_packet_locals_dict, + .flags = MP_TYPE_FLAG_EXTENDED, + MP_TYPE_EXTENDED_FIELDS( + .unary_op = mp_generic_unary_op, + ), +}; diff --git a/shared-bindings/wifi/Packet.h b/shared-bindings/wifi/Packet.h new file mode 100644 index 0000000000..09dfddfc98 --- /dev/null +++ b/shared-bindings/wifi/Packet.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H + +#include "py/enum.h" + +typedef enum { + PACKET_CH, + PACKET_LEN, + PACKET_RAW, + PACKET_RSSI, +} wifi_packet_t; + +extern const mp_obj_type_t wifi_packet_type; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H diff --git a/shared-bindings/wifi/__init__.c b/shared-bindings/wifi/__init__.c index ef72dced1f..399b47cc47 100644 --- a/shared-bindings/wifi/__init__.c +++ b/shared-bindings/wifi/__init__.c @@ -27,9 +27,10 @@ #include "py/objexcept.h" #include "py/runtime.h" #include "shared-bindings/wifi/__init__.h" -#include "shared-bindings/wifi/AuthMode.h" -#include "shared-bindings/wifi/Network.h" #include "shared-bindings/wifi/Radio.h" +#include "shared-bindings/wifi/Network.h" +#include "shared-bindings/wifi/AuthMode.h" +#include "shared-bindings/wifi/Packet.h" //| """ //| The `wifi` module provides necessary low-level functionality for managing @@ -51,16 +52,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(wifi___init___obj, wifi___init__); STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) }, - { MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) }, - { MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) }, - { MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) }, // Initialization { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) }, + { MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) }, + { MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) }, + { MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) }, + { MP_ROM_QSTR(MP_QSTR_Packet), MP_ROM_PTR(&wifi_packet_type) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) }, }; STATIC MP_DEFINE_CONST_DICT(wifi_module_globals, wifi_module_globals_table);