本文整理汇总了C++中sd_ble_gap_disconnect函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_ble_gap_disconnect函数的具体用法?C++ sd_ble_gap_disconnect怎么用?C++ sd_ble_gap_disconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_ble_gap_disconnect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_ble_evt
/**@brief Function for the Application's S110 SoftDevice event handler.
*
* @param[in] p_ble_evt S110 SoftDevice event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
m_is_advertising = false;
break;
case BLE_GAP_EVT_DISCONNECTED:
nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);
if (!m_tear_down_in_progress)
{
// The Disconnected event is because of an external event. (Link loss or
// disconnect triggered by the DFU Controller before the firmware update was
// complete).
// Restart advertising so that the DFU Controller can reconnect if possible.
advertising_start();
}
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
BLE_GAP_SEC_STATUS_SUCCESS,
&m_sec_params);
APP_ERROR_CHECK(err_code);
break;
case BLE_GATTS_EVT_TIMEOUT:
if (p_ble_evt->evt.gatts_evt.params.timeout.src == BLE_GATT_TIMEOUT_SRC_PROTOCOL)
{
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
}
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0);
APP_ERROR_CHECK(err_code);
break;
default:
// No implementation needed.
break;
}
}
示例2: on_conn_params_evt
/**@brief Function for handling the Connection Parameters Module.
*
* @details This function will be called for all events in the Connection Parameters Module which
* are passed to the application.
* @note All this function does is to disconnect. This could have been done by simply
* setting the disconnect_on_fail config parameter, but instead we use the event
* handler mechanism to demonstrate its use.
*
* @param[in] p_evt Event received from the Connection Parameters Module.
*/
static void on_conn_params_evt(ble_conn_params_evt_t * p_evt)
{
ret_code_t err_code;
if (p_evt->evt_type == BLE_CONN_PARAMS_EVT_FAILED)
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
APP_ERROR_CHECK(err_code);
}
}
示例3: ble_device_disconnect
void ble_device_disconnect( void )
{
uint32_t err_code;
if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
}
}
示例4: sd_ble_gap_disconnect
void BLETransceiver::onConnParamsEvt(ble_conn_params_evt_t * p_evt)
{
uint32_t err_code;
if(p_evt->evt_type == BLE_CONN_PARAMS_EVT_FAILED)
{
err_code = sd_ble_gap_disconnect(u16_connHandle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
APP_ERROR_CHECK(err_code);
}
}
示例5: on_conn_params_evt
/**@brief Function for handling the Connection Parameters Module.
*
* @details This function will be called for all events in the Connection Parameters Module which
* are passed to the application.
* @note All this function does is to disconnect. This could have been done by simply
* setting the disconnect_on_fail config parameter, but instead we use the event
* handler mechanism to demonstrate its use.
*
* @param[in] p_evt Event received from the Connection Parameters Module.
*/
static void on_conn_params_evt(ble_conn_params_evt_t * p_evt)
{
uint32_t err_code; // Variable used to check for any errors returned by functions
if(p_evt->evt_type == BLE_CONN_PARAMS_EVT_FAILED)
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
APP_ERROR_CHECK(err_code);// Check for errors
}
}
示例6: bsp_event_handler
/**@brief Function for handling events from the BSP module.
*
* @param[in] event Event generated when button is pressed.
*/
static void bsp_event_handler(bsp_event_t event)
{
uint32_t err_code;
switch (event)
{
case BSP_EVENT_SLEEP:
sleep_mode_enter();
break;
case BSP_EVENT_DISCONNECT:
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
break;
case BSP_EVENT_KEY_0:
if (m_is_ias_present)
{
if (!m_is_high_alert_signalled)
{
err_code = ble_ias_c_send_alert_level(&m_ias_c, BLE_CHAR_ALERT_LEVEL_HIGH_ALERT);
}
else
{
err_code = ble_ias_c_send_alert_level(&m_ias_c, BLE_CHAR_ALERT_LEVEL_NO_ALERT);
}
if (err_code == NRF_SUCCESS)
{
m_is_high_alert_signalled = !m_is_high_alert_signalled;
}
else if (
(err_code != BLE_ERROR_NO_TX_PACKETS)
&&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
&&
(err_code != NRF_ERROR_NOT_FOUND)
)
{
APP_ERROR_HANDLER(err_code);
}
}
break;
case BSP_EVENT_KEY_1: //STOP_ALERTING_BUTTON_ID
err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF);
APP_ERROR_CHECK(err_code);
break;
default:
break;
}
}
示例7: on_ble_evt
/**@brief Function for handling the Application's BLE Stack events.
*
* @param[in] p_ble_evt Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
nrf_gpio_pin_set(LED_CONNECTED);
g_UartServ.conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
break;
case BLE_GAP_EVT_DISCONNECTED:
nrf_gpio_pin_clear(LED_CONNECTED);
g_UartServ.conn_handle = BLE_CONN_HANDLE_INVALID;
advertising_start();
// Go to system-off mode, should not return from this function, wakeup will trigger
// a reset.
//system_off_mode_enter();
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
//err_code = sd_ble_gap_sec_params_reply(g_UartServ.conn_handle,
// BLE_GAP_SEC_STATUS_SUCCESS,
// &g_GAPSecParams);
//APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING)
{
nrf_gpio_pin_set(LED_CONNECTED);
// Go to system-off mode.
// (this function will not return; wakeup will cause a reset).
err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);
}
break;
case BLE_GATTC_EVT_TIMEOUT:
case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server and Client timeout events.
err_code = sd_ble_gap_disconnect(g_UartServ.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;
default:
// No implementation needed.
break;
}
}
示例8: on_ble_evt
/**@brief Function for handling BLE Stack events.
*
* @param[in] p_ble_evt Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
on_ble_gap_evt_adv_report(p_gap_evt);
break;
case BLE_GAP_EVT_CONNECTED:
on_ble_gap_evt_connected(p_gap_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_ble_gap_evt_disconnected(p_gap_evt);
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
{
// Accept parameters requested by the peer.
ble_gap_conn_params_t params;
params = p_gap_evt->params.conn_param_update_request.conn_params;
params.max_conn_interval = params.min_conn_interval;
err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle, ¶ms);
APP_ERROR_CHECK(err_code);
} break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
{
err_code = sd_ble_gatts_sys_attr_set(p_gap_evt->conn_handle, NULL, 0, 0);
APP_ERROR_CHECK(err_code);
} break;
case BLE_GATTC_EVT_TIMEOUT: // Fallthrough.
case BLE_GATTS_EVT_TIMEOUT:
{
NRF_LOG_DEBUG("GATT timeout, disconnecting.\r\n");
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
} break;
case BLE_EVT_USER_MEM_REQUEST:
{
err_code = sd_ble_user_mem_reply(p_ble_evt->evt.common_evt.conn_handle, NULL);
APP_ERROR_CHECK(err_code);
} break;
default:
// No implementation needed.
break;
}
}
示例9: flash_callback
void flash_callback(fs_evt_t const * const evt, fs_ret_t result)
{
if (result == FS_SUCCESS)
{
NRF_LOG_INFO("Obtained settings, enter dfu is %d\n", s_dfu_settings.enter_buttonless_dfu);
(void)sd_ble_gap_disconnect(p_m_dfu->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
p_m_dfu->is_waiting_for_disconnection = true;
}
}
示例10: jswrap_nrf_bluetooth_sleep
/*JSON{
"type" : "staticmethod",
"class" : "NRF",
"name" : "sleep",
"generate" : "jswrap_nrf_bluetooth_sleep"
}*/
void jswrap_nrf_bluetooth_sleep(void) {
uint32_t err_code;
// If connected, disconnect.
if (m_conn_handle != BLE_CONN_HANDLE_INVALID) {
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
// Stop advertising
err_code = sd_ble_gap_adv_stop();
NRF_RADIO->TASKS_DISABLE = (1UL);
}
示例11: bsp_event_handler
/**@brief Function for handling events from the BSP module.
*
* @param[in] event Event generated by button press.
*/
static void bsp_event_handler(bsp_event_t event)
{
uint32_t err_code;
switch (event)
{
case BSP_EVENT_SLEEP:
sleep_mode_enter();
break;//BSP_EVENT_SLEEP
case BSP_EVENT_DISCONNECT:
err_code = sd_ble_gap_disconnect(m_ans_c.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
break;//BSP_EVENT_DISCONNECT
case BSP_EVENT_WHITELIST_OFF:
err_code = ble_advertising_restart_without_whitelist();
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
break;//BSP_EVENT_WHITELIST_OFF
case BSP_EVENT_KEY_0:
if (m_ans_c.conn_handle != BLE_CONN_HANDLE_INVALID)
{
new_alert_state_toggle();
}
break;//BSP_EVENT_KEY_0
case BSP_EVENT_KEY_1:
if (m_ans_c.conn_handle != BLE_CONN_HANDLE_INVALID)
{
unread_alert_state_toggle();
}
break;//BSP_EVENT_KEY_1
case BSP_EVENT_KEY_2:
if (m_ans_c.conn_handle != BLE_CONN_HANDLE_INVALID)
{
all_alert_notify_request();
}
break;//BSP_EVENT_KEY_2
default:
// No implementation needed.
break;
}
}
示例12: on_ble_evt
/**@brief Function for handling the application's BLE stack events.
*
* @param[in] p_ble_evt Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code = NRF_SUCCESS;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
printf("@Connected\n\r");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(m_sec_ping, PING_DELAY, &m_notification_latest);
APP_ERROR_CHECK(err_code);
// BSP_LED_0_MASK BSP_LED_1_MASK BSP_LED_2_MASK
LEDS_ON(BSP_LED_1_MASK);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
break;
case BLE_GAP_EVT_DISCONNECTED:
printf("@Disconnected\n\r");
m_conn_handle = BLE_CONN_HANDLE_INVALID;
// BSP_LED_0_MASK BSP_LED_1_MASK BSP_LED_2_MASK
LEDS_OFF(BSP_LED_1_MASK);
err_code = app_timer_stop(m_sec_ping);
APP_ERROR_CHECK(err_code);
while (1) {
nrf_delay_ms(200);
LEDS_INVERT(BSP_LED_1_MASK);
}
break;
case BLE_GATTC_EVT_TIMEOUT:
case BLE_GATTS_EVT_TIMEOUT:
LOG("Timeout.\n\r");
// Disconnect on GATT Server and Client time-out events.
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;
default:
// No implementation needed.
break;
}
APP_ERROR_CHECK(err_code);
}
示例13: update_timeout_handler
static void update_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
#else /* #if !USE_APP_TIMER */
static void update_timeout_handler(void)
{
m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */
#endif /* #if !USE_APP_TIMER */
if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
// Check if we have reached the maximum number of attempts
m_update_count++;
if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
{
uint32_t err_code;
// Parameters are not ok, send connection parameters update request.
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
m_conn_params_config.error_handler(err_code);
}
}
else
{
m_update_count = 0;
// Negotiation failed, disconnect automatically if this has been configured
if (m_conn_params_config.disconnect_on_fail)
{
uint32_t err_code;
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
m_conn_params_config.error_handler(err_code);
}
}
// Notify the application that the procedure has failed
if (m_conn_params_config.evt_handler != NULL)
{
ble_conn_params_evt_t evt;
evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
m_conn_params_config.evt_handler(&evt);
}
}
}
}
示例14: on_ble_evt
/**@brief Function for handling the Application's BLE Stack events.
*
* @param[in] p_ble_evt Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code = NRF_SUCCESS;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_advertising_mode = BLE_NO_ADV;
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
break;
case BLE_GAP_EVT_DISCONNECTED:
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
advertising_start();
break;
case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING)
{
if (m_advertising_mode == BLE_SLEEP)
{
sleep_mode_enter();
}
else
{
advertising_start();
}
}
break;
case BLE_GATTC_EVT_TIMEOUT:
case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server and Client timeout events.
err_code = sd_ble_gap_disconnect(m_conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;
default:
// No implementation needed.
break;
}
}
示例15: notif_timeout_handler
/**@brief Function for handling the Notification timeout.
*
* @details This function will be called when the notification timer expires. This will stop the
* timer for connection interval and disconnect from the peer.
*
* @param[in] p_context Pointer used for passing some arbitrary information (context) from the
* app_start_timer() call to the timeout handler.
*/
static void notif_timeout_handler(void * p_context)
{
uint32_t err_code;
UNUSED_PARAMETER(p_context);
// Stop all notifications (by stopping the timer for connection interval that triggers
// notifications and disconnecting from peer).
err_code = app_timer_stop(m_conn_int_timer_id);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
}