summaryrefslogtreecommitdiff
path: root/shared-module/bleio
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module/bleio')
-rw-r--r--shared-module/bleio/Address.c (renamed from shared-module/bleio/Scanner.h)26
-rw-r--r--shared-module/bleio/Address.h9
-rw-r--r--shared-module/bleio/AdvertisementData.h85
-rw-r--r--shared-module/bleio/Characteristic.h3
-rw-r--r--shared-module/bleio/ScanEntry.c (renamed from shared-module/bleio/Device.h)30
-rw-r--r--shared-module/bleio/ScanEntry.h6
-rw-r--r--shared-module/bleio/Service.h44
7 files changed, 41 insertions, 162 deletions
diff --git a/shared-module/bleio/Scanner.h b/shared-module/bleio/Address.c
index 76f5e5866..6bc458b7c 100644
--- a/shared-module/bleio/Scanner.h
+++ b/shared-module/bleio/Address.c
@@ -3,6 +3,7 @@
*
* 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
@@ -24,16 +25,21 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
-#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
+#include <string.h>
-#include "py/obj.h"
+#include "py/objstr.h"
+#include "shared-bindings/bleio/Address.h"
+#include "shared-module/bleio/Address.h"
-typedef struct {
- mp_obj_base_t base;
- mp_obj_t adv_reports;
- uint16_t interval;
- uint16_t window;
-} bleio_scanner_obj_t;
+void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type) {
+ self->bytes = mp_obj_new_bytes(bytes, NUM_BLEIO_ADDRESS_BYTES);
+ self->type = address_type;
+}
-#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
+mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) {
+ return self->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 f0998c163..39789842f 100644
--- a/shared-module/bleio/Address.h
+++ b/shared-module/bleio/Address.h
@@ -3,6 +3,7 @@
*
* 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
@@ -27,14 +28,14 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
-#include "shared-bindings/bleio/AddressType.h"
+#include "py/obj.h"
-#define BLEIO_ADDRESS_BYTES 6
+#define NUM_BLEIO_ADDRESS_BYTES 6
typedef struct {
mp_obj_base_t base;
- bleio_address_type_t type;
- uint8_t value[BLEIO_ADDRESS_BYTES];
+ uint8_t type;
+ mp_obj_t bytes; // a bytes() object
} bleio_address_obj_t;
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h
deleted file mode 100644
index 738d53b23..000000000
--- a/shared-module/bleio/AdvertisementData.h
+++ /dev/null
@@ -1,85 +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_ADVERTISEMENTDATA_H
-#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
-
-#include "py/obj.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,
-};
-
-typedef struct {
- mp_obj_t device_name;
- mp_obj_t services;
- mp_obj_t data;
- bool connectable;
-} bleio_advertisement_data_t;
-
-#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h
index 958837e64..27b43588f 100644
--- a/shared-module/bleio/Characteristic.h
+++ b/shared-module/bleio/Characteristic.h
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2018 Artur Pacholec
+ * Copyright (c) 2019 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,5 +37,4 @@ typedef struct {
bool indicate : 1;
} bleio_characteristic_properties_t;
-
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
diff --git a/shared-module/bleio/Device.h b/shared-module/bleio/ScanEntry.c
index 8d9ece5ef..306ac33c5 100644
--- a/shared-module/bleio/Device.h
+++ b/shared-module/bleio/ScanEntry.c
@@ -3,7 +3,9 @@
*
* 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
@@ -24,22 +26,20 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H
-#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H
-
-#include <stdbool.h>
+#include <string.h>
+#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) {
+ return MP_OBJ_FROM_PTR(self->address);
+}
-typedef struct {
- mp_obj_base_t base;
- bool is_peripheral;
- mp_obj_t name;
- bleio_address_obj_t address;
- volatile uint16_t conn_handle;
- mp_obj_t service_list;
- mp_obj_t notif_handler;
- mp_obj_t conn_handler;
-} bleio_device_obj_t;
+mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self) {
+ return self->data;
+}
-#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H
+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 2f01669e2..b302460e6 100644
--- a/shared-module/bleio/ScanEntry.h
+++ b/shared-module/bleio/ScanEntry.h
@@ -3,6 +3,7 @@
*
* 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
@@ -27,13 +28,14 @@
#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;
- bleio_address_obj_t address;
bool connectable;
int8_t rssi;
+ bleio_address_obj_t *address;
mp_obj_t data;
} bleio_scanentry_obj_t;
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