Microchip® Advanced Software Framework

hr_sensor.c File Reference

Heart Rate Sensor Profile.

Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <string.h>
#include "timer_hw.h"
#include "at_ble_api.h"
#include "ble_manager.h"
#include "device_info.h"
#include "heart_rate.h"
#include "hr_sensor.h"
#include "ble_utils.h"

Functions

void hr_sensor_adv (void)
 hr_sensor_adv adds the advertisement data of the profile and starts advertisement More...
 
at_ble_status_t hr_sensor_char_changed_handler (void *params)
 hr_sensor_char_changed_handler called by the ble manager after a change in the characteristic More...
 
at_ble_status_t hr_sensor_char_write_request (void *params)
 hr_sensor_char_write_request handles the write request for heart rate control point characteristic. More...
 
at_ble_status_t hr_sensor_connected_state_handler (void *params)
 hr_sensor_connected_state_handler called by ble manager after a change in characteristic More...
 
void hr_sensor_disconnect (void)
 hr_sensor_disconnect disconnects with the peer device called by the application More...
 
at_ble_status_t hr_sensor_disconnect_event_handler (void *disconnect)
 hr_sensor_disconnect_event_handler called by ble manager after disconnection event recieved More...
 
void hr_sensor_init (void *param)
 hr_sensor_init initializes and defines the services of the hr profile More...
 
at_ble_status_t hr_sensor_notification_cfm_handler (void *params)
 hr_notification_confirmation_handler called on notification confirmation event by the ble manager More...
 
bool hr_sensor_send_notification (uint8_t *hr_data, uint8_t length)
 hr_sensor_send_notification adds the new characteristic value and sends the notification More...
 
void hr_sensor_service_define (void)
 hr_sensor_service_define defines the services of the profile More...
 
void hr_sensor_service_init (void)
 Initialization of profile services. More...
 
void register_hr_notification_handler (hr_notification_callback_t hr_notificaton_handler)
 register_hr_notification_handler registers the notification handler passed by the application param[in] hr_notification_callback_t address of the notification handler function to be called More...
 
void register_hr_reset_handler (hr_reset_callback_t hr_reset_handler)
 register_hr_reset_handler registers the reset handler passed by the application More...
 

Variables

at_ble_handle_t connection_handle
 contains the connection handle functions More...
 
dis_gatt_service_handler_t dis_service_handler
 device information service handler More...
 
static const ble_gap_event_cb_t hr_sensor_gap_handle
 
static const
ble_gatt_server_event_cb_t 
hr_sensor_gatt_server_handle
 
hr_gatt_service_handler_t hr_service_handler
 heart rate measurement service handler More...
 
hr_notification_callback_t notification_cb
 callback functions pointers contains the address of application functions More...
 
bool notification_confirm = true
 
hr_reset_callback_t reset_cb
 
uint8_t scan_rsp_data [SCAN_RESP_LEN] = {0x09, 0xff, 0x00, 0x06, 0xd6, 0xb2, 0xf0, 0x05, 0xf0, 0xf8}
 Scan response data. More...
 

void hr_sensor_adv ( void  )

hr_sensor_adv adds the advertisement data of the profile and starts advertisement

References AT_BLE_ADV_FP_ANY, AT_BLE_ADV_GEN_DISCOVERABLE, at_ble_adv_start(), AT_BLE_ADV_TYPE_UNDIRECTED, AT_BLE_SUCCESS, DBG_LOG, HR_SENSOR_FAST_ADV, and NULL.

Referenced by hr_sensor_app_custom_event().

at_ble_status_t hr_sensor_char_changed_handler ( void *  params)

hr_sensor_char_changed_handler called by the ble manager after a change in the characteristic

Parameters
[in]at_ble_characteristic_changed_twhich contains handle of characteristic and new value
Returns
AT_BLE_SUCCESS on success and AT_BLE_FAILURE on failure

References AT_BLE_SUCCESS, HR_CONTROL_POINT_RESET, HR_NOTIFICATION_DISABLE, HR_NOTIFICATION_ENABLE, hr_write_value_handler(), notification_cb, and reset_cb.

at_ble_status_t hr_sensor_char_write_request ( void *  params)
at_ble_status_t hr_sensor_connected_state_handler ( void *  params)

hr_sensor_connected_state_handler called by ble manager after a change in characteristic

Parameters
[in]at_ble_connected_twhich has connection handle and the peer device address

References AT_BLE_SUCCESS, connection_handle, and at_ble_connected_t::handle.

void hr_sensor_disconnect ( void  )

hr_sensor_disconnect disconnects with the peer device called by the application

References at_ble_disconnect(), AT_BLE_SUCCESS, AT_BLE_TERMINATED_BY_USER, connection_handle, and DBG_LOG.

Referenced by hr_sensor_app_custom_event().

at_ble_status_t hr_sensor_disconnect_event_handler ( void *  disconnect)

hr_sensor_disconnect_event_handler called by ble manager after disconnection event recieved

Parameters
[in]at_ble_disconnected_twhich has connection handle and reason for disconnection

References ALL_UNUSED, and AT_BLE_SUCCESS.

at_ble_status_t hr_sensor_notification_cfm_handler ( void *  params)

hr_notification_confirmation_handler called on notification confirmation event by the ble manager

hr_sensor_notification_cfm_handler called on notification confirmation event by the ble manager

Parameters
[in]at_ble_status_tAT_BLE_SUCCESS on success AT_BLE_FAILURE on failure called

References AT_BLE_SUCCESS, DBG_LOG_DEV, and at_ble_cmd_complete_event_t::status.

bool hr_sensor_send_notification ( uint8_t *  hr_data,
uint8_t  length 
)

hr_sensor_send_notification adds the new characteristic value and sends the notification

Parameters
[in]hr_datathe new hr characteristic value needs to be updated
[in]lengthlength of new characteristic value

Updating the new characteristic value

Sending the notification for the updated characteristic

References at_ble_characteristic_value_set(), at_ble_notification_send(), AT_BLE_SUCCESS, at_ble_characteristic_t::char_val_handle, connection_handle, DBG_LOG, and hr_gatt_service_handler::serv_chars.

Referenced by hr_measurment_send().

void hr_sensor_service_define ( void  )

hr_sensor_service_define defines the services of the profile

References AT_BLE_SUCCESS, DBG_LOG, DBG_LOG_DEV, dis_primary_service_define(), and hr_primary_service_define().

Referenced by hr_sensor_init().

void hr_sensor_service_init ( void  )

Initialization of profile services.

hr_sensor_service_init initializes the services of the profile

References dis_init_service(), and hr_init_service().

Referenced by hr_sensor_init().

void register_hr_notification_handler ( hr_notification_callback_t  hr_notificaton_handler)

register_hr_notification_handler registers the notification handler passed by the application param[in] hr_notification_callback_t address of the notification handler function to be called

References notification_cb.

Referenced by main().

void register_hr_reset_handler ( hr_reset_callback_t  hr_reset_handler)

register_hr_reset_handler registers the reset handler passed by the application

Parameters
[in]hr_reset_callback_taddress of the handler function to be called

References reset_cb.

Referenced by main().

at_ble_handle_t connection_handle

contains the connection handle functions

dis_gatt_service_handler_t dis_service_handler

device information service handler

const ble_gap_event_cb_t hr_sensor_gap_handle
static
Initial value:
= {
}
at_ble_status_t hr_sensor_connected_state_handler(void *params)
hr_sensor_connected_state_handler called by ble manager after a change in characteristic ...
Definition: hr_sensor.c:232
at_ble_status_t hr_sensor_disconnect_event_handler(void *disconnect)
hr_sensor_disconnect_event_handler called by ble manager after disconnection event recieved ...
Definition: hr_sensor.c:220
const ble_gatt_server_event_cb_t hr_sensor_gatt_server_handle
static
Initial value:
= {
.notification_confirmed = hr_sensor_notification_cfm_handler,
.characteristic_changed = hr_sensor_char_changed_handler,
.write_authorize_request = hr_sensor_char_write_request
}
at_ble_status_t hr_sensor_notification_cfm_handler(void *params)
hr_notification_confirmation_handler called on notification confirmation event by the ble manager ...
Definition: hr_sensor.c:145
at_ble_status_t hr_sensor_char_write_request(void *params)
hr_sensor_char_write_request handles the write request for heart rate control point characteristic...
Definition: hr_sensor.c:116
at_ble_status_t hr_sensor_char_changed_handler(void *params)
hr_sensor_char_changed_handler called by the ble manager after a change in the characteristic ...
Definition: hr_sensor.c:193
hr_gatt_service_handler_t hr_service_handler

heart rate measurement service handler

hr_notification_callback_t notification_cb

callback functions pointers contains the address of application functions

bool notification_confirm = true
uint8_t scan_rsp_data[SCAN_RESP_LEN] = {0x09, 0xff, 0x00, 0x06, 0xd6, 0xb2, 0xf0, 0x05, 0xf0, 0xf8}

Scan response data.