/**@brief Function for handling the Apple Notification Service client. * * @details This function is called for all events in the Apple Notification client that * are passed to the application. * * @param[in] p_evt Event received from the Apple Notification Service client. */ static void on_ancs_c_evt(ble_ancs_c_evt_t * p_evt) { uint32_t err_code = NRF_SUCCESS; switch (p_evt->evt_type) { case BLE_ANCS_C_EVT_DISCOVERY_COMPLETE: QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_END() QS_START_TX(); err_code = ble_ancs_c_handles_assign(&m_ancs_c,p_evt->conn_handle , &p_evt->service); APP_ERROR_CHECK(err_code); #if 0 apple_notification_setup(); #else QACTIVE_POST(AO_ble, ANCS_SIG, p_evt->evt_type); #endif break; case BLE_ANCS_C_EVT_NOTIF: { struct AncsNotification* status = &l_Ble.ancs_status[p_evt->notif.category_id]; status->flags = p_evt->notif.evt_flags; status->category_count = p_evt->notif.category_count; QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_U8(0, p_evt->notif.evt_id); QS_MEM((uint8_t*)&status->flags, sizeof(status->flags)); QS_END() QS_START_TX(); QACTIVE_POST(AO_ble, ANCS_SIG , ((uint32_t)p_evt->notif.evt_id << 24) //Add/Mod/Remove | 0 // flags might not fit into 8 bits if compiler doesn't pack | ((uint16_t)p_evt->notif.category_id << 8)//email, etc | p_evt->evt_type); } break; //case BLE_ANCS_C_EVT_NOTIF_ATTRIBUTE: //title, message, date, etc default: QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_END() QS_START_TX(); break; } }
/**@brief Function for handling the Apple Notification Service client. * * @details This function is called for all events in the Apple Notification client that * are passed to the application. * * @param[in] p_evt Event received from the Apple Notification Service client. */ static void on_ancs_c_evt(ble_ancs_c_evt_t * p_evt) { uint32_t err_code = NRF_SUCCESS; switch (p_evt->evt_type) { case BLE_ANCS_C_EVT_DISCOVER_COMPLETE: LOG("Apple Notification Service discovered on the server.\n"); apple_notification_setup(); break; case BLE_ANCS_C_EVT_NOTIF: m_notification_latest = p_evt->notif; notif_print(&m_notification_latest); break; case BLE_ANCS_C_EVT_NOTIF_ATTRIBUTE: notif_attr_print(&p_evt->attr, p_evt->ancs_attr_list); break; case BLE_ANCS_C_EVT_DISCOVER_FAILED: // ANCS not found. 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); } LOG("Apple Notification Service not discovered on the server.\n"); break; default: // No implementation needed. break; } }
/**@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; static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; 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); err_code = bsp_buttons_enable((1<<DISPLAY_MESSAGE_BUTTON_ID)); APP_ERROR_CHECK(err_code); m_advertising_mode = BLE_NO_ADVERTISING; m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; break; case BLE_GAP_EVT_AUTH_STATUS: apple_notification_setup(); 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; // Stop detecting button presses when not connected. err_code = bsp_buttons_enable(BSP_BUTTONS_NONE); APP_ERROR_CHECK(err_code); err_code = ble_ans_c_service_store(); APP_ERROR_CHECK(err_code); advertising_start(); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { if (m_advertising_mode == BLE_FAST_ADVERTISING) { advertising_start(); } else { err_code = bsp_indication_set(BSP_INDICATE_IDLE); APP_ERROR_CHECK(err_code); m_advertising_mode = BLE_NO_ADVERTISING; err_code = bsp_buttons_enable( (1 << BOND_DELETE_ALL_WAKEUP_BUTTON_ID) ); APP_ERROR_CHECK(err_code); // Go to system-off mode (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(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); }
/**@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; static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; 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); err_code = app_button_enable(); m_advertising_mode = BLE_NO_ADVERTISING; m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; break; case BLE_GAP_EVT_AUTH_STATUS: apple_notification_setup(); break; case BLE_GAP_EVT_DISCONNECTED: nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO); m_conn_handle = BLE_CONN_HANDLE_INVALID; // Stop detecting button presses when not connected. err_code = app_button_disable(); APP_ERROR_CHECK(err_code); // Since we are not in a connection and have not start to advertise either, store bonds. err_code = ble_bondmngr_bonded_centrals_store(); APP_ERROR_CHECK(err_code); err_code = ble_ans_c_service_store(); APP_ERROR_CHECK(err_code); advertising_start(); 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); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { if (m_advertising_mode == BLE_FAST_ADVERTISING) { advertising_start(); } else { nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO); m_advertising_mode = BLE_NO_ADVERTISING; // Go to system-off mode (function will not return; wakeup will cause a reset). nrf_gpio_cfg_sense_input(WAKEUP_BUTTON_PIN, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(BONDMNGR_DELETE_BUTTON_PIN_NO, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); err_code = sd_power_system_off(); } } 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); break; default: //No implementation needed break; } APP_ERROR_CHECK(err_code); }