From 35b919185747c42e183ccfc41f99fd370acca450 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 18 Jun 2019 23:46:20 -0400 Subject: Don't operate directly on bleio objects in shared-bindings: use common_hal routines instead. Changes made but not yet tested. --- shared-module/bleio/Address.c | 45 +++++++++++++++++++++++++++++++++ shared-module/bleio/Address.h | 2 ++ shared-module/bleio/Characteristic.h | 1 + shared-module/bleio/ScanEntry.c | 49 ++++++++++++++++++++++++++++++++++++ shared-module/bleio/ScanEntry.h | 3 ++- shared-module/bleio/Scanner.h | 39 ---------------------------- shared-module/bleio/Service.h | 44 -------------------------------- 7 files changed, 99 insertions(+), 84 deletions(-) create mode 100644 shared-module/bleio/Address.c create mode 100644 shared-module/bleio/ScanEntry.c delete mode 100644 shared-module/bleio/Scanner.h delete mode 100644 shared-module/bleio/Service.h (limited to 'shared-module') diff --git a/shared-module/bleio/Address.c b/shared-module/bleio/Address.c new file mode 100644 index 000000000..e26bbe2ac --- /dev/null +++ b/shared-module/bleio/Address.c @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * 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 + +#include "py/objproperty.h" +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" + +void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) { + memcpy(self->bytes, bytes, bytes_length); + self->type = address_type; +} + +mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) { + return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); +} + +uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) { + return self->type; +} diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index 65f493c16..f66e97d64 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -27,6 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H +#include "py/obj.h" + #define NUM_BLEIO_ADDRESS_BYTES 6 typedef struct { diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h index 958837e64..3132fd47b 100644 --- a/shared-module/bleio/Characteristic.h +++ b/shared-module/bleio/Characteristic.h @@ -37,5 +37,6 @@ typedef struct { bool indicate : 1; } bleio_characteristic_properties_t; +// bleio_characteristic_obj_t is defined in ports/*/common-hal. #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H diff --git a/shared-module/bleio/ScanEntry.c b/shared-module/bleio/ScanEntry.c new file mode 100644 index 000000000..44b50a4ce --- /dev/null +++ b/shared-module/bleio/ScanEntry.c @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * 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 + +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" +#include "shared-module/bleio/ScanEntry.h" + +mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { + bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + address->type = self->address.type; + return MP_OBJ_TO_PTR(address); +} + +mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) { + return self->data; +} + +mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self) { + return self->rssi; +} diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 6ae7334a8..40e02f9fa 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -27,7 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H -#include "shared-module/bleio/Address.h" +#include "py/obj.h" +#include "shared-bindings/bleio/Address.h" typedef struct { mp_obj_base_t base; diff --git a/shared-module/bleio/Scanner.h b/shared-module/bleio/Scanner.h deleted file mode 100644 index 76f5e5866..000000000 --- a/shared-module/bleio/Scanner.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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_MODULE_BLEIO_SCANNER_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H - -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; - mp_obj_t adv_reports; - uint16_t interval; - uint16_t window; -} bleio_scanner_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H diff --git a/shared-module/bleio/Service.h b/shared-module/bleio/Service.h deleted file mode 100644 index 828d4cdc8..000000000 --- a/shared-module/bleio/Service.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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_MODULE_BLEIO_SERVICE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H - -#include "common-hal/bleio/UUID.h" - -typedef struct { - mp_obj_base_t base; - uint16_t handle; - bool is_secondary; - bleio_uuid_obj_t *uuid; - // May be a Peripheral, Central, etc. - mp_obj_t *device; - mp_obj_t char_list; - uint16_t start_handle; - uint16_t end_handle; -} bleio_service_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H -- cgit v1.2.3