aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c')
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c
new file mode 100644
index 0000000..77cf92b
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/examples/ble_peripheral/ble_app_gatts_c/app_adv.c
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/**@brief Application advertising module.
+
+ @details This module contains the functions used by the example application
+ to set up the Advertising Module module and handle its events.
+*/
+
+#include "app_adv.h"
+#include "ble_advdata.h"
+#include "ble_advertising.h"
+#include "bsp.h"
+#include "peer_manager.h"
+#include "nrf_sdh.h"
+#include "nrf_sdh_soc.h"
+#include "nrf_sdh_ble.h"
+#include "nrf_log.h"
+
+
+#define APP_BLE_CONN_CFG_TAG 1 /**< A tag for a BLE stack configuration .*/
+#define APP_ADV_DURATION BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising duration in units of 10 milliseconds. */
+
+
+BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
+
+
+/**@brief Function for handling advertising events.
+
+ @details This function will be called for advertising events which are passed to the application.
+
+ @param[in] ble_adv_evt Advertising event.
+ */
+void on_adv_evt(ble_adv_evt_t ble_adv_evt)
+{
+ ret_code_t err_code;
+
+ switch (ble_adv_evt)
+ {
+ case BLE_ADV_EVT_FAST:
+ NRF_LOG_INFO("Fast advertising.");
+ err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
+ APP_ERROR_CHECK(err_code);
+ break;
+
+ case BLE_ADV_EVT_IDLE:
+ NRF_LOG_INFO("Advertising stopped.");
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/**@brief Function for initializing the Advertising functionality.
+
+ @details Encodes the required advertising data and passes it to the stack.
+ Also builds a structure to be passed to the stack when starting advertising.
+ */
+void advertising_init(void)
+{
+ ret_code_t err_code;
+ ble_advertising_init_t init;
+
+ memset(&init, 0, sizeof(init));
+
+
+ init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
+ init.advdata.include_appearance = true;
+ init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
+
+ init.config.ble_adv_fast_enabled = true;
+ init.config.ble_adv_fast_interval = ADV_INTERVAL;
+ init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
+
+ init.evt_handler = on_adv_evt;
+
+ err_code = ble_advertising_init(&m_advertising, &init);
+ APP_ERROR_CHECK(err_code);
+
+ ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
+}
+
+
+/**@brief Function for starting advertising, or instead trigger it from peer manager (after
+ deleting bonds).
+
+ @param[in] erase_bonds Bool to determine if bonds will be deleted before advertising.
+*/
+void advertising_start(bool erase_bonds)
+{
+ ret_code_t err_code;
+
+ if (erase_bonds == true)
+ {
+ // Advertising is started by the PM_EVT_PEERS_DELETE_SUCCEEDED event.
+ NRF_LOG_INFO("Erase bonds.");
+ err_code = pm_peers_delete();
+ APP_ERROR_CHECK(err_code);
+ }
+ else
+ {
+ err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
+ APP_ERROR_CHECK(err_code);
+ }
+}