初始版本
This commit is contained in:
530
components/ble/ble_services/ble_ans_c/ble_ans_c.c
Normal file
530
components/ble/ble_services/ble_ans_c/ble_ans_c.c
Normal file
@@ -0,0 +1,530 @@
|
||||
/**
|
||||
* Copyright (c) 2012 - 2020, 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.
|
||||
*
|
||||
*/
|
||||
/* Attention!
|
||||
* To maintain compliance with Nordic Semiconductor ASA's Bluetooth profile
|
||||
* qualification listings, this section of source code must not be modified.
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(BLE_ANS_C)
|
||||
#include "ble_ans_c.h"
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "ble_err.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "ble_db_discovery.h"
|
||||
#define NRF_LOG_MODULE_NAME ble_ans_c
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
#define NOTIFICATION_DATA_LENGTH 2 /**< The mandatory length of the notification data. After the mandatory data, the optional message is located. */
|
||||
#define READ_DATA_LENGTH_MIN 1 /**< Minimum data length in a valid Alert Notification Read Response message. */
|
||||
#define WRITE_MESSAGE_LENGTH 2 /**< Length of the write message for CCCD and control point. */
|
||||
|
||||
|
||||
/**@brief Function for intercepting GATTC and @ref nrf_ble_gq errors.
|
||||
*
|
||||
* @param[in] nrf_error Error code.
|
||||
* @param[in] p_ctx Parameter from the event handler.
|
||||
* @param[in] conn_handle Connection handle.
|
||||
*/
|
||||
static void gatt_error_handler(uint32_t nrf_error,
|
||||
void * p_ctx,
|
||||
uint16_t conn_handle)
|
||||
{
|
||||
ble_ans_c_t * p_ans = (ble_ans_c_t *)p_ctx;
|
||||
|
||||
NRF_LOG_DEBUG("A GATT Client error has occurred on conn_handle: 0X%X", conn_handle);
|
||||
|
||||
if (p_ans->error_handler != NULL)
|
||||
{
|
||||
p_ans->error_handler(nrf_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function for copying a characteristic.
|
||||
*/
|
||||
static void char_set(ble_gattc_char_t * p_dest_char, ble_gattc_char_t const * p_source_char)
|
||||
{
|
||||
memcpy(p_dest_char, p_source_char, sizeof(ble_gattc_char_t));
|
||||
}
|
||||
|
||||
static void char_cccd_set(ble_gattc_desc_t * p_cccd, uint16_t cccd_handle)
|
||||
{
|
||||
p_cccd->handle = cccd_handle;
|
||||
}
|
||||
|
||||
/** @brief Function for checking the presence of all the handles required by the client to use the server.
|
||||
*/
|
||||
static bool is_valid_ans_srv_discovered(ble_ans_c_service_t const * p_srv)
|
||||
{
|
||||
if ((p_srv->alert_notif_ctrl_point.handle_value == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->suported_new_alert_cat.handle_value == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->suported_unread_alert_cat.handle_value == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->new_alert.handle_value == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->unread_alert_status.handle_value == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->new_alert_cccd.handle == BLE_GATT_HANDLE_INVALID) ||
|
||||
(p_srv->unread_alert_cccd.handle == BLE_GATT_HANDLE_INVALID)
|
||||
)
|
||||
{
|
||||
// At least one required characteristic is missing on the server side.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ble_ans_c_on_db_disc_evt(ble_ans_c_t * p_ans, ble_db_discovery_evt_t const * p_evt)
|
||||
{
|
||||
ble_ans_c_evt_t evt;
|
||||
|
||||
memset(&evt, 0, sizeof(ble_ans_c_evt_t));
|
||||
evt.conn_handle = p_evt->conn_handle;
|
||||
|
||||
// Check if the Alert Notification Service is discovered.
|
||||
if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE
|
||||
&&
|
||||
p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_ALERT_NOTIFICATION_SERVICE
|
||||
&&
|
||||
p_evt->params.discovered_db.srv_uuid.type == BLE_UUID_TYPE_BLE)
|
||||
{
|
||||
// Find the characteristics inside the service.
|
||||
for (uint8_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
|
||||
{
|
||||
ble_gatt_db_char_t const * p_char = &(p_evt->params.discovered_db.charateristics[i]);
|
||||
|
||||
switch (p_char->characteristic.uuid.uuid)
|
||||
{
|
||||
case BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR:
|
||||
NRF_LOG_DEBUG("Found Ctrlpt \r\n\r");
|
||||
char_set(&evt.data.service.alert_notif_ctrl_point, &p_char->characteristic);
|
||||
break;
|
||||
|
||||
case BLE_UUID_UNREAD_ALERT_CHAR:
|
||||
NRF_LOG_DEBUG("Found Unread Alert \r\n\r");
|
||||
char_set(&evt.data.service.unread_alert_status, &p_char->characteristic);
|
||||
char_cccd_set(&evt.data.service.unread_alert_cccd,
|
||||
p_char->cccd_handle);
|
||||
break;
|
||||
|
||||
case BLE_UUID_NEW_ALERT_CHAR:
|
||||
NRF_LOG_DEBUG("Found New Alert \r\n\r");
|
||||
char_set(&evt.data.service.new_alert, &p_char->characteristic);
|
||||
char_cccd_set(&evt.data.service.new_alert_cccd,
|
||||
p_char->cccd_handle);
|
||||
break;
|
||||
|
||||
case BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR:
|
||||
NRF_LOG_DEBUG("Found supported unread alert category \r\n\r");
|
||||
char_set(&evt.data.service.suported_unread_alert_cat, &p_char->characteristic);
|
||||
break;
|
||||
|
||||
case BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR:
|
||||
NRF_LOG_DEBUG("Found supported new alert category \r\n\r");
|
||||
char_set(&evt.data.service.suported_new_alert_cat, &p_char->characteristic);
|
||||
break;
|
||||
|
||||
default:
|
||||
// No implementation needed.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_valid_ans_srv_discovered(&evt.data.service))
|
||||
{
|
||||
evt.evt_type = BLE_ANS_C_EVT_DISCOVERY_COMPLETE;
|
||||
}
|
||||
}
|
||||
else if ((p_evt->evt_type == BLE_DB_DISCOVERY_SRV_NOT_FOUND) ||
|
||||
(p_evt->evt_type == BLE_DB_DISCOVERY_ERROR))
|
||||
{
|
||||
evt.evt_type = BLE_ANS_C_EVT_DISCOVERY_FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p_ans->evt_handler(&evt);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for receiving and validating notifications received from the central.
|
||||
*/
|
||||
static void event_notify(ble_ans_c_t * p_ans, ble_evt_t const * p_ble_evt)
|
||||
{
|
||||
uint32_t message_length;
|
||||
ble_ans_c_evt_t event;
|
||||
ble_ans_alert_notification_t * p_alert = &event.data.alert;
|
||||
ble_gattc_evt_hvx_t const * p_notification = &p_ble_evt->evt.gattc_evt.params.hvx;
|
||||
|
||||
// If the message is not valid, then ignore.
|
||||
event.evt_type = BLE_ANS_C_EVT_NOTIFICATION;
|
||||
if (p_notification->len < NOTIFICATION_DATA_LENGTH)
|
||||
{
|
||||
return;
|
||||
}
|
||||
message_length = p_notification->len - NOTIFICATION_DATA_LENGTH;
|
||||
|
||||
if (p_notification->handle == p_ans->service.new_alert.handle_value)
|
||||
{
|
||||
BLE_UUID_COPY_INST(event.uuid, p_ans->service.new_alert.uuid);
|
||||
}
|
||||
else if (p_notification->handle == p_ans->service.unread_alert_status.handle_value)
|
||||
{
|
||||
BLE_UUID_COPY_INST(event.uuid, p_ans->service.unread_alert_status.uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing to process.
|
||||
return;
|
||||
}
|
||||
|
||||
p_alert->alert_category = p_notification->data[0];
|
||||
p_alert->alert_category_count = p_notification->data[1]; //lint !e415
|
||||
p_alert->alert_msg_length = (message_length > p_ans->message_buffer_size)
|
||||
? p_ans->message_buffer_size
|
||||
: message_length;
|
||||
p_alert->p_alert_msg_buf = p_ans->p_message_buffer;
|
||||
|
||||
memcpy(p_alert->p_alert_msg_buf,
|
||||
&p_notification->data[NOTIFICATION_DATA_LENGTH],
|
||||
p_alert->alert_msg_length); //lint !e416
|
||||
|
||||
p_ans->evt_handler(&event);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for validating and passing the response to the application,
|
||||
* when a read response is received.
|
||||
*/
|
||||
static void event_read_rsp(ble_ans_c_t * p_ans, ble_evt_t const * p_ble_evt)
|
||||
{
|
||||
ble_ans_c_evt_t event;
|
||||
ble_gattc_evt_read_rsp_t const * p_response;
|
||||
|
||||
p_response = &p_ble_evt->evt.gattc_evt.params.read_rsp;
|
||||
event.evt_type = BLE_ANS_C_EVT_READ_RESP;
|
||||
|
||||
if (p_response->len < READ_DATA_LENGTH_MIN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_response->handle == p_ans->service.suported_new_alert_cat.handle_value)
|
||||
{
|
||||
BLE_UUID_COPY_INST(event.uuid, p_ans->service.suported_new_alert_cat.uuid);
|
||||
}
|
||||
else if (p_response->handle == p_ans->service.suported_unread_alert_cat.handle_value)
|
||||
{
|
||||
BLE_UUID_COPY_INST(event.uuid, p_ans->service.suported_unread_alert_cat.uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the response is not valid, then ignore.
|
||||
return;
|
||||
}
|
||||
|
||||
event.data.settings = *(ble_ans_alert_settings_t *)(p_response->data);
|
||||
|
||||
if (p_response->len == READ_DATA_LENGTH_MIN)
|
||||
{
|
||||
// These variables must default to 0, if they are not returned by central.
|
||||
event.data.settings.ans_high_prioritized_alert_support = 0;
|
||||
event.data.settings.ans_instant_message_support = 0;
|
||||
}
|
||||
|
||||
p_ans->evt_handler(&event);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for disconnecting and cleaning the current service.
|
||||
*/
|
||||
static void event_disconnect(ble_ans_c_t * p_ans, ble_evt_t const * p_ble_evt)
|
||||
{
|
||||
if (p_ans->conn_handle == p_ble_evt->evt.gap_evt.conn_handle)
|
||||
{
|
||||
p_ans->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
|
||||
// Clearing all data for the service also sets all handle values to @ref BLE_GATT_HANDLE_INVALID
|
||||
memset(&p_ans->service, 0, sizeof(ble_ans_c_service_t));
|
||||
|
||||
// If there was a valid instance of IAS on the peer, send an event to the
|
||||
// application, so that it can do any cleanup related to this module.
|
||||
ble_ans_c_evt_t evt;
|
||||
|
||||
evt.evt_type = BLE_ANS_C_EVT_DISCONN_COMPLETE;
|
||||
p_ans->evt_handler(&evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for handling of BLE stack events. */
|
||||
void ble_ans_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
|
||||
{
|
||||
ble_ans_c_t * p_ans = (ble_ans_c_t *)p_context;
|
||||
|
||||
switch (p_ble_evt->header.evt_id)
|
||||
{
|
||||
case BLE_GATTC_EVT_HVX:
|
||||
event_notify(p_ans, p_ble_evt);
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_READ_RSP:
|
||||
event_read_rsp(p_ans, p_ble_evt);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
event_disconnect(p_ans, p_ble_evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_init(ble_ans_c_t * p_ans, ble_ans_c_init_t const * p_ans_init)
|
||||
{
|
||||
VERIFY_PARAM_NOT_NULL(p_ans);
|
||||
VERIFY_PARAM_NOT_NULL(p_ans_init);
|
||||
VERIFY_PARAM_NOT_NULL(p_ans_init->evt_handler);
|
||||
VERIFY_PARAM_NOT_NULL(p_ans_init->p_gatt_queue);
|
||||
|
||||
// Clear all handles.
|
||||
memset(p_ans, 0, sizeof(ble_ans_c_t));
|
||||
p_ans->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
|
||||
p_ans->evt_handler = p_ans_init->evt_handler;
|
||||
p_ans->error_handler = p_ans_init->error_handler;
|
||||
p_ans->message_buffer_size = p_ans_init->message_buffer_size;
|
||||
p_ans->p_message_buffer = p_ans_init->p_message_buffer;
|
||||
p_ans->p_gatt_queue = p_ans_init->p_gatt_queue;
|
||||
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.service.uuid, BLE_UUID_ALERT_NOTIFICATION_SERVICE);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.new_alert.uuid, BLE_UUID_NEW_ALERT_CHAR);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.alert_notif_ctrl_point.uuid,
|
||||
BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.unread_alert_status.uuid, BLE_UUID_UNREAD_ALERT_CHAR);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.suported_new_alert_cat.uuid,
|
||||
BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.suported_unread_alert_cat.uuid,
|
||||
BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR);
|
||||
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.new_alert_cccd.uuid, BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG);
|
||||
BLE_UUID_BLE_ASSIGN(p_ans->service.unread_alert_cccd.uuid,
|
||||
BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG);
|
||||
|
||||
return ble_db_discovery_evt_register(&p_ans->service.service.uuid);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for creating a tx message for writing a CCCD.
|
||||
*/
|
||||
static uint32_t cccd_configure(ble_ans_c_t const * const p_ans,
|
||||
uint16_t handle_cccd,
|
||||
bool notification_enable)
|
||||
{
|
||||
nrf_ble_gq_req_t cccd_req;
|
||||
uint16_t cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : 0;
|
||||
uint8_t cccd[WRITE_MESSAGE_LENGTH];
|
||||
|
||||
memset(&cccd_req, 0, sizeof(nrf_ble_gq_req_t));
|
||||
|
||||
cccd[0] = LSB_16(cccd_val);
|
||||
cccd[1] = MSB_16(cccd_val);
|
||||
|
||||
cccd_req.type = NRF_BLE_GQ_REQ_GATTC_WRITE;
|
||||
cccd_req.error_handler.cb = gatt_error_handler;
|
||||
cccd_req.error_handler.p_ctx = (ble_ans_c_t *)p_ans;
|
||||
cccd_req.params.gattc_write.handle = handle_cccd;
|
||||
cccd_req.params.gattc_write.len = WRITE_MESSAGE_LENGTH;
|
||||
cccd_req.params.gattc_write.p_value = cccd;
|
||||
cccd_req.params.gattc_write.offset = 0;
|
||||
cccd_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;
|
||||
|
||||
return nrf_ble_gq_item_add(p_ans->p_gatt_queue, &cccd_req, p_ans->conn_handle);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_enable_notif_new_alert(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
if (p_ans->conn_handle == BLE_CONN_HANDLE_INVALID)
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cccd_configure(p_ans,
|
||||
p_ans->service.new_alert_cccd.handle,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_disable_notif_new_alert(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
return cccd_configure(p_ans,
|
||||
p_ans->service.new_alert_cccd.handle,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_enable_notif_unread_alert(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
if ( p_ans->conn_handle == BLE_CONN_HANDLE_INVALID)
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
return cccd_configure(p_ans,
|
||||
p_ans->service.unread_alert_cccd.handle,
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_disable_notif_unread_alert(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
return cccd_configure(p_ans,
|
||||
p_ans->service.unread_alert_cccd.handle,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_control_point_write(ble_ans_c_t const * p_ans,
|
||||
ble_ans_control_point_t const * p_control_point)
|
||||
{
|
||||
nrf_ble_gq_req_t gq_req;
|
||||
uint8_t write_data[WRITE_MESSAGE_LENGTH];
|
||||
|
||||
write_data[0] = p_control_point->command;
|
||||
write_data[1] = p_control_point->category;
|
||||
|
||||
memset(&gq_req, 0, sizeof(nrf_ble_gq_req_t));
|
||||
|
||||
gq_req.type = NRF_BLE_GQ_REQ_GATTC_WRITE;
|
||||
gq_req.error_handler.cb = gatt_error_handler;
|
||||
gq_req.error_handler.p_ctx = (ble_ans_c_t *)p_ans;
|
||||
gq_req.params.gattc_write.handle = p_ans->service.alert_notif_ctrl_point.handle_value;
|
||||
gq_req.params.gattc_write.len = WRITE_MESSAGE_LENGTH;
|
||||
gq_req.params.gattc_write.p_value = write_data;
|
||||
gq_req.params.gattc_write.offset = 0;
|
||||
gq_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;
|
||||
|
||||
return nrf_ble_gq_item_add(p_ans->p_gatt_queue, &gq_req, p_ans->conn_handle);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_new_alert_read(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
nrf_ble_gq_req_t gq_req;
|
||||
|
||||
memset(&gq_req, 0, sizeof(nrf_ble_gq_req_t));
|
||||
|
||||
gq_req.type = NRF_BLE_GQ_REQ_GATTC_READ;
|
||||
gq_req.error_handler.cb = gatt_error_handler;
|
||||
gq_req.error_handler.p_ctx = (ble_ans_c_t *)p_ans;
|
||||
gq_req.params.gattc_read.handle = p_ans->service.suported_new_alert_cat.handle_value;
|
||||
gq_req.params.gattc_read.offset = 0;
|
||||
|
||||
return nrf_ble_gq_item_add(p_ans->p_gatt_queue, &gq_req, p_ans->conn_handle);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_unread_alert_read(ble_ans_c_t const * p_ans)
|
||||
{
|
||||
nrf_ble_gq_req_t gq_req;
|
||||
|
||||
memset(&gq_req, 0, sizeof(nrf_ble_gq_req_t));
|
||||
|
||||
gq_req.type = NRF_BLE_GQ_REQ_GATTC_READ;
|
||||
gq_req.error_handler.cb = gatt_error_handler;
|
||||
gq_req.error_handler.p_ctx = (ble_ans_c_t *)p_ans;
|
||||
gq_req.params.gattc_read.handle = p_ans->service.suported_unread_alert_cat.handle_value;
|
||||
gq_req.params.gattc_read.offset = 0;
|
||||
|
||||
return nrf_ble_gq_item_add(p_ans->p_gatt_queue, &gq_req, p_ans->conn_handle);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_new_alert_notify(ble_ans_c_t const * p_ans, ble_ans_category_id_t category_id)
|
||||
{
|
||||
ble_ans_control_point_t control_point;
|
||||
|
||||
control_point.command = ANS_NOTIFY_NEW_INCOMING_ALERT_IMMEDIATELY;
|
||||
control_point.category = category_id;
|
||||
|
||||
return ble_ans_c_control_point_write(p_ans, &control_point);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_unread_alert_notify(ble_ans_c_t const * p_ans, ble_ans_category_id_t category_id)
|
||||
{
|
||||
ble_ans_control_point_t control_point;
|
||||
|
||||
control_point.command = ANS_NOTIFY_UNREAD_CATEGORY_STATUS_IMMEDIATELY;
|
||||
control_point.category = category_id;
|
||||
|
||||
return ble_ans_c_control_point_write(p_ans, &control_point);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ble_ans_c_handles_assign(ble_ans_c_t * p_ans,
|
||||
uint16_t conn_handle,
|
||||
ble_ans_c_service_t const * p_peer_handles)
|
||||
{
|
||||
VERIFY_PARAM_NOT_NULL(p_ans);
|
||||
|
||||
if (!is_valid_ans_srv_discovered(p_peer_handles))
|
||||
{
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
p_ans->conn_handle = conn_handle;
|
||||
|
||||
if (p_peer_handles != NULL)
|
||||
{
|
||||
// Copy the handles from the discovered characteristics to the provided client instance.
|
||||
char_set(&p_ans->service.alert_notif_ctrl_point, &p_peer_handles->alert_notif_ctrl_point);
|
||||
char_set(&p_ans->service.suported_new_alert_cat, &p_peer_handles->suported_new_alert_cat);
|
||||
char_set(&p_ans->service.suported_unread_alert_cat, &p_peer_handles->suported_unread_alert_cat);
|
||||
char_set(&p_ans->service.new_alert, &p_peer_handles->new_alert);
|
||||
char_cccd_set(&p_ans->service.new_alert_cccd, p_peer_handles->new_alert_cccd.handle);
|
||||
char_set(&p_ans->service.unread_alert_status, &p_peer_handles->unread_alert_status);
|
||||
char_cccd_set(&p_ans->service.unread_alert_cccd, p_peer_handles->unread_alert_cccd.handle);
|
||||
}
|
||||
|
||||
return nrf_ble_gq_conn_handle_register(p_ans->p_gatt_queue, conn_handle);
|
||||
}
|
||||
#endif // NRF_MODULE_ENABLED(BLE_ANS_C)
|
||||
418
components/ble/ble_services/ble_ans_c/ble_ans_c.h
Normal file
418
components/ble/ble_services/ble_ans_c/ble_ans_c.h
Normal file
@@ -0,0 +1,418 @@
|
||||
/**
|
||||
* Copyright (c) 2012 - 2020, 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.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ble_ans_c Alert Notification Service Client
|
||||
* @{
|
||||
* @ingroup ble_sdk_srv
|
||||
* @brief Alert Notification module.
|
||||
*
|
||||
* @details This module implements the Alert Notification Client according to the
|
||||
* Alert Notification Profile.
|
||||
*
|
||||
* @note The application must register this module as the BLE event observer by using the
|
||||
* NRF_SDH_BLE_OBSERVER macro. Example:
|
||||
* @code
|
||||
* ble_ans_c_t instance;
|
||||
* NRF_SDH_BLE_OBSERVER(anything, BLE_ANS_C_BLE_OBSERVER_PRIO,
|
||||
* ble_ans_c_on_ble_evt, &instance);
|
||||
* @endcode
|
||||
*
|
||||
* @note Attention!
|
||||
* To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
|
||||
* qualification listings, this section of source code must not be modified.
|
||||
*/
|
||||
#ifndef BLE_ANS_C_H__
|
||||
#define BLE_ANS_C_H__
|
||||
|
||||
#include "ble.h"
|
||||
#include "ble_gatts.h"
|
||||
#include "ble_types.h"
|
||||
#include "sdk_common.h"
|
||||
#include "ble_srv_common.h"
|
||||
#include "ble_db_discovery.h"
|
||||
#include "nrf_ble_gq.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Macro for defining a ble_ans_c instance.
|
||||
*
|
||||
* @param _name Name of the instance.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define BLE_ANS_C_DEF(_name) \
|
||||
static ble_ans_c_t _name; \
|
||||
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
|
||||
BLE_ANS_C_BLE_OBSERVER_PRIO, \
|
||||
ble_ans_c_on_ble_evt, &_name)
|
||||
|
||||
/** @brief Macro for defining multiple ble_ans_c instances.
|
||||
*
|
||||
* @param _name Name of the array of instances.
|
||||
* @param _cnt Number of instances to define.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define BLE_ANS_C_ARRAY_DEF(_name, _cnt) \
|
||||
static ble_ans_c_t _name[_cnt]; \
|
||||
NRF_SDH_BLE_OBSERVERS(_name ## _obs, \
|
||||
BLE_ANS_C_BLE_OBSERVER_PRIO, \
|
||||
ble_ans_c_on_ble_evt, &_name, _cnt)
|
||||
|
||||
// Forward declaration of the ble_ans_c_t type.
|
||||
typedef struct ble_ans_c_s ble_ans_c_t;
|
||||
|
||||
/** Alert types, as defined in the alert category ID. UUID: 0x2A43. */
|
||||
typedef enum
|
||||
{
|
||||
ANS_TYPE_SIMPLE_ALERT = 0, /**< General text alert or non-text alert.*/
|
||||
ANS_TYPE_EMAIL = 1, /**< Email message arrives.*/
|
||||
ANS_TYPE_NEWS = 2, /**< News feeds such as RSS, Atom.*/
|
||||
ANS_TYPE_NOTIFICATION_CALL = 3, /**< Incoming call.*/
|
||||
ANS_TYPE_MISSED_CALL = 4, /**< Missed call.*/
|
||||
ANS_TYPE_SMS_MMS = 5, /**< SMS or MMS message arrives.*/
|
||||
ANS_TYPE_VOICE_MAIL = 6, /**< Voice mail.*/
|
||||
ANS_TYPE_SCHEDULE = 7, /**< Alert that occurs on calendar, planner.*/
|
||||
ANS_TYPE_HIGH_PRIORITIZED_ALERT = 8, /**< Alert to be handled as high priority.*/
|
||||
ANS_TYPE_INSTANT_MESSAGE = 9, /**< Alert for incoming instant messages.*/
|
||||
ANS_TYPE_ALL_ALERTS = 0xFF /**< Identifies all alerts. */
|
||||
} ble_ans_category_id_t;
|
||||
|
||||
/** Alert notification control point commands, as defined in the Alert Notification Specification.
|
||||
* UUID: 0x2A44.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ANS_ENABLE_NEW_INCOMING_ALERT_NOTIFICATION = 0, /**< Enable New Incoming Alert Notification.*/
|
||||
ANS_ENABLE_UNREAD_CATEGORY_STATUS_NOTIFICATION = 1, /**< Enable Unread Category Status Notification.*/
|
||||
ANS_DISABLE_NEW_INCOMING_ALERT_NOTIFICATION = 2, /**< Disable New Incoming Alert Notification.*/
|
||||
ANS_DISABLE_UNREAD_CATEGORY_STATUS_NOTIFICATION = 3, /**< Disable Unread Category Status Notification.*/
|
||||
ANS_NOTIFY_NEW_INCOMING_ALERT_IMMEDIATELY = 4, /**< Notify New Incoming Alert immediately.*/
|
||||
ANS_NOTIFY_UNREAD_CATEGORY_STATUS_IMMEDIATELY = 5, /**< Notify Unread Category Status immediately.*/
|
||||
} ble_ans_command_id_t;
|
||||
|
||||
/**@brief Alert Notification Event types that are passed from client to the application on an event. */
|
||||
typedef enum
|
||||
{
|
||||
BLE_ANS_C_EVT_DISCOVERY_COMPLETE, /**< A successful connection is established and the characteristics of the server were fetched. */
|
||||
BLE_ANS_C_EVT_DISCOVERY_FAILED, /**< It was not possible to discover service or characteristics of the connected peer. */
|
||||
BLE_ANS_C_EVT_DISCONN_COMPLETE, /**< The connection is taken down. */
|
||||
BLE_ANS_C_EVT_NOTIFICATION, /**< A valid notification was received from the server.*/
|
||||
BLE_ANS_C_EVT_READ_RESP, /**< A read response was received from the server.*/
|
||||
BLE_ANS_C_EVT_WRITE_RESP /**< A write response was received from the server.*/
|
||||
} ble_ans_c_evt_type_t;
|
||||
|
||||
/**@brief Alert Notification Control Point structure. */
|
||||
typedef struct
|
||||
{
|
||||
ble_ans_command_id_t command; /**< The command to be written to the control point. See @ref ble_ans_command_id_t. */
|
||||
ble_ans_category_id_t category; /**< The category for the control point for which the command applies. See @ref ble_ans_category_id_t. */
|
||||
} ble_ans_control_point_t;
|
||||
|
||||
/**@brief Alert Notification Setting structure containing the supported alerts in the service.
|
||||
*
|
||||
*@details
|
||||
* The structure contains bit fields that describe which alerts are supported:
|
||||
* - 0 = Unsupported
|
||||
* - 1 = Supported
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t ans_simple_alert_support : 1; /**< Support for general text alert or non-text alert.*/
|
||||
uint8_t ans_email_support : 1; /**< Support for alert when an email message arrives.*/
|
||||
uint8_t ans_news_support : 1; /**< Support for news feeds such as RSS, Atom.*/
|
||||
uint8_t ans_notification_call_support : 1; /**< Support for incoming call.*/
|
||||
uint8_t ans_missed_call_support : 1; /**< Support for missed call.*/
|
||||
uint8_t ans_sms_mms_support : 1; /**< Support for SMS or MMS message arrival.*/
|
||||
uint8_t ans_voice_mail_support : 1; /**< Support for voice mail.*/
|
||||
uint8_t ans_schedule_support : 1; /**< Support for alert that occurs on calendar or planner.*/
|
||||
uint8_t ans_high_prioritized_alert_support : 1; /**< Support for alert that should be handled as high priority.*/
|
||||
uint8_t ans_instant_message_support : 1; /**< Support for alert for incoming instant messages.*/
|
||||
uint8_t reserved : 6; /**< Reserved for future use. */
|
||||
} ble_ans_alert_settings_t;
|
||||
|
||||
/**@brief Alert Notification structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t alert_category; /**< Alert category to which this alert belongs.*/
|
||||
uint8_t alert_category_count; /**< Number of alerts in the category. */
|
||||
uint32_t alert_msg_length; /**< Length of the optional text message sent by the server. */
|
||||
uint8_t * p_alert_msg_buf; /**< Pointer to the buffer that contains the optional text message. */
|
||||
} ble_ans_alert_notification_t;
|
||||
|
||||
/**@brief Structure for holding information on the Alert Notification Service, if found on the server. */
|
||||
typedef struct
|
||||
{
|
||||
ble_gattc_service_t service; /**< The GATT service that holds the discovered Alert Notification Service. */
|
||||
ble_gattc_char_t alert_notif_ctrl_point; /**< Characteristic for the Alert Notification Control Point. See @ref BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR. */
|
||||
ble_gattc_char_t suported_new_alert_cat; /**< Characteristic for the Supported New Alert category. See @ref BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR. */
|
||||
ble_gattc_char_t suported_unread_alert_cat; /**< Characteristic for the Unread Alert category. See @ref BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR. */
|
||||
ble_gattc_char_t new_alert; /**< Characteristic for the New Alert Notification. See @ref BLE_UUID_NEW_ALERT_CHAR. */
|
||||
ble_gattc_desc_t new_alert_cccd; /**< Characteristic Descriptor for the New Alert category. Enables or disables GATT notifications. */
|
||||
ble_gattc_char_t unread_alert_status; /**< Characteristic for the Unread Alert Notification. See @ref BLE_UUID_UNREAD_ALERT_CHAR. */
|
||||
ble_gattc_desc_t unread_alert_cccd; /**< Characteristic Descriptor for the Unread Alert category. Enables or disables GATT notifications */
|
||||
} ble_ans_c_service_t;
|
||||
|
||||
/**@brief Alert Notification Event structure
|
||||
*
|
||||
* @details Structure for holding information about the event that should be handled, as well as
|
||||
* additional information.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ble_ans_c_evt_type_t evt_type; /**< Type of event. */
|
||||
uint16_t conn_handle; /**< Connection handle on which the ANS service was discovered on the peer device. This is filled if the evt_type is @ref BLE_ANS_C_EVT_DISCOVERY_COMPLETE.*/
|
||||
ble_uuid_t uuid; /**< UUID of the event in case of an alert or notification. */
|
||||
union
|
||||
{
|
||||
ble_ans_alert_settings_t settings; /**< Setting returned from server on read request. */
|
||||
ble_ans_alert_notification_t alert; /**< Alert Notification data sent by the server. */
|
||||
uint32_t error_code; /**< Additional status or error code, if the event is caused by a stack error or GATT status, for example during service discovery. */
|
||||
ble_ans_c_service_t service; /**< Information on the discovered Alert Notification Service. This is filled if the evt_type is @ref BLE_ANS_C_EVT_DISCOVERY_COMPLETE.*/
|
||||
} data;
|
||||
} ble_ans_c_evt_t;
|
||||
|
||||
/**@brief Alert Notification event handler type. */
|
||||
typedef void (*ble_ans_c_evt_handler_t) (ble_ans_c_evt_t * p_evt);
|
||||
|
||||
/**@brief Alert Notification structure. Contains various status information for the client. */
|
||||
struct ble_ans_c_s
|
||||
{
|
||||
ble_ans_c_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Alert Notification Client Application. */
|
||||
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
|
||||
uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack; if not in a connection, the handle is BLE_CONN_HANDLE_INVALID). */
|
||||
uint8_t central_handle; /**< Handle for the currently connected central, if peer is bonded. */
|
||||
uint8_t service_handle; /**< Handle for the service in the database to be used for this instance. */
|
||||
uint32_t message_buffer_size; /**< Size of the message buffer to hold the additional text messages received on notifications. */
|
||||
uint8_t * p_message_buffer; /**< Pointer to the buffer to be used for additional text message handling. */
|
||||
ble_ans_c_service_t service; /**< Struct to store different handles and UUIDs related to the service. */
|
||||
nrf_ble_gq_t * p_gatt_queue; /**< Pointer to the BLE GATT Queue instance. */
|
||||
};
|
||||
|
||||
/**@brief Alert Notification init structure. Contains all options and data needed for
|
||||
* the initialization of the client.*/
|
||||
typedef struct
|
||||
{
|
||||
ble_ans_c_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
|
||||
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
|
||||
uint32_t message_buffer_size; /**< Size of the buffer to handle messages. */
|
||||
uint8_t * p_message_buffer; /**< Pointer to the buffer for passing messages. */
|
||||
nrf_ble_gq_t * p_gatt_queue; /**< Pointer to the BLE GATT Queue instance. */
|
||||
} ble_ans_c_init_t;
|
||||
|
||||
|
||||
/**@brief Function for handling events from the Database Discovery module.
|
||||
*
|
||||
* @details Call this function when you get a callback event from the Database Discovery module.
|
||||
* This function handles an event from the Database Discovery module and determines
|
||||
* whether it relates to the discovery of Heart Rate Service at the peer. If it does, this function
|
||||
* calls the application's event handler to indicate that the Heart Rate Service was
|
||||
* discovered at the peer. The function also populates the event with service-related
|
||||
* information before providing it to the application.
|
||||
*
|
||||
* @param[in] p_ans Pointer to the Alert Notification client structure instance that will handle
|
||||
* the discovery.
|
||||
* @param[in] p_evt Pointer to the event received from the Database Discovery module.
|
||||
*/
|
||||
void ble_ans_c_on_db_disc_evt(ble_ans_c_t * p_ans, ble_db_discovery_evt_t const * p_evt);
|
||||
|
||||
|
||||
/**@brief Function for handling the application's BLE stack events.
|
||||
*
|
||||
* @details Handles all events from the BLE stack of interest to the Alert Notification Client.
|
||||
*
|
||||
* @param[in] p_ble_evt Event received from the BLE stack.
|
||||
* @param[in] p_context Alert Notification Client structure.
|
||||
*/
|
||||
void ble_ans_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
|
||||
|
||||
|
||||
/**@brief Function for initializing the Alert Notification Client.
|
||||
*
|
||||
* @param[out] p_ans Alert Notification Client structure. This structure must be
|
||||
* supplied by the application. It is initialized by this function,
|
||||
* and is later used to identify this particular client instance.
|
||||
* @param[in] p_ans_init Information needed to initialize the client.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful initialization of client. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_init(ble_ans_c_t * p_ans, ble_ans_c_init_t const * p_ans_init);
|
||||
|
||||
|
||||
/**@brief Function for writing the to CCCD to enable new alert notifications from the Alert Notification Service.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful writing of the CCCD. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_enable_notif_new_alert(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for writing to the CCCD to enable unread alert notifications from the Alert Notification Service.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful writing of the CCCD. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_enable_notif_unread_alert(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for writing to the CCCD to disable new alert notifications from the Alert Notification Service.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful writing of the CCCD. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_disable_notif_new_alert(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for writing to the CCCD to disable unread alert notifications from the Alert Notification Service.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful writing of the CCCD, otherwise an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_disable_notif_unread_alert(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for writing to the Alert Notification Control Point to specify alert notification behavior in the
|
||||
* Alert Notification Service on the Central.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be
|
||||
* supplied by the application. It identifies the particular client
|
||||
* instance to use.
|
||||
* @param[in] p_control_point Alert Notification Control Point structure. This structure
|
||||
* specifies the values to write to the Alert Notification Control
|
||||
* Point (UUID 0x2A44).
|
||||
*
|
||||
* @return NRF_SUCCESS on successful writing of the Control Point. Otherwise,
|
||||
* this API propagates the error code returned by function
|
||||
* @ref nrf_ble_gq_item_add.
|
||||
*/
|
||||
uint32_t ble_ans_c_control_point_write(ble_ans_c_t const * p_ans,
|
||||
ble_ans_control_point_t const * p_control_point);
|
||||
|
||||
|
||||
/**@brief Function for reading the Supported New Alert characteristic value of the service.
|
||||
* The value describes the alerts supported in the central.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful transmission of the read request. Otherwise,
|
||||
* this API propagates the error code returned by function
|
||||
* @ref nrf_ble_gq_item_add.
|
||||
*/
|
||||
uint32_t ble_ans_c_new_alert_read(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for reading the Supported Unread Alert characteristic value of the service.
|
||||
* The value describes the alerts supported in the central.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful transmission of the read request. Otherwise,
|
||||
* this API propagates the error code returned by function
|
||||
* @ref nrf_ble_gq_item_add.
|
||||
*/
|
||||
uint32_t ble_ans_c_unread_alert_read(ble_ans_c_t const * p_ans);
|
||||
|
||||
|
||||
/**@brief Function for requesting the peer to notify the New Alert characteristics immediately.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
* @param[in] category The category ID for which the peer should notify the client.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful transmission of the read request. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_new_alert_notify(ble_ans_c_t const * p_ans, ble_ans_category_id_t category);
|
||||
|
||||
|
||||
/**@brief Function for requesting the peer to notify the Unread Alert characteristics immediately.
|
||||
*
|
||||
* @param[in] p_ans Alert Notification structure. This structure must be supplied by
|
||||
* the application. It identifies the particular client instance to use.
|
||||
* @param[in] category The category ID for which the peer should notify the client.
|
||||
*
|
||||
* @return NRF_SUCCESS on successful transmission of the read request. Otherwise, it returns an error code.
|
||||
*/
|
||||
uint32_t ble_ans_c_unread_alert_notify(ble_ans_c_t const * p_ans, ble_ans_category_id_t category);
|
||||
|
||||
|
||||
/**@brief Function for assigning handles to an instance of ans_c.
|
||||
*
|
||||
* @details Call this function when a link has been established with a peer to
|
||||
* associate the link to an instance of the module. This makes it possible
|
||||
* to handle several links and associate each link to a particular
|
||||
* instance of the ans_c module. The connection handle and attribute handles
|
||||
* are provided from the discovery event @ref BLE_ANS_C_EVT_DISCOVERY_COMPLETE.
|
||||
*
|
||||
* @param[in] p_ans Pointer to the Alert Notification client structure instance to
|
||||
* associate with the handles.
|
||||
* @param[in] conn_handle Connection handle to associated with the given Alert Notification Client
|
||||
* Instance.
|
||||
* @param[in] p_peer_handles Attribute handles on the ANS server that you want this ANS client to
|
||||
* interact with.
|
||||
*
|
||||
*/
|
||||
uint32_t ble_ans_c_handles_assign(ble_ans_c_t * p_ans,
|
||||
uint16_t const conn_handle,
|
||||
ble_ans_c_service_t const * p_peer_handles);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // BLE_ANS_C_H__
|
||||
|
||||
/** @} */
|
||||
|
||||
Reference in New Issue
Block a user