テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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