BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:a607cd9655d7 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 2 *
yihui 1:a607cd9655d7 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:a607cd9655d7 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:a607cd9655d7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:a607cd9655d7 6 *
yihui 1:a607cd9655d7 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:a607cd9655d7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:a607cd9655d7 9 * the file.
yihui 1:a607cd9655d7 10 */
yihui 1:a607cd9655d7 11
yihui 1:a607cd9655d7 12 /** @file
yihui 1:a607cd9655d7 13 *
yihui 1:a607cd9655d7 14 * @defgroup ble_sdk_srv_bps Blood Pressure Service
yihui 1:a607cd9655d7 15 * @{
yihui 1:a607cd9655d7 16 * @ingroup ble_sdk_srv
yihui 1:a607cd9655d7 17 * @brief Blood Pressure Service module.
yihui 1:a607cd9655d7 18 *
yihui 1:a607cd9655d7 19 * @details This module implements the Blood Pressure Service.
yihui 1:a607cd9655d7 20 *
yihui 1:a607cd9655d7 21 * If an event handler is supplied by the application, the Blood Pressure
yihui 1:a607cd9655d7 22 * Service will generate Blood Pressure Service events to the application.
yihui 1:a607cd9655d7 23 *
yihui 1:a607cd9655d7 24 * @note The application must propagate BLE stack events to the Blood Pressure Service
yihui 1:a607cd9655d7 25 * module by calling ble_bps_on_ble_evt() from the from the @ref ble_stack_handler function.
yihui 1:a607cd9655d7 26 *
yihui 1:a607cd9655d7 27 * @note Attention!
yihui 1:a607cd9655d7 28 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
yihui 1:a607cd9655d7 29 * qualification listings, this section of source code must not be modified.
yihui 1:a607cd9655d7 30 */
yihui 1:a607cd9655d7 31
yihui 1:a607cd9655d7 32 #ifndef BLE_BPS_H__
yihui 1:a607cd9655d7 33 #define BLE_BPS_H__
yihui 1:a607cd9655d7 34
yihui 1:a607cd9655d7 35 #include <stdint.h>
yihui 1:a607cd9655d7 36 #include <stdbool.h>
yihui 1:a607cd9655d7 37 #include "ble.h"
yihui 1:a607cd9655d7 38 #include "ble_srv_common.h"
yihui 1:a607cd9655d7 39 #include "ble_date_time.h"
yihui 1:a607cd9655d7 40
yihui 1:a607cd9655d7 41 // Blood Pressure Feature bits
yihui 1:a607cd9655d7 42 #define BLE_BPS_FEATURE_BODY_MOVEMENT_BIT (0x01 << 0) /**< Body Movement Detection Support bit. */
yihui 1:a607cd9655d7 43 #define BLE_BPS_FEATURE_CUFF_FIT_BIT (0x01 << 1) /**< Cuff Fit Detection Support bit. */
yihui 1:a607cd9655d7 44 #define BLE_BPS_FEATURE_IRREGULAR_PULSE_BIT (0x01 << 2) /**< Irregular Pulse Detection Support bit. */
yihui 1:a607cd9655d7 45 #define BLE_BPS_FEATURE_PULSE_RATE_RANGE_BIT (0x01 << 3) /**< Pulse Rate Range Detection Support bit. */
yihui 1:a607cd9655d7 46 #define BLE_BPS_FEATURE_MEASUREMENT_POSITION_BIT (0x01 << 4) /**< Measurement Position Detection Support bit. */
yihui 1:a607cd9655d7 47 #define BLE_BPS_FEATURE_MULTIPLE_BOND_BIT (0x01 << 5) /**< Multiple Bond Support bit. */
yihui 1:a607cd9655d7 48
yihui 1:a607cd9655d7 49 /**@brief Blood Pressure Service event type. */
yihui 1:a607cd9655d7 50 typedef enum
yihui 1:a607cd9655d7 51 {
yihui 1:a607cd9655d7 52 BLE_BPS_EVT_INDICATION_ENABLED, /**< Blood Pressure value indication enabled event. */
yihui 1:a607cd9655d7 53 BLE_BPS_EVT_INDICATION_DISABLED, /**< Blood Pressure value indication disabled event. */
yihui 1:a607cd9655d7 54 BLE_BPS_EVT_INDICATION_CONFIRMED /**< Confirmation of a blood pressure measurement indication has been received. */
yihui 1:a607cd9655d7 55 } ble_bps_evt_type_t;
yihui 1:a607cd9655d7 56
yihui 1:a607cd9655d7 57 /**@brief Blood Pressure Service event. */
yihui 1:a607cd9655d7 58 typedef struct
yihui 1:a607cd9655d7 59 {
yihui 1:a607cd9655d7 60 ble_bps_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 61 } ble_bps_evt_t;
yihui 1:a607cd9655d7 62
yihui 1:a607cd9655d7 63 // Forward declaration of the ble_bps_t type.
yihui 1:a607cd9655d7 64 typedef struct ble_bps_s ble_bps_t;
yihui 1:a607cd9655d7 65
yihui 1:a607cd9655d7 66 /**@brief Blood Pressure Service event handler type. */
yihui 1:a607cd9655d7 67 typedef void (*ble_bps_evt_handler_t) (ble_bps_t * p_bps, ble_bps_evt_t * p_evt);
yihui 1:a607cd9655d7 68
yihui 1:a607cd9655d7 69 /**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit vlue with 12-bit mantissa and
yihui 1:a607cd9655d7 70 * 4-bit exponent. */
yihui 1:a607cd9655d7 71 typedef struct
yihui 1:a607cd9655d7 72 {
yihui 1:a607cd9655d7 73 int8_t exponent; /**< Base 10 exponent, only 4 bits */
yihui 1:a607cd9655d7 74 int16_t mantissa; /**< Mantissa, only 12 bits */
yihui 1:a607cd9655d7 75 } ieee_float16_t;
yihui 1:a607cd9655d7 76
yihui 1:a607cd9655d7 77 /**@brief Blood Pressure Service init structure. This contains all options and data
yihui 1:a607cd9655d7 78 * needed for initialization of the service. */
yihui 1:a607cd9655d7 79 typedef struct
yihui 1:a607cd9655d7 80 {
yihui 1:a607cd9655d7 81 ble_bps_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Blood Pressure Service. */
yihui 1:a607cd9655d7 82 ble_srv_cccd_security_mode_t bps_meas_attr_md; /**< Initial security level for blood pressure measurement attribute */
yihui 1:a607cd9655d7 83 ble_srv_security_mode_t bps_feature_attr_md; /**< Initial security level for blood pressure feature attribute */
yihui 1:a607cd9655d7 84 uint16_t feature; /**< Initial value for blood pressure feature */
yihui 1:a607cd9655d7 85 } ble_bps_init_t;
yihui 1:a607cd9655d7 86
yihui 1:a607cd9655d7 87 /**@brief Blood Pressure Service structure. This contains various status information for
yihui 1:a607cd9655d7 88 * the service. */
yihui 1:a607cd9655d7 89 typedef struct ble_bps_s
yihui 1:a607cd9655d7 90 {
yihui 1:a607cd9655d7 91 ble_bps_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Blood Pressure Service. */
yihui 1:a607cd9655d7 92 uint16_t service_handle; /**< Handle of Blood Pressure Service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 93 ble_gatts_char_handles_t meas_handles; /**< Handles related to the Blood Pressure Measurement characteristic. */
yihui 1:a607cd9655d7 94 ble_gatts_char_handles_t feature_handles; /**< Handles related to the Blood Pressure Feature characteristic. */
yihui 1:a607cd9655d7 95 uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
yihui 1:a607cd9655d7 96 uint16_t feature; /**< Value of Blood Pressure feature. */
yihui 1:a607cd9655d7 97 } ble_bps_t;
yihui 1:a607cd9655d7 98
yihui 1:a607cd9655d7 99 /**@brief Blood Pressure Service measurement structure. This contains a Blood Pressure
yihui 1:a607cd9655d7 100 * measurement. */
yihui 1:a607cd9655d7 101 typedef struct ble_bps_meas_s
yihui 1:a607cd9655d7 102 {
yihui 1:a607cd9655d7 103 bool blood_pressure_units_in_kpa; /**< Blood Pressure Units Flag, 0=mmHg, 1=kPa */
yihui 1:a607cd9655d7 104 bool time_stamp_present; /**< Time Stamp Flag, 0=not present, 1=present. */
yihui 1:a607cd9655d7 105 bool pulse_rate_present; /**< Pulse Rate Flag, 0=not present, 1=present. */
yihui 1:a607cd9655d7 106 bool user_id_present; /**< User ID Flag, 0=not present, 1=present. */
yihui 1:a607cd9655d7 107 bool measurement_status_present; /**< Measurement Status Flag, 0=not present, 1=present. */
yihui 1:a607cd9655d7 108 ieee_float16_t blood_pressure_systolic; /**< Blood Pressure Measurement Compound Value - Systolic. */
yihui 1:a607cd9655d7 109 ieee_float16_t blood_pressure_diastolic; /**< Blood Pressure Measurement Compound Value - Diastolic . */
yihui 1:a607cd9655d7 110 ieee_float16_t mean_arterial_pressure; /**< Blood Pressure Measurement Compound Value - Mean Arterial Pressure. */
yihui 1:a607cd9655d7 111 ble_date_time_t time_stamp; /**< Time Stamp. */
yihui 1:a607cd9655d7 112 ieee_float16_t pulse_rate; /**< Pulse Rate. */
yihui 1:a607cd9655d7 113 uint8_t user_id; /**< User ID. */
yihui 1:a607cd9655d7 114 uint16_t measurement_status; /**< Measurement Status. */
yihui 1:a607cd9655d7 115 } ble_bps_meas_t;
yihui 1:a607cd9655d7 116
yihui 1:a607cd9655d7 117 /**@brief Function for initializing the Blood Pressure Service.
yihui 1:a607cd9655d7 118 *
yihui 1:a607cd9655d7 119 * @param[out] p_bps Blood Pressure Service structure. This structure will have to
yihui 1:a607cd9655d7 120 * be supplied by the application. It will be initialized by this function,
yihui 1:a607cd9655d7 121 * and will later be used to identify this particular service instance.
yihui 1:a607cd9655d7 122 * @param[in] p_bps_init Information needed to initialize the service.
yihui 1:a607cd9655d7 123 *
yihui 1:a607cd9655d7 124 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
yihui 1:a607cd9655d7 125 */
yihui 1:a607cd9655d7 126 uint32_t ble_bps_init(ble_bps_t * p_bps, const ble_bps_init_t * p_bps_init);
yihui 1:a607cd9655d7 127
yihui 1:a607cd9655d7 128 /**@brief Function for handling the Application's BLE Stack events.
yihui 1:a607cd9655d7 129 *
yihui 1:a607cd9655d7 130 * @details Handles all events from the BLE stack of interest to the Blood Pressure Service.
yihui 1:a607cd9655d7 131 *
yihui 1:a607cd9655d7 132 * @param[in] p_bps Blood Pressure Service structure.
yihui 1:a607cd9655d7 133 * @param[in] p_ble_evt Event received from the BLE stack.
yihui 1:a607cd9655d7 134 */
yihui 1:a607cd9655d7 135 void ble_bps_on_ble_evt(ble_bps_t * p_bps, ble_evt_t * p_ble_evt);
yihui 1:a607cd9655d7 136
yihui 1:a607cd9655d7 137 /**@brief Function for sending blood pressure measurement if indication has been enabled.
yihui 1:a607cd9655d7 138 *
yihui 1:a607cd9655d7 139 * @details The application calls this function after having performed a Blood Pressure
yihui 1:a607cd9655d7 140 * measurement. If indication has been enabled, the measurement data is encoded and
yihui 1:a607cd9655d7 141 * sent to the client.
yihui 1:a607cd9655d7 142 *
yihui 1:a607cd9655d7 143 * @param[in] p_bps Blood Pressure Service structure.
yihui 1:a607cd9655d7 144 * @param[in] p_bps_meas Pointer to new blood pressure measurement.
yihui 1:a607cd9655d7 145 *
yihui 1:a607cd9655d7 146 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 147 */
yihui 1:a607cd9655d7 148 uint32_t ble_bps_measurement_send(ble_bps_t * p_bps, ble_bps_meas_t * p_bps_meas);
yihui 1:a607cd9655d7 149
yihui 1:a607cd9655d7 150 /**@brief Function for checking if indication of Blood Pressure Measurement is currently enabled.
yihui 1:a607cd9655d7 151 *
yihui 1:a607cd9655d7 152 * @param[in] p_bps Blood Pressure Service structure.
yihui 1:a607cd9655d7 153 * @param[out] p_indication_enabled TRUE if indication is enabled, FALSE otherwise.
yihui 1:a607cd9655d7 154 *
yihui 1:a607cd9655d7 155 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 156 */
yihui 1:a607cd9655d7 157 uint32_t ble_bps_is_indication_enabled(ble_bps_t * p_bps, bool * p_indication_enabled);
yihui 1:a607cd9655d7 158
yihui 1:a607cd9655d7 159 #endif // BLE_BPS_H__
yihui 1:a607cd9655d7 160
yihui 1:a607cd9655d7 161 /** @} */