Skip to content

Commit e2652f8

Browse files
committed
add packet class
1 parent 1099716 commit e2652f8

File tree

4 files changed

+121
-6
lines changed

4 files changed

+121
-6
lines changed

py/circuitpy_defns.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ SRC_COMMON_HAL_ALL = \
433433
watchdog/WatchDogMode.c \
434434
watchdog/WatchDogTimer.c \
435435
watchdog/__init__.c \
436+
wifi/Monitor.c \
436437
wifi/Network.c \
437438
wifi/Radio.c \
438439
wifi/ScannedNetworks.c \
@@ -475,6 +476,7 @@ $(filter $(SRC_PATTERNS), \
475476
paralleldisplay/ParallelBus.c \
476477
supervisor/RunReason.c \
477478
wifi/AuthMode.c \
479+
wifi/Packet.c \
478480
)
479481

480482
SRC_BINDINGS_ENUMS += \

shared-bindings/wifi/Packet.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/enum.h"
28+
29+
#include "shared-bindings/wifi/Packet.h"
30+
31+
MAKE_ENUM_VALUE(wifi_packet_type, packet, CH, PACKET_CH);
32+
MAKE_ENUM_VALUE(wifi_packet_type, packet, LEN, PACKET_LEN);
33+
MAKE_ENUM_VALUE(wifi_packet_type, packet, RAW, PACKET_RAW);
34+
MAKE_ENUM_VALUE(wifi_packet_type, packet, RSSI, PACKET_RSSI);
35+
36+
//| class Packet:
37+
//| """The packet parameters."""
38+
//|
39+
//| CH: object
40+
//| """The packet's channel."""
41+
//|
42+
//| LEN: object
43+
//| """The packet's length."""
44+
//|
45+
//| RAW: object
46+
//| """The packet's payload."""
47+
//|
48+
//| RSSI: object
49+
//| """The packet's rssi."""
50+
//|
51+
MAKE_ENUM_MAP(wifi_packet) {
52+
MAKE_ENUM_MAP_ENTRY(packet, CH),
53+
MAKE_ENUM_MAP_ENTRY(packet, LEN),
54+
MAKE_ENUM_MAP_ENTRY(packet, RAW),
55+
MAKE_ENUM_MAP_ENTRY(packet, RSSI),
56+
};
57+
STATIC MP_DEFINE_CONST_DICT(wifi_packet_locals_dict, wifi_packet_locals_table);
58+
59+
MAKE_PRINTER(wifi, wifi_packet);
60+
61+
const mp_obj_type_t wifi_packet_type = {
62+
{ &mp_type_type },
63+
.name = MP_QSTR_Packet,
64+
.print = wifi_packet_print,
65+
.locals_dict = (mp_obj_t)&wifi_packet_locals_dict,
66+
.flags = MP_TYPE_FLAG_EXTENDED,
67+
MP_TYPE_EXTENDED_FIELDS(
68+
.unary_op = mp_generic_unary_op,
69+
),
70+
};

shared-bindings/wifi/Packet.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H
29+
30+
#include "py/enum.h"
31+
32+
typedef enum {
33+
PACKET_CH,
34+
PACKET_LEN,
35+
PACKET_RAW,
36+
PACKET_RSSI,
37+
} wifi_packet_t;
38+
39+
extern const mp_obj_type_t wifi_packet_type;
40+
41+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_PACKET_H

shared-bindings/wifi/__init__.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#include "py/objexcept.h"
2828
#include "py/runtime.h"
2929
#include "shared-bindings/wifi/__init__.h"
30-
#include "shared-bindings/wifi/AuthMode.h"
31-
#include "shared-bindings/wifi/Network.h"
3230
#include "shared-bindings/wifi/Radio.h"
31+
#include "shared-bindings/wifi/Network.h"
32+
#include "shared-bindings/wifi/AuthMode.h"
33+
#include "shared-bindings/wifi/Packet.h"
3334

3435
//| """
3536
//| 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__);
5152

5253
STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = {
5354
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) },
55+
56+
// Initialization
57+
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
58+
5459
{ MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) },
5560
{ MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) },
5661
{ MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) },
62+
{ MP_ROM_QSTR(MP_QSTR_Packet), MP_ROM_PTR(&wifi_packet_type) },
5763

5864
// Properties
5965
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
60-
61-
// Initialization
62-
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) },
63-
6466
};
6567

6668
STATIC MP_DEFINE_CONST_DICT(wifi_module_globals, wifi_module_globals_table);

0 commit comments

Comments
 (0)