bps.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file bps.h
5 *
6 * @brief Blood Pressure Service API.
7 *
8 *****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 *****************************************************************************************
36 */
37
38 /**
39 * @addtogroup BLE_SRV BLE Services
40 * @{
41 * @brief Definitions and prototypes for the BLE Service interface.
42 */
43
44 /**
45 * @defgroup BLE_SDK_BPS Blood Pressure Service (BPS)
46 * @{
47 * @brief Definitions and prototypes for the BPS interface.
48 *
49 * @details The Blood Pressure Service exposes blood pressure and other data from
50 * a blood pressure monitor for use in consumer and profession healthcare
51 * application.
52 *
53 * This module implements the Blood Pressure Service with the Blood
54 * Pressure Measurement characteristic. The Intermediate Cuff Pressure
55 * characteristic is optional, and is not supported in this module.
56 *
57 * After \ref bps_init_t variable is initialized, the developer shall call
58 * \ref bps_service_init() to add a Blood Pressure Service and a Blood
59 * Pressure Measurement characteristic to the BLE Stack database. Blood
60 * Pressure Measurement characteristic supports Indicate property only,
61 * so this module stores the value of Blood Pressure Measurement
62 * neither in BLE Stack database nor in bps_env_t variable.
63 *
64 * If an event handler is provided by the application, the Blood
65 * Pressure Service will pass Blood Pressure Service events to the
66 * application.
67 *
68 */
69
70 #ifndef __BPS_H__
71 #define __BPS_H__
72
73 #include "gr_includes.h"
74 #include "ble_prf_utils.h"
75 #include "custom_config.h"
76 #include <stdint.h>
77 #include <stdbool.h>
78
79 /**
80 * @defgroup BPS_MACRO Defines
81 * @{
82 */
83 #define BPS_CONNECTION_MAX 10 /**< Maximum number of BPS connections. */
84 #define BPS_BP_MEAS_MAX_LEN 20 /**< Maximum notification length. */
85
86 /**
87 * @defgroup BPS_CHAR_MASK Characteristics Mask
88 * @{
89 * @brief Bit masks for the initialization of @ref bps_init_t.char_mask.
90 */
91 #define BPS_CHAR_MANDATORY 0x018F /**< Bit mask of the mandatory characteristics in BPS. */
92 #define BPS_CHAR_INTM_CUFF_PRESS_SUP 0x0070 /**< Bit mask of the Intermediate Cuff Pressure descriptor. */
93 #define BPS_CHAR_FULL 0x01ff /**< Bit mask of the full characteristic. */
94 /** @} */
95 /** @} */
96
97 /**
98 * @defgroup BPS_ENUM Enumerations
99 * @{
100 */
101 /**@brief Blood Pressure Service event type. */
102 typedef enum
103 {
104 BPS_EVT_INVALID, /**< Invalid event. */
105 BPS_EVT_BP_MEAS_INDICATION_ENABLED, /**< The measurement indication has been enabled. */
106 BPS_EVT_BP_MEAS_INDICATION_DISABLED, /**< The measurement indication has been disabled. */
107 BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED, /**< The Intermediate Cuff Pressure notification has been enabled. */
108 BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED, /**< The Intermediate Cuff Pressure notification has been disabled. */
109 BPS_EVT_READ_BL_PRESSURE_FEATURE, /**< The peer reads Blood Pressure Feature characteristic. */
110 } bps_evt_type_t;
111
112 /**@brief Blood Pressure Feature bits. */
113 enum bp_feature_bit
114 {
115 BP_FEATURE_BODY_MOVEMENT_BIT = (0x01 << 0), /**< Body Movement Detection Support bit. */
116 BP_FEATURE_CUFF_FIT_BIT = (0x01 << 1), /**< Cuff Fit Detection Support bit. */
117 BP_FEATURE_IRREGULAR_PULSE_BIT = (0x01 << 2), /**< Irregular Pulse Detection Support bit. */
118 BP_FEATURE_PULSE_RATE_RANGE_BIT = (0x01 << 3), /**< Pulse Rate Range Detection Support bit. */
119 BP_FEATURE_MEASUREMENT_POSITION_BIT = (0x01 << 4), /**< Measurement Position Detection Support bit. */
120 BP_FEATURE_MULTIPLE_BOND_BIT = (0x01 << 5), /**< Multiple Bond Support bit. */
121 };
122 /** @} */
123
124 /**
125 * @defgroup BPS_TYPEDEF Typedefs
126 * @{
127 */
128 /**@brief Blood Pressure Service event handler type. */
129 typedef void (*bps_evt_handler_t)(uint8_t conn_idx, bps_evt_type_t event);
130 /** @} */
131
132 /**
133 * @defgroup BPS_STRUCT Structures
134 * @{
135 */
136 /**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit value with 12-bit mantissa and 4-bit exponent. */
137 typedef struct
138 {
139 int8_t exponent; /**< Base 10 exponent, only 4 bits */
140 int16_t mantissa; /**< Mantissa, only 12 bits */
141 } bps_ieee_float16_t;
142
143 /**@brief Blood Pressure measurement structure. */
144 typedef struct
145 {
146 uint8_t bl_unit_in_kpa; /**< Blood Pressure Units Flag, 0=mmHg, 1=kPa */
147 uint8_t time_stamp_present; /**< Time Stamp Flag, 0=not present, 1=present. */
148 uint8_t pulse_rate_present; /**< Pulse Rate Flag, 0=not present, 1=present. */
149 uint8_t user_id_present; /**< User ID Flag, 0=not present, 1=present. */
150 uint8_t meas_status_present; /**< Measurement Status Flag, 0=not present, 1=present. */
151 bps_ieee_float16_t systolic; /**< Blood Pressure Measurement Compound Value - Systolic. */
152 bps_ieee_float16_t diastolic; /**< Blood Pressure Measurement Compound Value - Diastolic . */
153 bps_ieee_float16_t mean_arterial_pr; /**< Blood Pressure Measurement Compound Value - Mean Arterial Pressure. */
154 prf_date_time_t time_stamp; /**< Time Stamp. */
155 bps_ieee_float16_t pulse_rate; /**< Pulse Rate. */
156 uint8_t user_id; /**< User ID. */
157 uint16_t meas_status; /**< Measurement Status. */
158 } bps_meas_t;
159
160 /**@brief Blood Pressure Service init stucture. This contains all option and data needed for initialization of the service. */
161 typedef struct
162 {
163 bps_evt_handler_t evt_handler; /**< Blood Pressure Service event handler. */
164 uint16_t char_mask; /**< Mask of Supported characteristics, and configured with \ref BPS_CHAR_MASK */
165 uint16_t bp_feature; /**< Value of Blood Pressure Feature characteristic. */
166 } bps_init_t;
167 /** @} */
168
169 /**
170 * @defgroup BPS_FUNCTION Functions
171 * @{
172 */
173 /**
174 *****************************************************************************************
175 * @brief Initialize a Blood Pressure Service instance and add in the DB.
176 *
177 * @param[in] p_bps_init: Pointer to Blood Pressure Service initialization variable
178 *
179 * @return Result of service initialization.
180 *****************************************************************************************
181 */
182 sdk_err_t bps_service_init(bps_init_t *p_bps_init);
183
184 /**
185 *****************************************************************************************
186 * @brief Send Blood Pressure Measurement indication.
187 *
188 * @param[in] conn_idx: Connection index.
189 * @param[in] p_meas: Pointer to the Blood Pressure measurement.
190 *
191 * @return Result of sending indication.
192 *****************************************************************************************
193 */
194 sdk_err_t bps_measurement_send(uint8_t conn_idx, bps_meas_t *p_meas);
195 /** @} */
196
197 #endif
198 /** @} */
199 /** @} */
bps_init_t::bp_feature
uint16_t bp_feature
Definition: bps.h:165
bps_meas_t::pulse_rate_present
uint8_t pulse_rate_present
Definition: bps.h:148
bps_init_t::evt_handler
bps_evt_handler_t evt_handler
Definition: bps.h:163
BP_FEATURE_MULTIPLE_BOND_BIT
@ BP_FEATURE_MULTIPLE_BOND_BIT
Definition: bps.h:120
bps_evt_type_t
bps_evt_type_t
Blood Pressure Service event type.
Definition: bps.h:103
bps_meas_t::bl_unit_in_kpa
uint8_t bl_unit_in_kpa
Definition: bps.h:146
bp_feature_bit
bp_feature_bit
Blood Pressure Feature bits.
Definition: bps.h:114
gr_includes.h
Include Files API.
bps_meas_t::systolic
bps_ieee_float16_t systolic
Definition: bps.h:151
bps_evt_handler_t
void(* bps_evt_handler_t)(uint8_t conn_idx, bps_evt_type_t event)
Blood Pressure Service event handler type.
Definition: bps.h:129
bps_meas_t::time_stamp
prf_date_time_t time_stamp
Definition: bps.h:154
bps_meas_t::time_stamp_present
uint8_t time_stamp_present
Definition: bps.h:147
BPS_EVT_READ_BL_PRESSURE_FEATURE
@ BPS_EVT_READ_BL_PRESSURE_FEATURE
Definition: bps.h:109
bps_ieee_float16_t
SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit value with 12-bit mantissa and 4-bit expo...
Definition: bps.h:138
BPS_EVT_INVALID
@ BPS_EVT_INVALID
Definition: bps.h:104
bps_meas_t::mean_arterial_pr
bps_ieee_float16_t mean_arterial_pr
Definition: bps.h:153
bps_meas_t::pulse_rate
bps_ieee_float16_t pulse_rate
Definition: bps.h:155
bps_meas_t
Blood Pressure measurement structure.
Definition: bps.h:145
bps_ieee_float16_t::mantissa
int16_t mantissa
Definition: bps.h:140
BP_FEATURE_PULSE_RATE_RANGE_BIT
@ BP_FEATURE_PULSE_RATE_RANGE_BIT
Definition: bps.h:118
bps_init_t::char_mask
uint16_t char_mask
Definition: bps.h:164
BP_FEATURE_BODY_MOVEMENT_BIT
@ BP_FEATURE_BODY_MOVEMENT_BIT
Definition: bps.h:115
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:257
prf_date_time_t
The date and time structure. The packed size is 7 bytes.
Definition: ble_prf_types.h:101
bps_ieee_float16_t::exponent
int8_t exponent
Definition: bps.h:139
bps_service_init
sdk_err_t bps_service_init(bps_init_t *p_bps_init)
Initialize a Blood Pressure Service instance and add in the DB.
BPS_EVT_BP_MEAS_INDICATION_ENABLED
@ BPS_EVT_BP_MEAS_INDICATION_ENABLED
Definition: bps.h:105
BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED
@ BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED
Definition: bps.h:107
BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED
@ BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED
Definition: bps.h:108
bps_meas_t::diastolic
bps_ieee_float16_t diastolic
Definition: bps.h:152
BPS_EVT_BP_MEAS_INDICATION_DISABLED
@ BPS_EVT_BP_MEAS_INDICATION_DISABLED
Definition: bps.h:106
ble_prf_utils.h
Profile/Service Utilities API.
BP_FEATURE_CUFF_FIT_BIT
@ BP_FEATURE_CUFF_FIT_BIT
Definition: bps.h:116
bps_meas_t::user_id
uint8_t user_id
Definition: bps.h:156
bps_init_t
Blood Pressure Service init stucture. This contains all option and data needed for initialization of ...
Definition: bps.h:162
bps_measurement_send
sdk_err_t bps_measurement_send(uint8_t conn_idx, bps_meas_t *p_meas)
Send Blood Pressure Measurement indication.
bps_meas_t::meas_status_present
uint8_t meas_status_present
Definition: bps.h:150
BP_FEATURE_IRREGULAR_PULSE_BIT
@ BP_FEATURE_IRREGULAR_PULSE_BIT
Definition: bps.h:117
bps_meas_t::meas_status
uint16_t meas_status
Definition: bps.h:157
bps_meas_t::user_id_present
uint8_t user_id_present
Definition: bps.h:149
BP_FEATURE_MEASUREMENT_POSITION_BIT
@ BP_FEATURE_MEASUREMENT_POSITION_BIT
Definition: bps.h:119