|
| 1 | +/* |
| 2 | + * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2018 Artur Pacholec |
| 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 "shared-bindings/bleio/AddressType.h" |
| 28 | + |
| 29 | +//| .. currentmodule:: bleio |
| 30 | +//| |
| 31 | +//| :class:`AddressType` -- defines the type of a BLE address |
| 32 | +//| ============================================================= |
| 33 | +//| |
| 34 | +//| .. class:: bleio.AddressType |
| 35 | +//| |
| 36 | +//| Enum-like class to define the type of a BLE address. |
| 37 | +//| |
| 38 | +//| .. data:: PUBLIC |
| 39 | +//| |
| 40 | +//| The address is public |
| 41 | +//| |
| 42 | +//| .. data:: RANDOM_STATIC |
| 43 | +//| |
| 44 | +//| The address is random static |
| 45 | +//| |
| 46 | +//| .. data:: RANDOM_PRIVATE_RESOLVABLE |
| 47 | +//| |
| 48 | +//| The address is random private resolvable |
| 49 | +//| |
| 50 | +//| .. data:: RANDOM_PRIVATE_NON_RESOLVABLE |
| 51 | +//| |
| 52 | +//| The address is private non-resolvable |
| 53 | +//| |
| 54 | +const mp_obj_type_t bleio_addresstype_type; |
| 55 | + |
| 56 | +const bleio_addresstype_obj_t bleio_addresstype_public_obj = { |
| 57 | + { &bleio_addresstype_type }, |
| 58 | +}; |
| 59 | + |
| 60 | +const bleio_addresstype_obj_t bleio_addresstype_random_static_obj = { |
| 61 | + { &bleio_addresstype_type }, |
| 62 | +}; |
| 63 | + |
| 64 | +const bleio_addresstype_obj_t bleio_addresstype_random_private_resolvable_obj = { |
| 65 | + { &bleio_addresstype_type }, |
| 66 | +}; |
| 67 | + |
| 68 | +const bleio_addresstype_obj_t bleio_addresstype_random_private_non_resolvable_obj = { |
| 69 | + { &bleio_addresstype_type }, |
| 70 | +}; |
| 71 | + |
| 72 | +STATIC const mp_rom_map_elem_t bleio_addresstype_locals_dict_table[] = { |
| 73 | + { MP_ROM_QSTR(MP_QSTR_PUBLIC), MP_ROM_PTR(&bleio_addresstype_public_obj) }, |
| 74 | + { MP_ROM_QSTR(MP_QSTR_RANDOM_STATIC), MP_ROM_PTR(&bleio_addresstype_random_static_obj) }, |
| 75 | + { MP_ROM_QSTR(MP_QSTR_RANDOM_PRIVATE_RESOLVABLE), MP_ROM_PTR(&bleio_addresstype_random_private_resolvable_obj) }, |
| 76 | + { MP_ROM_QSTR(MP_QSTR_RANDOM_PRIVATE_NON_RESOLVABLE), MP_ROM_PTR(&bleio_addresstype_random_private_non_resolvable_obj) }, |
| 77 | +}; |
| 78 | +STATIC MP_DEFINE_CONST_DICT(bleio_addresstype_locals_dict, bleio_addresstype_locals_dict_table); |
| 79 | + |
| 80 | +STATIC void bleio_addresstype_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { |
| 81 | + qstr type = MP_QSTR_PUBLIC; |
| 82 | + |
| 83 | + if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&bleio_addresstype_random_static_obj)) { |
| 84 | + type = MP_QSTR_RANDOM_STATIC; |
| 85 | + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&bleio_addresstype_random_private_resolvable_obj)) { |
| 86 | + type = MP_QSTR_RANDOM_PRIVATE_RESOLVABLE; |
| 87 | + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&bleio_addresstype_random_private_non_resolvable_obj)) { |
| 88 | + type = MP_QSTR_RANDOM_PRIVATE_NON_RESOLVABLE; |
| 89 | + } |
| 90 | + |
| 91 | + mp_printf(print, "%q.%q.%q", MP_QSTR_bleio, MP_QSTR_AddressType, type); |
| 92 | +} |
| 93 | + |
| 94 | +const mp_obj_type_t bleio_addresstype_type = { |
| 95 | + { &mp_type_type }, |
| 96 | + .name = MP_QSTR_AddressType, |
| 97 | + .print = bleio_addresstype_print, |
| 98 | + .locals_dict = (mp_obj_t)&bleio_addresstype_locals_dict, |
| 99 | +}; |
0 commit comments