summaryrefslogtreecommitdiff
path: root/shared-bindings/bleio/Descriptor.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-08-02 17:56:44 -0400
committerDan Halbert <halbert@halwitz.org>2019-08-02 17:57:31 -0400
commit7ce3776b8086abbe0d01056651904a59bf4f8bec (patch)
treed00f8bb26f27b9d52f847b146b3c7af68460d4fb /shared-bindings/bleio/Descriptor.c
parentee518b9141a4218b4f5f461d1e72621b6be5da81 (diff)
WIP: rework of Characteristic properties; enhance Descriptor; not tested
Diffstat (limited to 'shared-bindings/bleio/Descriptor.c')
-rw-r--r--shared-bindings/bleio/Descriptor.c90
1 files changed, 15 insertions, 75 deletions
diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c
index f2e5aa01d..b709f3aa7 100644
--- a/shared-bindings/bleio/Descriptor.c
+++ b/shared-bindings/bleio/Descriptor.c
@@ -28,6 +28,7 @@
#include "py/objproperty.h"
#include "py/runtime.h"
+#include "shared-bindings/bleio/Attribute.h"
#include "shared-bindings/bleio/Descriptor.h"
#include "shared-bindings/bleio/UUID.h"
@@ -41,23 +42,15 @@
//| information about the characteristic.
//|
-//| .. class:: Descriptor(uuid)
+//| .. class:: Descriptor(uuid, security_mode=`Attribute.OPEN`)
//|
-//| Create a new descriptor object with the UUID uuid.
+//| Create a new descriptor object with the UUID uuid and the given value, if any.
-//| .. attribute:: handle
-//|
-//| The descriptor handle. (read-only)
-//|
-
-//| .. attribute:: uuid
-//|
-//| The descriptor uuid. (read-only)
-//|
STATIC mp_obj_t bleio_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_uuid };
+ enum { ARG_uuid, ARG_security_mode };
static const mp_arg_t allowed_args[] = {
- { MP_QSTR_uuid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
+ { MP_QSTR_uuid, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_security_mode, MP_ARG_KW_ONLY| MP_ARG_INT, {.u_int = SEC_MODE_OPEN } },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -69,28 +62,22 @@ STATIC mp_obj_t bleio_descriptor_make_new(const mp_obj_type_t *type, size_t n_ar
mp_raise_ValueError(translate("Expected a UUID"));
}
+ const bleio_attribute_security_mode_t security_mode = args[ARG_security_mode].u_int;
+ common_hal_bleio_attribute_security_mode_check_valid(security_mode);
+
bleio_descriptor_obj_t *self = m_new_obj(bleio_descriptor_obj_t);
self->base.type = type;
bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_arg);
- common_hal_bleio_descriptor_construct(self, uuid);
- return MP_OBJ_FROM_PTR(self);
-}
+ common_hal_bleio_descriptor_construct(self, uuid, security_mode);
-STATIC mp_obj_t bleio_descriptor_get_handle(mp_obj_t self_in) {
- bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in);
-
- return mp_obj_new_int(common_hal_bleio_descriptor_get_handle(self));
+ return MP_OBJ_FROM_PTR(self);
}
-MP_DEFINE_CONST_FUN_OBJ_1(bleio_descriptor_get_handle_obj, bleio_descriptor_get_handle);
-
-const mp_obj_property_t bleio_descriptor_handle_obj = {
- .base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&bleio_descriptor_get_handle_obj,
- (mp_obj_t)&mp_const_none_obj,
- (mp_obj_t)&mp_const_none_obj},
-};
+//| .. attribute:: uuid
+//|
+//| The descriptor uuid. (read-only)
+//|
STATIC mp_obj_t bleio_descriptor_get_uuid(mp_obj_t self_in) {
bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -108,54 +95,7 @@ const mp_obj_property_t bleio_descriptor_uuid_obj = {
STATIC const mp_rom_map_elem_t bleio_descriptor_locals_dict_table[] = {
// Properties
- { MP_ROM_QSTR(MP_QSTR_handle), MP_ROM_PTR(&bleio_descriptor_handle_obj) },
{ MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_descriptor_uuid_obj) },
-
- // Static variables
- { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_EXTENDED_PROPERTIES),
- MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_EXTENDED_PROPERTIES) },
-
- { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_USER_DESCRIPTION),
- MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION) },
-
- { MP_ROM_QSTR(MP_QSTR_CLIENT_CHARACTERISTIC_CONFIGURATION),
- MP_ROM_INT(DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION) },
-
- { MP_ROM_QSTR(MP_QSTR_SERVER_CHARACTERISTIC_CONFIGURATION),
- MP_ROM_INT(DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION) },
-
- { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_PRESENTATION_FORMAT),
- MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_PRESENTATION_FORMAT) },
-
- { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_AGGREGATE_FORMAT),
- MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_AGGREGATE_FORMAT) },
-
- { MP_ROM_QSTR(MP_QSTR_VALID_RANGE),
- MP_ROM_INT(DESCRIPTOR_UUID_VALID_RANGE) },
-
- { MP_ROM_QSTR(MP_QSTR_EXTERNAL_REPORT_REFERENCE),
- MP_ROM_INT(DESCRIPTOR_UUID_EXTERNAL_REPORT_REFERENCE) },
-
- { MP_ROM_QSTR(MP_QSTR_REPORT_REFERENCE),
- MP_ROM_INT(DESCRIPTOR_UUID_REPORT_REFERENCE) },
-
- { MP_ROM_QSTR(MP_QSTR_NUMBER_OF_DIGITALS),
- MP_ROM_INT(DESCRIPTOR_UUID_NUMBER_OF_DIGITALS) },
-
- { MP_ROM_QSTR(MP_QSTR_VALUE_TRIGGER_SETTING),
- MP_ROM_INT(DESCRIPTOR_UUID_VALUE_TRIGGER_SETTING) },
-
- { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_CONFIGURATION),
- MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_CONFIGURATION) },
-
- { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_MEASUREMENT ),
- MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_MEASUREMENT) },
-
- { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_TRIGGER_SETTING),
- MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_TRIGGER_SETTING) },
-
- { MP_ROM_QSTR(MP_QSTR_TIME_TRIGGER_SETTING),
- MP_ROM_INT(DESCRIPTOR_UUID_TIME_TRIGGER_SETTING) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_locals_dict_table);