|
24 | 24 | * THE SOFTWARE. |
25 | 25 | */ |
26 | 26 |
|
| 27 | +#include "py/runtime.h" |
| 28 | + |
27 | 29 | #include "shared-bindings/_bleio/Attribute.h" |
28 | 30 | #include "shared-bindings/_bleio/Characteristic.h" |
29 | 31 | #include "shared-bindings/_bleio/Descriptor.h" |
30 | 32 | #include "shared-bindings/_bleio/Service.h" |
31 | 33 |
|
32 | | -// Return the type of the attribute. |
33 | | -ble_attribute_type_uuid bleio_attribute_type_uuid(mp_obj_t *attribute) { |
| 34 | + |
| 35 | +bleio_uuid_obj_t *bleio_attribute_get_uuid(mp_obj_t *attribute) { |
34 | 36 | if (MP_OBJ_IS_TYPE(attribute, &bleio_characteristic_type)) { |
35 | | - return BLE_TYPE_CHARACTERISTIC; |
| 37 | + bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(attribute); |
| 38 | + return characteristic->uuid; |
36 | 39 | } |
37 | 40 | if (MP_OBJ_IS_TYPE(attribute, &bleio_descriptor_type)) { |
38 | | - return BLE_TYPE_DESCRIPTOR; |
| 41 | + bleio_descriptor_obj_t *descriptor = MP_OBJ_TO_PTR(attribute); |
| 42 | + return descriptor->uuid; |
39 | 43 | } |
40 | 44 | if (MP_OBJ_IS_TYPE(attribute, &bleio_service_type)) { |
41 | 45 | bleio_service_obj_t *service = MP_OBJ_TO_PTR(attribute); |
42 | | - return service->is_secondary ? BLE_TYPE_SECONDARY_SERVICE : BLE_TYPE_PRIMARY_SERVICE; |
| 46 | + return service->uuid; |
43 | 47 | } |
44 | | - return BLE_TYPE_UNKNOWN; |
| 48 | + mp_raise_RuntimeError(translate("Invalid BLE attribute")); |
45 | 49 | } |
46 | | - |
47 | | -// Convert a _bleio security mode to a ble_gap_conn_sec_mode_t setting. |
48 | | -// void bleio_attribute_gatts_set_security_mode(ble_gap_conn_sec_mode_t *perm, bleio_attribute_security_mode_t security_mode) { |
49 | | -// switch (security_mode) { |
50 | | -// case SECURITY_MODE_NO_ACCESS: |
51 | | -// BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(perm); |
52 | | -// break; |
53 | | - |
54 | | -// case SECURITY_MODE_OPEN: |
55 | | -// BLE_GAP_CONN_SEC_MODE_SET_OPEN(perm); |
56 | | -// break; |
57 | | - |
58 | | -// case SECURITY_MODE_ENC_NO_MITM: |
59 | | -// BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(perm); |
60 | | -// break; |
61 | | - |
62 | | -// case SECURITY_MODE_ENC_WITH_MITM: |
63 | | -// BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(perm); |
64 | | -// break; |
65 | | - |
66 | | -// case SECURITY_MODE_LESC_ENC_WITH_MITM: |
67 | | -// BLE_GAP_CONN_SEC_MODE_SET_LESC_ENC_WITH_MITM(perm); |
68 | | -// break; |
69 | | - |
70 | | -// case SECURITY_MODE_SIGNED_NO_MITM: |
71 | | -// BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(perm); |
72 | | -// break; |
73 | | - |
74 | | -// case SECURITY_MODE_SIGNED_WITH_MITM: |
75 | | -// BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(perm); |
76 | | -// break; |
77 | | -// } |
78 | | -// } |
0 commit comments