From 6ff37ded28cce60f1cf36180560a602c7d984fc7 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 24 Jan 2021 21:50:43 +0100 Subject: [PATCH] change(mp-ble): Cleanup cccd section --- pycardium/modules/modbluetooth_card10.c | 34 +++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index 9916eba60..66f86ef8a 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -449,17 +449,16 @@ int mp_bluetooth_gatts_register_service( flags & (MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE)) { /* CCCD */ currentHandle++; - uint8_t initCcc[2] = {}; - // TODO: activate notification/indications by default - // Not according to spec + uint8_t cccd_buf[2] = {}; + // TODO: Handle CCC data. + // Until then: activate notification/indications by default. if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY) { - initCcc[0] |= 0x01; + cccd_buf[0] |= 0x01; } if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE) { - initCcc[0] |= 0x02; + cccd_buf[0] |= 0x02; } - // TODO: Handle CCC data uint8_t ccc_uuid[] = { 0x02, 0x29 }; uint8_t flags = MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ | MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE; @@ -468,16 +467,25 @@ int mp_bluetooth_gatts_register_service( ccc_uuid, sizeof(ccc_uuid), flags, - initCcc, - sizeof(initCcc), - sizeof(initCcc) + cccd_buf, + sizeof(cccd_buf), + sizeof(cccd_buf) ); epic_ble_atts_set_attr( - currentHandle, initCcc, sizeof(initCcc) + currentHandle, cccd_buf, sizeof(cccd_buf) ); - //mp_bluetooth_gatts_db_create_entry(GATTS_DB, handles[handle_index] + 1, MP_BLUETOOTH_CCCB_LEN); - //gatts_status_create_entry(GATTS_STATUS, handles[handle_index] + 1); - //int ret = mp_bluetooth_gatts_db_write(GATTS_DB, handles[handle_index] + 1, cccb_buf, sizeof(cccb_buf)); + mp_bluetooth_gatts_db_create_entry( + GATTS_DB, currentHandle, sizeof(cccd_buf) + ); + int ret = mp_bluetooth_gatts_db_write( + GATTS_DB, + currentHandle, + cccd_buf, + sizeof(cccd_buf) + ); + if (ret) { + return ret; + } } handle_index++; -- GitLab