Nordic Semiconductor nRF5 AirFuel SDK
version 2.2.0
|
#include <stdlib.h>
#include "app_profile.h"
#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "app_error.h"
#include "ble.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_bas.h"
#include "ble_hrs.h"
#include "ble_dis.h"
#include "ble_conn_params.h"
#include "boards.h"
#include "sensorsim.h"
#include "softdevice_handler.h"
#include "app_timer.h"
#include "device_manager.h"
#include "pstorage.h"
#include "app_trace.h"
#include "bsp.h"
#include "nrf_delay.h"
#include "bsp_btn_ble.h"
#include "app_gpiote.h"
Go to the source code of this file.
Functions | |
APP_TIMER_DEF (m_battery_timer_id) | |
APP_TIMER_DEF (m_heart_rate_timer_id) | |
APP_TIMER_DEF (m_rr_interval_timer_id) | |
APP_TIMER_DEF (m_sensor_contact_timer_id) | |
static void | battery_level_update (void) |
Function for performing battery measurement and updating the Battery Level characteristic in Battery Service. | |
static void | battery_level_meas_timeout_handler (void *p_context) |
Function for handling the Battery measurement timer timeout. More... | |
static void | heart_rate_meas_timeout_handler (void *p_context) |
Function for handling the Heart rate measurement timer timeout. More... | |
static void | rr_interval_timeout_handler (void *p_context) |
Function for handling the RR interval timer timeout. More... | |
static void | sensor_contact_detected_timeout_handler (void *p_context) |
Function for handling the Sensor Contact Detected timer timeout. More... | |
static void | timers_init (void) |
Function for the Timer initialization. More... | |
static void | gap_params_init (void) |
Function for the GAP initialization. More... | |
static void | advertising_stop (void) |
Function for stopping advertising. | |
static void | reset_prepare (void) |
Function for preparing for system reset. | |
static void | services_init (void) |
Function for initializing services that will be used by the application. More... | |
static void | sensor_simulator_init (void) |
Function for initializing the sensor simulators. | |
static void | application_timers_start (void) |
Function for starting application timers. | |
static void | on_conn_params_evt (ble_conn_params_evt_t *p_evt) |
Function for handling the Connection Parameters Module. More... | |
static void | conn_params_error_handler (uint32_t nrf_error) |
Function for handling a Connection Parameters error. More... | |
static void | conn_params_init (void) |
Function for initializing the Connection Parameters module. | |
static void | sleep_mode_enter (void) |
Function for putting the chip into sleep mode. More... | |
static void | on_adv_evt (ble_adv_evt_t ble_adv_evt) |
Function for handling advertising events. More... | |
static void | on_ble_evt (ble_evt_t *p_ble_evt) |
Function for handling the Application's BLE Stack events. More... | |
static void | ble_evt_dispatch (ble_evt_t *p_ble_evt) |
Function for dispatching a BLE stack event to all modules with a BLE stack event handler. More... | |
static void | sys_evt_dispatch (uint32_t sys_evt) |
Function for dispatching a system event to interested modules. More... | |
void | bsp_event_handler (bsp_event_t event) |
Function for handling events from the BSP module. More... | |
static uint32_t | device_manager_evt_handler (dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result) |
Function for handling the Device Manager events. More... | |
static void | device_manager_init (bool erase_bonds) |
Function for the Device Manager initialization. More... | |
static void | advertising_init (void) |
Function for initializing the Advertising functionality. | |
void | app_profile_init (void) |
Initialize profile. Is only called once. | |
void | app_profile_on_ble_evt (ble_evt_t *p_ble_evt) |
Handle BLE event. More... | |
void | app_profile_on_sys_evt (uint32_t sys_evt) |
Handle system event. More... | |
void | app_profile_start (void) |
Start profile. Is called every time profile is activated. | |
void | app_profile_stop (void) |
Stop profile. Note: Needs to set the softdevice in a state where it is ok to initialize PRU profile. | |
Variables | |
static uint16_t | m_conn_handle = BLE_CONN_HANDLE_INVALID |
static ble_bas_t | m_bas |
static ble_hrs_t | m_hrs |
static bool | m_rr_interval_enabled = true |
static sensorsim_cfg_t | m_battery_sim_cfg |
static sensorsim_state_t | m_battery_sim_state |
static sensorsim_cfg_t | m_heart_rate_sim_cfg |
static sensorsim_state_t | m_heart_rate_sim_state |
static sensorsim_cfg_t | m_rr_interval_sim_cfg |
static sensorsim_state_t | m_rr_interval_sim_state |
static dm_application_instance_t | m_app_handle |
static ble_uuid_t | m_adv_uuids [] |
#define IS_SRVC_CHANGED_CHARACT_PRESENT 1 |
Include or not the service_changed characteristic. if not enabled, the server's database cannot be changed for the lifetime of the device
Definition at line 43 of file ble_app_hrs.c.
#define DEVICE_NAME "Nordic_HRM" |
Name of device. Will be included in the advertising data.
Definition at line 45 of file ble_app_hrs.c.
#define MANUFACTURER_NAME "NordicSemiconductor" |
Manufacturer. Will be passed to Device Information Service.
Definition at line 46 of file ble_app_hrs.c.
#define APP_ADV_INTERVAL 300 |
The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms).
Definition at line 47 of file ble_app_hrs.c.
#define APP_ADV_TIMEOUT_IN_SECONDS 180 |
The advertising timeout in units of seconds.
Definition at line 48 of file ble_app_hrs.c.
#define APP_TIMER_PRESCALER 0 |
Value of the RTC1 PRESCALER register.
Definition at line 50 of file ble_app_hrs.c.
#define APP_PROFILE_MAX_TIMERS (4+BSP_APP_TIMERS_NUMBER) |
Maximum number of simultaneously created timers.
Definition at line 51 of file ble_app_hrs.c.
#define APP_TIMER_OP_QUEUE_SIZE 4 |
Size of timer operation queues.
Definition at line 52 of file ble_app_hrs.c.
#define BATTERY_LEVEL_MEAS_INTERVAL APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER) |
Battery level measurement interval (ticks).
Definition at line 54 of file ble_app_hrs.c.
#define MIN_BATTERY_LEVEL 81 |
Minimum simulated battery level.
Definition at line 55 of file ble_app_hrs.c.
#define MAX_BATTERY_LEVEL 100 |
Maximum simulated battery level.
Definition at line 56 of file ble_app_hrs.c.
#define BATTERY_LEVEL_INCREMENT 1 |
Increment between each simulated battery level measurement.
Definition at line 57 of file ble_app_hrs.c.
#define HEART_RATE_MEAS_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) |
Heart rate measurement interval (ticks).
Definition at line 59 of file ble_app_hrs.c.
#define MIN_HEART_RATE 140 |
Minimum heart rate as returned by the simulated measurement function.
Definition at line 60 of file ble_app_hrs.c.
#define MAX_HEART_RATE 300 |
Maximum heart rate as returned by the simulated measurement function.
Definition at line 61 of file ble_app_hrs.c.
#define HEART_RATE_INCREMENT 10 |
Value by which the heart rate is incremented/decremented for each call to the simulated measurement function.
Definition at line 62 of file ble_app_hrs.c.
#define RR_INTERVAL_INTERVAL APP_TIMER_TICKS(300, APP_TIMER_PRESCALER) |
RR interval interval (ticks).
Definition at line 64 of file ble_app_hrs.c.
#define MIN_RR_INTERVAL 100 |
Minimum RR interval as returned by the simulated measurement function.
Definition at line 65 of file ble_app_hrs.c.
#define MAX_RR_INTERVAL 500 |
Maximum RR interval as returned by the simulated measurement function.
Definition at line 66 of file ble_app_hrs.c.
#define RR_INTERVAL_INCREMENT 1 |
Value by which the RR interval is incremented/decremented for each call to the simulated measurement function.
Definition at line 67 of file ble_app_hrs.c.
#define SENSOR_CONTACT_DETECTED_INTERVAL APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) |
Sensor Contact Detected toggle interval (ticks).
Definition at line 69 of file ble_app_hrs.c.
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(400, UNIT_1_25_MS) |
Minimum acceptable connection interval (0.4 seconds).
Definition at line 71 of file ble_app_hrs.c.
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(650, UNIT_1_25_MS) |
Maximum acceptable connection interval (0.65 second).
Definition at line 72 of file ble_app_hrs.c.
#define SLAVE_LATENCY 0 |
Slave latency.
Definition at line 73 of file ble_app_hrs.c.
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) |
Connection supervisory timeout (4 seconds).
Definition at line 74 of file ble_app_hrs.c.
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).
Definition at line 76 of file ble_app_hrs.c.
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER) |
Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds).
Definition at line 77 of file ble_app_hrs.c.
#define MAX_CONN_PARAMS_UPDATE_COUNT 3 |
Number of attempts before giving up the connection parameter negotiation.
Definition at line 78 of file ble_app_hrs.c.
#define SEC_PARAM_BOND 1 |
Perform bonding.
Definition at line 80 of file ble_app_hrs.c.
#define SEC_PARAM_MITM 0 |
Man In The Middle protection not required.
Definition at line 81 of file ble_app_hrs.c.
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE |
No I/O capabilities.
Definition at line 82 of file ble_app_hrs.c.
#define SEC_PARAM_OOB 0 |
Out Of Band data not available.
Definition at line 83 of file ble_app_hrs.c.
#define SEC_PARAM_MIN_KEY_SIZE 7 |
Minimum encryption key size.
Definition at line 84 of file ble_app_hrs.c.
#define SEC_PARAM_MAX_KEY_SIZE 16 |
Maximum encryption key size.
Definition at line 85 of file ble_app_hrs.c.
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
Definition at line 87 of file ble_app_hrs.c.
APP_TIMER_DEF | ( | m_battery_timer_id | ) |
Battery timer.
APP_TIMER_DEF | ( | m_heart_rate_timer_id | ) |
Heart rate measurement timer.
APP_TIMER_DEF | ( | m_rr_interval_timer_id | ) |
RR interval timer.
APP_TIMER_DEF | ( | m_sensor_contact_timer_id | ) |
Sensor contact detected timer.
|
static |
Function for handling the Battery measurement timer timeout.
This function will be called each time the battery level measurement timer expires.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
Definition at line 141 of file ble_app_hrs.c.
|
static |
Function for handling the Heart rate measurement timer timeout.
This function will be called each time the heart rate measurement timer expires. It will exclude RR Interval data from every third measurement.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
Definition at line 156 of file ble_app_hrs.c.
|
static |
Function for handling the RR interval timer timeout.
This function will be called each time the RR interval timer expires.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
Definition at line 191 of file ble_app_hrs.c.
|
static |
Function for handling the Sensor Contact Detected timer timeout.
This function will be called each time the Sensor Contact Detected timer expires.
[in] | p_context | Pointer used for passing some arbitrary information (context) from the app_start_timer() call to the timeout handler. |
Definition at line 213 of file ble_app_hrs.c.
|
static |
Function for the Timer initialization.
Initializes the timer module. This creates and starts application timers.
Definition at line 228 of file ble_app_hrs.c.
|
static |
Function for the GAP initialization.
This function sets up all the necessary GAP (Generic Access Profile) parameters of the device including the device name, appearance, and the preferred connection parameters.
Definition at line 260 of file ble_app_hrs.c.
|
static |
Function for initializing services that will be used by the application.
Initialize the Heart Rate, Battery and Device Information services.
Definition at line 332 of file ble_app_hrs.c.
|
static |
Function for handling the Connection Parameters Module.
This function will be called for all events in the Connection Parameters Module which are passed to the application.
[in] | p_evt | Event received from the Connection Parameters Module. |
Definition at line 450 of file ble_app_hrs.c.
|
static |
Function for handling a Connection Parameters error.
[in] | nrf_error | Error code containing information about what went wrong. |
Definition at line 466 of file ble_app_hrs.c.
|
static |
Function for putting the chip into sleep mode.
Definition at line 499 of file ble_app_hrs.c.
|
static |
Function for handling advertising events.
This function will be called for advertising events which are passed to the application.
[in] | ble_adv_evt | Advertising event. |
Definition at line 520 of file ble_app_hrs.c.
|
static |
Function for handling the Application's BLE Stack events.
[in] | p_ble_evt | Bluetooth stack event. |
Definition at line 543 of file ble_app_hrs.c.
|
static |
Function for dispatching a BLE stack event to all modules with a BLE stack event handler.
This function is called from the BLE Stack event interrupt handler after a BLE stack event has been received.
[in] | p_ble_evt | Bluetooth stack event. |
Definition at line 573 of file ble_app_hrs.c.
|
static |
Function for dispatching a system event to interested modules.
This function is called from the System event interrupt handler after a system event has been received.
[in] | sys_evt | System stack event. |
Definition at line 592 of file ble_app_hrs.c.
void bsp_event_handler | ( | bsp_event_t | event | ) |
Function for handling events from the BSP module.
[in] | event | Event generated by button press. |
Definition at line 604 of file ble_app_hrs.c.
|
static |
Function for handling the Device Manager events.
[in] | p_handle | Device manager handle |
[in] | p_event | Device manager event |
[out] | event_result | Result |
Definition at line 642 of file ble_app_hrs.c.
|
static |
Function for the Device Manager initialization.
[in] | erase_bonds | Indicates whether bonding information should be cleared from persistent storage during initialization of the Device Manager. |
Definition at line 657 of file ble_app_hrs.c.
void app_profile_on_ble_evt | ( | ble_evt_t * | p_ble_evt | ) |
Handle BLE event.
[in] | p_ble_evt | BLE event to handle. |
Definition at line 726 of file ble_app_hrs.c.
void app_profile_on_sys_evt | ( | uint32_t | sys_evt | ) |
Handle system event.
sys_evt | System event to handle. |
Definition at line 731 of file ble_app_hrs.c.
|
static |
Handle of the current connection.
Definition at line 89 of file ble_app_hrs.c.
|
static |
Structure used to identify the battery service.
Definition at line 90 of file ble_app_hrs.c.
|
static |
Structure used to identify the heart rate service.
Definition at line 91 of file ble_app_hrs.c.
|
static |
Flag for enabling and disabling the registration of new RR interval measurements (the purpose of disabling this is just to test sending HRM without RR interval data.
Definition at line 92 of file ble_app_hrs.c.
|
static |
Battery Level sensor simulator configuration.
Definition at line 94 of file ble_app_hrs.c.
|
static |
Battery Level sensor simulator state.
Definition at line 95 of file ble_app_hrs.c.
|
static |
Heart Rate sensor simulator configuration.
Definition at line 96 of file ble_app_hrs.c.
|
static |
Heart Rate sensor simulator state.
Definition at line 97 of file ble_app_hrs.c.
|
static |
RR Interval sensor simulator configuration.
Definition at line 98 of file ble_app_hrs.c.
|
static |
RR Interval sensor simulator state.
Definition at line 99 of file ble_app_hrs.c.
|
static |
Application identifier allocated by device manager
Definition at line 106 of file ble_app_hrs.c.
|
static |
Universally unique service identifiers.
Definition at line 108 of file ble_app_hrs.c.