uint32_t conn_mw_ble_tx_packet_count_get(uint8_t const * const p_rx_buf, uint32_t rx_buf_len, uint8_t * const p_tx_buf, uint32_t * const p_tx_buf_len) { SER_ASSERT_NOT_NULL(p_rx_buf); SER_ASSERT_NOT_NULL(p_tx_buf); SER_ASSERT_NOT_NULL(p_tx_buf_len); uint8_t count; uint16_t conn_handle; uint8_t * p_count = &count; uint32_t err_code = NRF_SUCCESS; uint32_t sd_err_code; err_code = ble_tx_packet_count_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_count); SER_ASSERT(err_code == NRF_SUCCESS, err_code); sd_err_code = sd_ble_tx_packet_count_get(conn_handle, p_count); err_code = ble_tx_packet_count_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_count); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
/***************************************************************************** * Static functions *****************************************************************************/ static uint32_t mesh_gatt_evt_push(mesh_gatt_evt_t* p_gatt_evt) { if (m_active_conn_handle == CONN_HANDLE_INVALID) { return BLE_ERROR_INVALID_CONN_HANDLE; } if (!m_mesh_service.notification_enabled) { return BLE_ERROR_NOT_ENABLED; } uint8_t count; uint8_t err_code; #if (NORDIC_SDK_VERSION >= 11) err_code = sd_ble_tx_packet_count_get(m_active_conn_handle, &count); #else err_code = sd_ble_tx_buffer_count_get(&count); #endif if (err_code != NRF_SUCCESS) { return NRF_ERROR_BUSY; } if (count == 0) { #if (NORDIC_SDK_VERSION >= 11) return BLE_ERROR_NO_TX_PACKETS; #else return BLE_ERROR_NO_TX_BUFFERS; #endif } ble_gatts_hvx_params_t hvx_params; hvx_params.handle = m_mesh_service.ble_val_char_handles.value_handle; hvx_params.type = BLE_GATT_HVX_NOTIFICATION; hvx_params.offset = 0; uint16_t hvx_len; switch (p_gatt_evt->opcode) { case MESH_GATT_EVT_OPCODE_DATA: hvx_len = p_gatt_evt->param.data_update.data_len + 4; break; case MESH_GATT_EVT_OPCODE_FLAG_SET: case MESH_GATT_EVT_OPCODE_FLAG_REQ: case MESH_GATT_EVT_OPCODE_FLAG_RSP: hvx_len = 5; break; case MESH_GATT_EVT_OPCODE_CMD_RSP: hvx_len = 3; break; default: hvx_len = 1; } hvx_params.p_len = &hvx_len; hvx_params.p_data = (uint8_t*) p_gatt_evt; return sd_ble_gatts_hvx(m_active_conn_handle, &hvx_params); }
/*######## HANDLER ###################################*/ void Connection::ConnectionSuccessfulHandler(ble_evt_t* bleEvent) { u32 err = 0; this->handshakeStarted = node->appTimerMs; if (direction == CONNECTION_DIRECTION_IN) logt("CONN", "Incoming connection %d connected", connectionId); else logt("CONN", "Outgoing connection %d connected", connectionId); connectionHandle = bleEvent->evt.gap_evt.conn_handle; err = sd_ble_tx_packet_count_get(this->connectionHandle, &unreliableBuffersFree); if(err != NRF_SUCCESS){ //BLE_ERROR_INVALID_CONN_HANDLE && NRF_ERROR_INVALID_ADDR can be ignored } //Save connection interval (min and max are the same values in this event) currentConnectionInterval = bleEvent->evt.gap_evt.params.connected.conn_params.min_conn_interval; connectionState = CONNECTED; }