bleio: Move ScanEntry to shared module and add a new AdvertisementData class

This commit is contained in:
arturo182 2018-07-17 17:00:37 +02:00
parent 345334aaf1
commit 7390dc7dab
14 changed files with 592 additions and 229 deletions

View File

@ -135,7 +135,6 @@ DRIVERS_SRC_C += $(addprefix modules/,\
ubluepy/ubluepy_delegate.c \ ubluepy/ubluepy_delegate.c \
ubluepy/ubluepy_constants.c \ ubluepy/ubluepy_constants.c \
ubluepy/ubluepy_scanner.c \ ubluepy/ubluepy_scanner.c \
ubluepy/ubluepy_scan_entry.c \
) )
SRC_COMMON_HAL += \ SRC_COMMON_HAL += \
@ -187,6 +186,8 @@ ifneq ($(SD), )
SRC_BINDINGS_ENUMS += \ SRC_BINDINGS_ENUMS += \
bleio/Address.c \ bleio/Address.c \
bleio/AddressType.c \ bleio/AddressType.c \
bleio/AdvertisementData.c \
bleio/ScanEntry.c \
bleio/UUIDType.c bleio/UUIDType.c
endif endif

View File

@ -785,6 +785,18 @@ void ble_drv_scan_start(void) {
} }
} }
void ble_drv_scan_continue(void) {
SD_TEST_OR_ENABLE();
#if (BLUETOOTH_SD == 140)
uint32_t err_code;
if ((err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer)) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not continue scanning. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
#endif
}
void ble_drv_scan_stop(void) { void ble_drv_scan_stop(void) {
sd_ble_gap_scan_stop(); sd_ble_gap_scan_stop();
} }

View File

@ -108,6 +108,8 @@ void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, u
void ble_drv_scan_start(void); void ble_drv_scan_start(void);
void ble_drv_scan_continue(void);
void ble_drv_scan_stop(void); void ble_drv_scan_stop(void);
void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler); void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler);

View File

@ -34,7 +34,6 @@ extern const mp_obj_type_t ubluepy_characteristic_type;
extern const mp_obj_type_t ubluepy_delegate_type; extern const mp_obj_type_t ubluepy_delegate_type;
extern const mp_obj_type_t ubluepy_constants_type; extern const mp_obj_type_t ubluepy_constants_type;
extern const mp_obj_type_t ubluepy_scanner_type; extern const mp_obj_type_t ubluepy_scanner_type;
extern const mp_obj_type_t ubluepy_scan_entry_type;
STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = { STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluepy) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluepy) },
@ -46,7 +45,6 @@ STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
#endif #endif
#if MICROPY_PY_UBLUEPY_CENTRAL #if MICROPY_PY_UBLUEPY_CENTRAL
{ MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&ubluepy_scanner_type) }, { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&ubluepy_scanner_type) },
{ MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&ubluepy_scan_entry_type) },
#endif #endif
{ MP_ROM_QSTR(MP_QSTR_DefaultDelegate), MP_ROM_PTR(&ubluepy_delegate_type) }, { MP_ROM_QSTR(MP_QSTR_DefaultDelegate), MP_ROM_PTR(&ubluepy_delegate_type) },
{ MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&ubluepy_service_type) }, { MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&ubluepy_service_type) },

View File

@ -78,7 +78,6 @@ extern const mp_obj_type_t ubluepy_service_type;
extern const mp_obj_type_t ubluepy_characteristic_type; extern const mp_obj_type_t ubluepy_characteristic_type;
extern const mp_obj_type_t ubluepy_peripheral_type; extern const mp_obj_type_t ubluepy_peripheral_type;
extern const mp_obj_type_t ubluepy_scanner_type; extern const mp_obj_type_t ubluepy_scanner_type;
extern const mp_obj_type_t ubluepy_scan_entry_type;
extern const mp_obj_type_t ubluepy_constants_type; extern const mp_obj_type_t ubluepy_constants_type;
extern const mp_obj_type_t ubluepy_constants_ad_types_type; extern const mp_obj_type_t ubluepy_constants_ad_types_type;
@ -153,15 +152,6 @@ typedef struct _ubluepy_scanner_obj_t {
mp_obj_t adv_reports; mp_obj_t adv_reports;
} ubluepy_scanner_obj_t; } ubluepy_scanner_obj_t;
typedef struct _ubluepy_scan_entry_obj_t {
mp_obj_base_t base;
mp_obj_t addr;
uint8_t addr_type;
bool connectable;
int8_t rssi;
mp_obj_t data;
} ubluepy_scan_entry_obj_t;
typedef enum _ubluepy_prop_t { typedef enum _ubluepy_prop_t {
UBLUEPY_PROP_BROADCAST = 0x01, UBLUEPY_PROP_BROADCAST = 0x01,
UBLUEPY_PROP_READ = 0x02, UBLUEPY_PROP_READ = 0x02,

View File

@ -31,58 +31,11 @@
#include "modubluepy.h" #include "modubluepy.h"
STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = {
// GAP AD Types
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_FLAGS), MP_ROM_INT(0x01) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE), MP_ROM_INT(0x02) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE), MP_ROM_INT(0x03) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_32BIT_SERVICE_UUID_MORE_AVAILABLE), MP_ROM_INT(0x04) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_32BIT_SERVICE_UUID_COMPLETE), MP_ROM_INT(0x05) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE), MP_ROM_INT(0x06) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE), MP_ROM_INT(0x07) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SHORT_LOCAL_NAME), MP_ROM_INT(0x08) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_COMPLETE_LOCAL_NAME), MP_ROM_INT(0x09) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_TX_POWER_LEVEL), MP_ROM_INT(0x0A) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_CLASS_OF_DEVICE), MP_ROM_INT(0x0D) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SIMPLE_PAIRING_HASH_C), MP_ROM_INT(0x0E) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R), MP_ROM_INT(0x0F) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SECURITY_MANAGER_TK_VALUE), MP_ROM_INT(0x10) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SECURITY_MANAGER_OOB_FLAGS), MP_ROM_INT(0x11) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE), MP_ROM_INT(0x12) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT), MP_ROM_INT(0x14) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT), MP_ROM_INT(0x15) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SERVICE_DATA), MP_ROM_INT(0x16) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_PUBLIC_TARGET_ADDRESS), MP_ROM_INT(0x17) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_RANDOM_TARGET_ADDRESS), MP_ROM_INT(0x18) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_APPEARANCE), MP_ROM_INT(0x19) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_ADVERTISING_INTERVAL), MP_ROM_INT(0x1A) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_LE_BLUETOOTH_DEVICE_ADDRESS), MP_ROM_INT(0x1B) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_LE_ROLE), MP_ROM_INT(0x1C) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SIMPLE_PAIRING_HASH_C256), MP_ROM_INT(0x1D) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SIMPLE_PAIRING_RANDOMIZER_R256), MP_ROM_INT(0x1E) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SERVICE_DATA_32BIT_UUID), MP_ROM_INT(0x20) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_SERVICE_DATA_128BIT_UUID), MP_ROM_INT(0x21) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_URI), MP_ROM_INT(0x24) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_3D_INFORMATION_DATA), MP_ROM_INT(0x3D) },
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(0xFF) },
};
STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table);
const mp_obj_type_t ubluepy_constants_ad_types_type = {
{ &mp_type_type },
.name = MP_QSTR_ad_types,
.locals_dict = (mp_obj_dict_t*)&ubluepy_constants_ad_types_locals_dict
};
STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = {
// GAP events // GAP events
{ MP_ROM_QSTR(MP_QSTR_EVT_GAP_CONNECTED), MP_ROM_INT(16) }, { MP_ROM_QSTR(MP_QSTR_EVT_GAP_CONNECTED), MP_ROM_INT(16) },
{ MP_ROM_QSTR(MP_QSTR_EVT_GAP_DISCONNECTED), MP_ROM_INT(17) }, { MP_ROM_QSTR(MP_QSTR_EVT_GAP_DISCONNECTED), MP_ROM_INT(17) },
{ MP_ROM_QSTR(MP_QSTR_EVT_GATTS_WRITE), MP_ROM_INT(80) }, { MP_ROM_QSTR(MP_QSTR_EVT_GATTS_WRITE), MP_ROM_INT(80) },
{ MP_ROM_QSTR(MP_QSTR_UUID_CCCD), MP_ROM_INT(0x2902) },
{ MP_ROM_QSTR(MP_QSTR_ad_types), MP_ROM_PTR(&ubluepy_constants_ad_types_type) },
}; };
STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table);

View File

@ -1,146 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Glenn Ruben Bakke
*
* 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 <string.h>
#include "py/obj.h"
#include "py/runtime.h"
#include "py/objstr.h"
#include "py/objlist.h"
#include "py/objarray.h"
#include "py/objtuple.h"
#include "py/qstr.h"
#if MICROPY_PY_UBLUEPY_CENTRAL
#include "ble_drv.h"
STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
ubluepy_scan_entry_obj_t * self = (ubluepy_scan_entry_obj_t *)o;
(void)self;
mp_printf(print, "ScanEntry");
}
/// \method addr()
/// Return address as text string.
///
STATIC mp_obj_t scan_entry_get_addr(mp_obj_t self_in) {
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
return self->addr;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_obj, scan_entry_get_addr);
/// \method addr_type()
/// Return address type value.
///
STATIC mp_obj_t scan_entry_get_addr_type(mp_obj_t self_in) {
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(self->addr_type);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_type_obj, scan_entry_get_addr_type);
/// \method rssi()
/// Return RSSI value.
///
STATIC mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) {
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(self->rssi);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi);
/// \method getScanData()
/// Return list of the scan data tupples (ad_type, description, value)
///
STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) {
ubluepy_scan_entry_obj_t * self = MP_OBJ_TO_PTR(self_in);
mp_obj_t retval_list = mp_obj_new_list(0, NULL);
// TODO: check if self->data is set
mp_obj_array_t * data = MP_OBJ_TO_PTR(self->data);
uint16_t byte_index = 0;
while (byte_index < data->len) {
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
uint8_t adv_item_len = ((uint8_t * )data->items)[byte_index];
uint8_t adv_item_type = ((uint8_t * )data->items)[byte_index + 1];
mp_obj_t description = mp_const_none;
mp_map_t *constant_map = mp_obj_dict_get_map(ubluepy_constants_ad_types_type.locals_dict);
mp_map_elem_t *ad_types_table = MP_OBJ_TO_PTR(constant_map->table);
uint16_t num_of_elements = constant_map->used;
for (uint16_t i = 0; i < num_of_elements; i++) {
mp_map_elem_t element = (mp_map_elem_t)*ad_types_table;
ad_types_table++;
uint16_t element_value = mp_obj_get_int(element.value);
if (adv_item_type == element_value) {
qstr key_qstr = MP_OBJ_QSTR_VALUE(element.key);
const char * text = qstr_str(key_qstr);
size_t len = qstr_len(key_qstr);
vstr_t vstr;
vstr_init(&vstr, len);
vstr_printf(&vstr, "%s", text);
description = mp_obj_new_str(vstr.buf, vstr.len);
vstr_clear(&vstr);
}
}
t->items[0] = MP_OBJ_NEW_SMALL_INT(adv_item_type);
t->items[1] = description;
t->items[2] = mp_obj_new_bytearray(adv_item_len - 1,
&((uint8_t * )data->items)[byte_index + 2]);
mp_obj_list_append(retval_list, MP_OBJ_FROM_PTR(t));
byte_index += adv_item_len + 1;
}
return retval_list;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_scan_entry_get_scan_data_obj, scan_entry_get_scan_data);
STATIC const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_addr), MP_ROM_PTR(&bluepy_scan_entry_get_addr_obj) },
{ MP_ROM_QSTR(MP_QSTR_addr_type), MP_ROM_PTR(&bluepy_scan_entry_get_addr_type_obj) },
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bluepy_scan_entry_get_rssi_obj) },
{ MP_ROM_QSTR(MP_QSTR_getScanData), MP_ROM_PTR(&ubluepy_scan_entry_get_scan_data_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table);
const mp_obj_type_t ubluepy_scan_entry_type = {
{ &mp_type_type },
.name = MP_QSTR_ScanEntry,
.print = ubluepy_scan_entry_print,
.locals_dict = (mp_obj_dict_t*)&ubluepy_scan_entry_locals_dict
};
#endif // MICROPY_PY_UBLUEPY_CENTRAL

View File

@ -33,31 +33,25 @@
#if MICROPY_PY_UBLUEPY_CENTRAL #if MICROPY_PY_UBLUEPY_CENTRAL
#include "shared-bindings/bleio/ScanEntry.h"
#include "ble_drv.h" #include "ble_drv.h"
STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) { STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) {
ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in);
ubluepy_scan_entry_obj_t * item = m_new_obj(ubluepy_scan_entry_obj_t); // TODO: Don't add new entry for each item, group by address and update
item->base.type = &ubluepy_scan_entry_type; bleio_scanentry_obj_t *item = m_new_obj(bleio_scanentry_obj_t);
item->base.type = &bleio_scanentry_type;
vstr_t vstr;
vstr_init(&vstr, 17);
vstr_printf(&vstr, ""HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
data->p_peer_addr[5], data->p_peer_addr[4], data->p_peer_addr[3],
data->p_peer_addr[2], data->p_peer_addr[1], data->p_peer_addr[0]);
item->addr = mp_obj_new_str(vstr.buf, vstr.len);
vstr_clear(&vstr);
item->addr_type = data->addr_type;
item->rssi = data->rssi; item->rssi = data->rssi;
item->data = mp_obj_new_bytearray(data->data_len, data->p_data); item->data = mp_obj_new_bytearray(data->data_len, data->p_data);
item->address.type = data->addr_type;
memcpy(item->address.value, data->p_peer_addr, BLEIO_ADDRESS_BYTES);
mp_obj_list_append(self->adv_reports, item); mp_obj_list_append(self->adv_reports, item);
ble_drv_scan_continue();
} }
STATIC void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { STATIC void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {

View File

@ -0,0 +1,92 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Artur Pacholec
*
* 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/obj.h"
#include "shared-module/bleio/AdvertisementData.h"
//| .. currentmodule:: bleio
//|
//| :class:`AdvertisementData` -- data used during BLE advertising
//| ==============================================================
//|
//| Represents the data to be broadcast during BLE advertising.
//|
// TODO: Implement constructor and methods
STATIC const mp_rom_map_elem_t bleio_advertisementdata_locals_dict_table[] = {
// Static variables
{ MP_ROM_QSTR(MP_QSTR_FLAGS), MP_ROM_INT(AdFlags) },
{ MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf16BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf16BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf32BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf32BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf128BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf128BitServiceClassUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_SHORTENED_LOCAL_NAME), MP_ROM_INT(AdShortenedLocalName) },
{ MP_ROM_QSTR(MP_QSTR_COMPLETE_LOCAL_NAME), MP_ROM_INT(AdCompleteLocalName) },
{ MP_ROM_QSTR(MP_QSTR_TX_POWER_LEVEL), MP_ROM_INT(AdTxPowerLevel) },
{ MP_ROM_QSTR(MP_QSTR_CLASS_OF_DEVICE), MP_ROM_INT(AdClassOfDevice) },
{ MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C), MP_ROM_INT(AdSimplePairingHashC) },
{ MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R), MP_ROM_INT(AdSimplePairingRandomizerR) },
{ MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_TK_VALUE), MP_ROM_INT(AdSecurityManagerTKValue) },
{ MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_OOB_FLAGS), MP_ROM_INT(AdSecurityManagerOOBFlags) },
{ MP_ROM_QSTR(MP_QSTR_SLAVE_CONNECTION_INTERVAL_RANGE), MP_ROM_INT(AdSlaveConnectionIntervalRange) },
{ MP_ROM_QSTR(MP_QSTR_LIST_OF_16BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf16BitServiceSolicitationUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_LIST_OF_128BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf128BitServiceSolicitationUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_SERVICE_DATA), MP_ROM_INT(AdServiceData) },
{ MP_ROM_QSTR(MP_QSTR_PUBLIC_TARGET_ADDRESS), MP_ROM_INT(AdPublicTargetAddress) },
{ MP_ROM_QSTR(MP_QSTR_RANDOM_TARGET_ADDRESS), MP_ROM_INT(AdRandomTargetAddress) },
{ MP_ROM_QSTR(MP_QSTR_APPEARANCE), MP_ROM_INT(AdAppearance) },
{ MP_ROM_QSTR(MP_QSTR_ADVERTISING_INTERNAL), MP_ROM_INT(AdAdvertisingInterval) },
{ MP_ROM_QSTR(MP_QSTR_LE_BLUETOOTH_DEVICE_ADDRESS), MP_ROM_INT(AdLEBluetoothDeviceAddress) },
{ MP_ROM_QSTR(MP_QSTR_LE_ROLE), MP_ROM_INT(AdLERole) },
{ MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C256), MP_ROM_INT(AdSimplePairingHashC256) },
{ MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R256), MP_ROM_INT(AdSimplePairingRandomizerR256) },
{ MP_ROM_QSTR(MP_QSTR_LIST_OF_32BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf32BitServiceSolicitationUUIDs) },
{ MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_32BIT_UUID), MP_ROM_INT(AdServiceData32BitUUID) },
{ MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_128BIT_UUID), MP_ROM_INT(AdServiceData128BitUUID) },
{ MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE), MP_ROM_INT(AdLESecureConnectionsConfirmationValue) },
{ MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_RANDOM_VALUE), MP_ROM_INT(AdLESecureConnectionsRandomValue) },
{ MP_ROM_QSTR(MP_QSTR_URI), MP_ROM_INT(AdURI) },
{ MP_ROM_QSTR(MP_QSTR_INDOOR_POSITIONING), MP_ROM_INT(AdIndoorPositioning) },
{ MP_ROM_QSTR(MP_QSTR_TRANSPORT_DISCOVERY_DATA), MP_ROM_INT(AdTransportDiscoveryData) },
{ MP_ROM_QSTR(MP_QSTR_LE_SUPPORTED_FEATURES), MP_ROM_INT(AdLESupportedFeatures) },
{ MP_ROM_QSTR(MP_QSTR_CHANNEL_MAP_UPDATE_INDICATION), MP_ROM_INT(AdChannelMapUpdateIndication) },
{ MP_ROM_QSTR(MP_QSTR_PB_ADV), MP_ROM_INT(AdPBADV) },
{ MP_ROM_QSTR(MP_QSTR_MESH_MESSAGE), MP_ROM_INT(AdMeshMessage) },
{ MP_ROM_QSTR(MP_QSTR_MESH_BEACON), MP_ROM_INT(AdMeshBeacon) },
{ MP_ROM_QSTR(MP_QSTR_3D_INFORMATION_DATA), MP_ROM_INT(Ad3DInformationData) },
{ MP_ROM_QSTR(MP_QSTR_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(AdManufacturerSpecificData) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_advertisementdata_locals_dict, bleio_advertisementdata_locals_dict_table);
const mp_obj_type_t bleio_advertisementdata_type = {
{ &mp_type_type },
.name = MP_QSTR_AdvertisementData,
.locals_dict = (mp_obj_dict_t*)&bleio_advertisementdata_locals_dict
};

View File

@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Artur Pacholec
*
* 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_BLEIO_ADVERTISEMENTDATA_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H
#include "py/obj.h"
extern const mp_obj_type_t bleio_advertisementdata_type;
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H

View File

@ -0,0 +1,307 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2017 Glenn Ruben Bakke
*
* 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 <string.h>
#include "py/objarray.h"
#include "py/objproperty.h"
#include "py/objstr.h"
#include "py/objtuple.h"
#include "shared-bindings/bleio/Address.h"
#include "shared-module/bleio/AdvertisementData.h"
#include "shared-bindings/bleio/UUID.h"
#include "shared-bindings/bleio/ScanEntry.h"
//| .. currentmodule:: bleio
//|
//| :class:`ScanEntry` -- BLE scan response entry
//| =========================================================
//|
//| Encapsulates information about a device that was received as a
//| response to a BLE scan request.
//|
//| .. attribute:: address
//|
//| The address of the device. (read-only)
//| This attribute is of type `bleio:Address`.
//|
//| .. attribute:: manufacturer_specific_data
//|
//| The manufacturer-specific data present in the advertisement packet. (read-only)
//|
//| .. attribute:: name
//|
//| The name of the device. (read-only)
//| This attribute might be `None` if the data was missing from the advertisement packet.
//|
//| .. attribute:: raw_data
//|
//| All the advertisement data present in the packet. (read-only)
//|
//| .. attribute:: rssi
//|
//| The signal strength of the device at the time of the scan. (read-only)
//|
//| .. attribute:: service_uuids
//|
//| The address of the device. (read-only)
//| This attribute is a list of `bleio:UUID`.
//| This attribute might be empty or incomplete, depending on the advertisement packet.
//| Currently only 16-bit UUIDS are listed.
//|
//| .. attribute:: tx_power_level
//|
//| The transmit power level of the device. (read-only)
//| This attribute might be `None` if the data was missing from the advertisement packet.
//|
static uint8_t find_data_item(mp_obj_array_t *data_in, uint8_t type, uint8_t **data_out) {
uint16_t i = 0;
while (i < data_in->len) {
const uint8_t item_len = ((uint8_t*)data_in->items)[i];
const uint8_t item_type = ((uint8_t*)data_in->items)[i + 1];
if (item_type != type) {
i += (item_len + 1);
continue;
}
*data_out = &((uint8_t*)data_in->items)[i + 2];
return item_len;
}
return 0;
}
STATIC mp_obj_t scanentry_get_name(mp_obj_t self_in);
STATIC void bleio_scanentry_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
bleio_scanentry_obj_t *self = (bleio_scanentry_obj_t *)self_in;
mp_printf(print, "ScanEntry(address: "HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
self->address.value[5], self->address.value[4], self->address.value[3],
self->address.value[1], self->address.value[1], self->address.value[0]);
const mp_obj_t name_obj = scanentry_get_name(self_in);
if (name_obj != mp_const_none) {
mp_obj_str_t *str = MP_OBJ_TO_PTR(name_obj);
mp_printf(print, " name: %s", str->data);
}
mp_print_str(print, ")");
}
STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t obj = bleio_address_type.make_new(&bleio_address_type, 1, 0, (mp_obj_t)&mp_const_none_obj);
bleio_address_obj_t *address = MP_OBJ_TO_PTR(obj);
address->type = self->address.type;
memcpy(address->value, self->address.value, BLEIO_ADDRESS_BYTES);
return obj;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_address_obj, bleio_scanentry_get_address);
const mp_obj_property_t bleio_scanentry_address_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&bluepy_scanentry_get_address_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_manufacturer_specific_data(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_array_t *data = MP_OBJ_TO_PTR(self->data);
uint8_t *manuf_data;
const uint8_t manuf_data_len = find_data_item(data, AdManufacturerSpecificData, &manuf_data);
if (manuf_data_len == 0) {
return mp_const_none;
}
return mp_obj_new_bytearray_by_ref(manuf_data_len, manuf_data);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(scanentry_get_manufacturer_specific_data_obj, scanentry_get_manufacturer_specific_data);
const mp_obj_property_t bleio_scanentry_manufacturer_specific_data_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&scanentry_get_manufacturer_specific_data_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_name(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_array_t *data = MP_OBJ_TO_PTR(self->data);
uint8_t *name;
// Try for Complete but settle for Shortened
uint8_t name_len = find_data_item(data, AdCompleteLocalName, &name);
if (name_len == 0) {
name_len = find_data_item(data, AdShortenedLocalName, &name);
}
if (name_len == 0) {
return mp_const_none;
}
return mp_obj_new_str((const char*)name, name_len - 1, false);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_name_obj, scanentry_get_name);
const mp_obj_property_t bleio_scanentry_name_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&bluepy_scanentry_get_name_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t entries = mp_obj_new_list(0, NULL);
mp_obj_array_t *data = MP_OBJ_TO_PTR(self->data);
uint16_t i = 0;
while (i < data->len) {
mp_obj_tuple_t *entry = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
const uint8_t item_len = ((uint8_t*)data->items)[i];
const uint8_t item_type = ((uint8_t*)data->items)[i + 1];
entry->items[0] = MP_OBJ_NEW_SMALL_INT(item_type);
entry->items[1] = mp_obj_new_bytearray(item_len - 1, &((uint8_t*)data->items)[i + 2]);
mp_obj_list_append(entries, MP_OBJ_FROM_PTR(entry));
i += (item_len + 1);
}
return entries;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data);
const mp_obj_property_t bleio_scanentry_raw_data_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&bleio_scanentry_get_raw_data_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(self->rssi);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_rssi_obj, scanentry_get_rssi);
const mp_obj_property_t bleio_scanentry_rssi_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&bluepy_scanentry_get_rssi_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_service_uuids(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_array_t *data = MP_OBJ_TO_PTR(self->data);
uint8_t *uuids;
// Try for Complete but settle for Incomplete
uint8_t uuids_len = find_data_item(data, AdCompleteListOf16BitServiceClassUUIDs, &uuids);
if (uuids_len == 0) {
uuids_len = find_data_item(data, AdIncompleteListOf16BitServiceClassUUIDs, &uuids);
}
mp_obj_t entries = mp_obj_new_list(0, NULL);
for (size_t i = 0; i < uuids_len / sizeof(uint16_t); ++i) {
const mp_obj_t uuid_int = mp_obj_new_int(uuids[sizeof(uint16_t) * i] | (uuids[sizeof(uint16_t) * i + 1] << 8));
const mp_obj_t uuid_obj = bleio_uuid_type.make_new(&bleio_uuid_type, 1, 0, &uuid_int);
mp_obj_list_append(entries, uuid_obj);
}
// TODO: 32-bit UUIDs
// TODO: 128-bit UUIDs
return entries;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(scanentry_get_service_uuids_obj, scanentry_get_service_uuids);
const mp_obj_property_t bleio_scanentry_service_uuids_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&scanentry_get_service_uuids_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC mp_obj_t scanentry_get_tx_power_level(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_array_t *data = MP_OBJ_TO_PTR(self->data);
uint8_t *tx_power;
const uint8_t tx_power_len = find_data_item(data, AdTxPowerLevel, &tx_power);
if (tx_power_len == 0) {
return mp_const_none;
}
return mp_obj_new_int((int8_t)(*tx_power));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(scanentry_get_tx_power_level_obj, scanentry_get_tx_power_level);
const mp_obj_property_t bleio_scanentry_tx_power_level_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&scanentry_get_tx_power_level_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
STATIC const mp_rom_map_elem_t bleio_scanentry_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_manufacturer_specific_data), MP_ROM_PTR(&bleio_scanentry_manufacturer_specific_data_obj) },
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&bleio_scanentry_name_obj) },
{ MP_ROM_QSTR(MP_QSTR_raw_data), MP_ROM_PTR(&bleio_scanentry_raw_data_obj) },
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) },
{ MP_ROM_QSTR(MP_QSTR_service_uuids), MP_ROM_PTR(&bleio_scanentry_service_uuids_obj) },
{ MP_ROM_QSTR(MP_QSTR_tx_power_level), MP_ROM_PTR(&bleio_scanentry_tx_power_level_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_scanentry_locals_dict, bleio_scanentry_locals_dict_table);
const mp_obj_type_t bleio_scanentry_type = {
{ &mp_type_type },
.name = MP_QSTR_ScanEntry,
.print = bleio_scanentry_print,
.locals_dict = (mp_obj_dict_t*)&bleio_scanentry_locals_dict
};

View File

@ -0,0 +1,44 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2017 Glenn Ruben Bakke
*
* 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_BLEIO_SCANENTRY_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H
#include "shared-module/bleio/Address.h"
#include "py/objtype.h"
typedef struct {
mp_obj_base_t base;
bleio_address_obj_t address;
bool connectable;
int8_t rssi;
mp_obj_t data;
} bleio_scanentry_obj_t;
extern const mp_obj_type_t bleio_scanentry_type;
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H

View File

@ -29,7 +29,9 @@
#include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/__init__.h"
#include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/Address.h"
#include "shared-bindings/bleio/AddressType.h" #include "shared-bindings/bleio/AddressType.h"
#include "shared-bindings/bleio/AdvertisementData.h"
#include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/Descriptor.h"
#include "shared-bindings/bleio/ScanEntry.h"
#include "shared-bindings/bleio/UUID.h" #include "shared-bindings/bleio/UUID.h"
#include "shared-bindings/bleio/UUIDType.h" #include "shared-bindings/bleio/UUIDType.h"
@ -49,8 +51,10 @@
//| //|
//| Address //| Address
//| AddressType //| AddressType
//| AdvertisementData
//| Adapter //| Adapter
//| Descriptor //| Descriptor
//| ScanEntry
//| UUID //| UUID
//| UUIDType //| UUIDType
//| //|
@ -64,14 +68,16 @@
STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) },
{ MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) },
{ MP_ROM_QSTR(MP_QSTR_AddressType), MP_ROM_PTR(&bleio_addresstype_type) }, { MP_ROM_QSTR(MP_QSTR_AdvertisementData), MP_ROM_PTR(&bleio_advertisementdata_type) },
{ MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) },
{ MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) },
{ MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&bleio_uuid_type) }, { MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&bleio_uuid_type) },
// Properties // Properties
{ MP_ROM_QSTR(MP_QSTR_adapter), MP_ROM_PTR(&common_hal_bleio_adapter_obj) }, { MP_ROM_QSTR(MP_QSTR_adapter), MP_ROM_PTR(&common_hal_bleio_adapter_obj) },
// Enum-like Classes. // Enum-like Classes.
{ MP_ROM_QSTR(MP_QSTR_AddressType), MP_ROM_PTR(&bleio_addresstype_type) },
{ MP_ROM_QSTR(MP_QSTR_UUIDType), MP_ROM_PTR(&bleio_uuidtype_type) }, { MP_ROM_QSTR(MP_QSTR_UUIDType), MP_ROM_PTR(&bleio_uuidtype_type) },
}; };

View File

@ -0,0 +1,76 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Artur Pacholec
*
* 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_ATMEL_SAMD_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
#define MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
// Taken from https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
enum {
AdFlags = 0x01,
AdIncompleteListOf16BitServiceClassUUIDs = 0x02,
AdCompleteListOf16BitServiceClassUUIDs = 0x03,
AdIncompleteListOf32BitServiceClassUUIDs = 0x04,
AdCompleteListOf32BitServiceClassUUIDs = 0x05,
AdIncompleteListOf128BitServiceClassUUIDs = 0x06,
AdCompleteListOf128BitServiceClassUUIDs = 0x07,
AdShortenedLocalName = 0x08,
AdCompleteLocalName = 0x09,
AdTxPowerLevel = 0x0A,
AdClassOfDevice = 0x0D,
AdSimplePairingHashC = 0x0E,
AdSimplePairingRandomizerR = 0x0F,
AdSecurityManagerTKValue = 0x10,
AdSecurityManagerOOBFlags = 0x11,
AdSlaveConnectionIntervalRange = 0x12,
AdListOf16BitServiceSolicitationUUIDs = 0x14,
AdListOf128BitServiceSolicitationUUIDs = 0x15,
AdServiceData = 0x16,
AdPublicTargetAddress = 0x17,
AdRandomTargetAddress = 0x18,
AdAppearance = 0x19,
AdAdvertisingInterval = 0x1A,
AdLEBluetoothDeviceAddress = 0x1B,
AdLERole = 0x1C,
AdSimplePairingHashC256 = 0x1D,
AdSimplePairingRandomizerR256 = 0x1E,
AdListOf32BitServiceSolicitationUUIDs = 0x1F,
AdServiceData32BitUUID = 0x20,
AdServiceData128BitUUID = 0x21,
AdLESecureConnectionsConfirmationValue = 0x22,
AdLESecureConnectionsRandomValue = 0x23,
AdURI = 0x24,
AdIndoorPositioning = 0x25,
AdTransportDiscoveryData = 0x26,
AdLESupportedFeatures = 0x27,
AdChannelMapUpdateIndication = 0x28,
AdPBADV = 0x29,
AdMeshMessage = 0x2A,
AdMeshBeacon = 0x2B,
Ad3DInformationData = 0x3D,
AdManufacturerSpecificData = 0xFF,
};
#endif // MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H