diff --git a/boards.txt b/boards.txt index cfd06e4a..811c1a54 100644 --- a/boards.txt +++ b/boards.txt @@ -50,8 +50,8 @@ feather52.build.nrfutil.macosx=/usr/local/bin/nrfutil feather52.menu.debug.l0=Level 0 (Release) feather52.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0 -feather52.menu.debug.l1=Level 1 (Error Mess) +feather52.menu.debug.l1=Level 1 (Error Message) feather52.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1 -feather52.menu.debug.l2=Level 2 (TBD) +feather52.menu.debug.l2=Level 2 (Full Debug) feather52.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 diff --git a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp index 38baf542..8ae0a54a 100644 --- a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp +++ b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp @@ -343,6 +343,10 @@ void BLECharacteristic::eventHandler(ble_evt_t* event) } } +/*------------------------------------------------------------------*/ +/* WRITE + *------------------------------------------------------------------*/ + err_t BLECharacteristic::write(const uint8_t* data, int len) { return write(data, len, 0); @@ -389,9 +393,13 @@ err_t BLECharacteristic::write(uint8_t num) return write( (uint8_t*) &num, sizeof(num)); } +/*------------------------------------------------------------------*/ +/* NOTIFY + *------------------------------------------------------------------*/ bool BLECharacteristic::notifyEnabled(void) { VERIFY( _properties.notify && Bluefruit.connected() ); + uint16_t cccd; ble_gatts_value_t value = { @@ -407,24 +415,32 @@ bool BLECharacteristic::notifyEnabled(void) err_t BLECharacteristic::notify(const uint8_t* data, int len, uint16_t offset) { - if ( !_properties.notify ) return NRF_ERROR_INVALID_PARAM; + VERIFY( _properties.notify, NRF_ERROR_INVALID_PARAM); - // Whether Txbuf available or not we still update the chars'value - (void) Bluefruit.txbuf_get(100); - - // could not exceed max len - uint16_t actual_len = min16(len, _max_len); - - ble_gatts_hvx_params_t hvx_params = + // Must already connected for enabled to be tru + if ( notifyEnabled() ) { - .handle = _handles.value_handle, - .type = BLE_GATT_HVX_NOTIFICATION, - .offset = offset, - .p_len = &actual_len, - .p_data = (uint8_t*) data, - }; + // Whether Txbuf available or not we still update the chars'value + (void) Bluefruit.txbuf_get(100); - VERIFY_STATUS( sd_ble_gatts_hvx(Bluefruit.connHandle(), &hvx_params) ); + // could not exceed max len + uint16_t actual_len = min16(len, _max_len); + + ble_gatts_hvx_params_t hvx_params = + { + .handle = _handles.value_handle, + .type = BLE_GATT_HVX_NOTIFICATION, + .offset = offset, + .p_len = &actual_len, + .p_data = (uint8_t*) data, + }; + + VERIFY_STATUS( sd_ble_gatts_hvx(Bluefruit.connHandle(), &hvx_params) ); + } + else + { + write(data, len); + } return ERROR_NONE; } diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 3bb318b4..61ad0a3f 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -103,6 +103,9 @@ AdafruitBluefruit::AdafruitBluefruit(void) _conn_hdl = BLE_GATT_HANDLE_INVALID; _bonded = false; + _auth_type = BLE_GAP_AUTH_KEY_TYPE_NONE; + varclr(_pin); + _chars_count = 0; for(uint8_t i=0; ievt.gap_evt.params.passkey_display; + + PRINT_INT(passkey_display->match_request); + PRINT_BUFFER(passkey_display->passkey, 6); + + // sd_ble_gap_auth_key_reply + } + break; case BLE_GAP_EVT_CONN_SEC_UPDATE: { diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index e83e7251..bad9efb1 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -106,8 +106,8 @@ class AdafruitBluefruit /*------------------------------------------------------------------*/ /* *------------------------------------------------------------------*/ - void disconnect(void); bool connected(void); + void disconnect(void); err_t setConnInterval (uint16_t min, uint16_t max); err_t setConnIntervalMS(uint16_t min_ms, uint16_t max_ms); @@ -117,10 +117,11 @@ class AdafruitBluefruit ble_gap_addr_t peerAddr(void); bool txbuf_get(uint32_t ms); - err_t saveAllCCCD(void); + + bool setPIN(const char* pin); /*------------------------------------------------------------------*/ - /* Central + /* Central API object *------------------------------------------------------------------*/ BLECentral Central; @@ -142,11 +143,12 @@ class AdafruitBluefruit bool _central_enabled; SemaphoreHandle_t _ble_event_sem; - BLEDfu _dfu_svc; TimerHandle_t _led_blink_th; bool _led_conn; + BLEDfu _dfu_svc; + // ADV Data struct { uint8_t data[BLE_GAP_ADV_MAX_SIZE]; @@ -163,6 +165,9 @@ class AdafruitBluefruit uint16_t _conn_hdl; bool _bonded; + uint8_t _auth_type; + char _pin[BLE_GAP_PASSKEY_LEN]; + // TODO move to bonding place public: // temporary struct { @@ -179,7 +184,6 @@ private: ble_gap_addr_t _peer_addr; - // Transmission Buffer Count for HVX notification, max is seen at 7 SemaphoreHandle_t _txbuf_sem; @@ -192,6 +196,7 @@ private: void _startConnLed(void); void _stopConnLed(void); + err_t _saveBondedCCCD(void); void _poll(void); friend void adafruit_bluefruit_task(void* arg);