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 "gr55xx_sys.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 < CFG_MAX_CONNECTIONS ?\
84 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of BPS connections. */
85 #define BPS_BP_MEAS_MAX_LEN 20 /**< Maximum notification length. */
86
87 /**
88 * @defgroup BPS_CHAR_MASK Characteristics Mask
89 * @{
90 * @brief Bit masks for the initialization of @ref bps_init_t.char_mask.
91 */
92 #define BPS_CHAR_MANDATORY 0x018F /**< Bit mask of the mandatory characteristics in BPS. */
93 #define BPS_CHAR_INTM_CUFF_PRESS_SUP 0x0070 /**< Bit mask of the Intermediate Cuff Pressure descriptor. */
94 #define BPS_CHAR_FULL 0x01ff /**< Bit mask of the full characteristic. */
95 /** @} */
96 /** @} */
97
98 /**
99 * @defgroup BPS_ENUM Enumerations
100 * @{
101 */
102 /**@brief Blood Pressure Service event type. */
103 typedef enum
104 {
105 BPS_EVT_INVALID, /**< Invalid event. */
106 BPS_EVT_BP_MEAS_INDICATION_ENABLED, /**< The measurement indication has been enabled. */
107 BPS_EVT_BP_MEAS_INDICATION_DISABLED, /**< The measurement indication has been disabled. */
108 BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED, /**< The Intermediate Cuff Pressure notification has been enabled. */
109 BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED, /**< The Intermediate Cuff Pressure notification has been disabled. */
110 BPS_EVT_READ_BL_PRESSURE_FEATURE, /**< The peer reads Blood Pressure Feature characteristic. */
111 } bps_evt_type_t;
112
113 /**@brief Blood Pressure Feature bits. */
114 enum bp_feature_bit
115 {
116 BP_FEATURE_BODY_MOVEMENT_BIT = (0x01 << 0), /**< Body Movement Detection Support bit. */
117 BP_FEATURE_CUFF_FIT_BIT = (0x01 << 1), /**< Cuff Fit Detection Support bit. */
118 BP_FEATURE_IRREGULAR_PULSE_BIT = (0x01 << 2), /**< Irregular Pulse Detection Support bit. */
119 BP_FEATURE_PULSE_RATE_RANGE_BIT = (0x01 << 3), /**< Pulse Rate Range Detection Support bit. */
120 BP_FEATURE_MEASUREMENT_POSITION_BIT = (0x01 << 4), /**< Measurement Position Detection Support bit. */
121 BP_FEATURE_MULTIPLE_BOND_BIT = (0x01 << 5), /**< Multiple Bond Support bit. */
122 };
123 /** @} */
124
125 /**
126 * @defgroup BPS_TYPEDEF Typedefs
127 * @{
128 */
129 /**@brief Blood Pressure Service event handler type. */
130 typedef void (*bps_evt_handler_t)(uint8_t conn_idx, bps_evt_type_t event);
131 /** @} */
132
133 /**
134 * @defgroup BPS_STRUCT Structures
135 * @{
136 */
137 /**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit value with 12-bit mantissa and 4-bit exponent. */
138 typedef struct
139 {
140 int8_t exponent; /**< Base 10 exponent, only 4 bits */
141 int16_t mantissa; /**< Mantissa, only 12 bits */
142 } ieee_float16_t;
143
144 /**@brief Blood Pressure measurement structure. */
145 typedef struct
146 {
147 uint8_t bl_unit_in_kpa; /**< Blood Pressure Units Flag, 0=mmHg, 1=kPa */
148 uint8_t time_stamp_present; /**< Time Stamp Flag, 0=not present, 1=present. */
149 uint8_t pulse_rate_present; /**< Pulse Rate Flag, 0=not present, 1=present. */
150 uint8_t user_id_present; /**< User ID Flag, 0=not present, 1=present. */
151 uint8_t meas_status_present; /**< Measurement Status Flag, 0=not present, 1=present. */
152 ieee_float16_t systolic; /**< Blood Pressure Measurement Compound Value - Systolic. */
153 ieee_float16_t diastolic; /**< Blood Pressure Measurement Compound Value - Diastolic . */
154 ieee_float16_t mean_arterial_pr; /**< Blood Pressure Measurement Compound Value - Mean Arterial Pressure. */
155 prf_date_time_t time_stamp; /**< Time Stamp. */
156 ieee_float16_t pulse_rate; /**< Pulse Rate. */
157 uint8_t user_id; /**< User ID. */
158 uint16_t meas_status; /**< Measurement Status. */
159 } bps_meas_t;
160
161 /**@brief Blood Pressure Service init stucture. This contains all option and data needed for initialization of the service. */
162 typedef struct
163 {
164 bps_evt_handler_t evt_handler; /**< Blood Pressure Service event handler. */
165 uint16_t char_mask; /**< Mask of Supported characteristics, and configured with \ref BPS_CHAR_MASK */
166 uint16_t bp_feature; /**< Value of Blood Pressure Feature characteristic. */
167 } bps_init_t;
168 /** @} */
169
170 /**
171 * @defgroup BPS_FUNCTION Functions
172 * @{
173 */
174 /**
175 *****************************************************************************************
176 * @brief Initialize a Blood Pressure Service instance and add in the DB.
177 *
178 * @param[in] p_bps_init: Pointer to Blood Pressure Service initialization variable
179 *
180 * @return Result of service initialization.
181 *****************************************************************************************
182 */
183 sdk_err_t bps_service_init(bps_init_t *p_bps_init);
184
185 /**
186 *****************************************************************************************
187 * @brief Send Blood Pressure Measurement indication.
188 *
189 * @param[in] conn_idx: Connection index.
190 * @param[in] p_meas: Pointer to the Blood Pressure measurement.
191 *
192 * @return Result of sending indication.
193 *****************************************************************************************
194 */
195 sdk_err_t bps_measurement_send(uint8_t conn_idx, bps_meas_t *p_meas);
196 /** @} */
197
198 #endif
199 /** @} */
200 /** @} */
bps_init_t::bp_feature
uint16_t bp_feature
Value of Blood Pressure Feature characteristic.
Definition: bps.h:166
bps_meas_t::pulse_rate_present
uint8_t pulse_rate_present
Pulse Rate Flag, 0=not present, 1=present.
Definition: bps.h:149
bps_meas_t::pulse_rate
ieee_float16_t pulse_rate
Pulse Rate.
Definition: bps.h:156
bps_init_t::evt_handler
bps_evt_handler_t evt_handler
Blood Pressure Service event handler.
Definition: bps.h:164
BP_FEATURE_MULTIPLE_BOND_BIT
@ BP_FEATURE_MULTIPLE_BOND_BIT
Multiple Bond Support bit.
Definition: bps.h:121
bps_evt_type_t
bps_evt_type_t
Blood Pressure Service event type.
Definition: bps.h:104
bps_meas_t::bl_unit_in_kpa
uint8_t bl_unit_in_kpa
Blood Pressure Units Flag, 0=mmHg, 1=kPa.
Definition: bps.h:147
bp_feature_bit
bp_feature_bit
Blood Pressure Feature bits.
Definition: bps.h:115
gr55xx_sys.h
GR55XX System API.
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:130
bps_meas_t::time_stamp
prf_date_time_t time_stamp
Time Stamp.
Definition: bps.h:155
bps_meas_t::time_stamp_present
uint8_t time_stamp_present
Time Stamp Flag, 0=not present, 1=present.
Definition: bps.h:148
BPS_EVT_READ_BL_PRESSURE_FEATURE
@ BPS_EVT_READ_BL_PRESSURE_FEATURE
The peer reads Blood Pressure Feature characteristic.
Definition: bps.h:110
ieee_float16_t::mantissa
int16_t mantissa
Mantissa, only 12 bits.
Definition: bps.h:141
bps_meas_t::mean_arterial_pr
ieee_float16_t mean_arterial_pr
Blood Pressure Measurement Compound Value - Mean Arterial Pressure.
Definition: bps.h:154
bps_meas_t::diastolic
ieee_float16_t diastolic
Blood Pressure Measurement Compound Value - Diastolic .
Definition: bps.h:153
BPS_EVT_INVALID
@ BPS_EVT_INVALID
Invalid event.
Definition: bps.h:105
ieee_float16_t::exponent
int8_t exponent
Base 10 exponent, only 4 bits.
Definition: bps.h:140
bps_meas_t
Blood Pressure measurement structure.
Definition: bps.h:146
BP_FEATURE_PULSE_RATE_RANGE_BIT
@ BP_FEATURE_PULSE_RATE_RANGE_BIT
Pulse Rate Range Detection Support bit.
Definition: bps.h:119
bps_init_t::char_mask
uint16_t char_mask
Mask of Supported characteristics, and configured with Characteristics Mask.
Definition: bps.h:165
BP_FEATURE_BODY_MOVEMENT_BIT
@ BP_FEATURE_BODY_MOVEMENT_BIT
Body Movement Detection Support bit.
Definition: bps.h:116
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
bps_meas_t::systolic
ieee_float16_t systolic
Blood Pressure Measurement Compound Value - Systolic.
Definition: bps.h:152
prf_date_time_t
The date and time structure.
Definition: ble_prf_types.h:101
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
The measurement indication has been enabled.
Definition: bps.h:106
BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED
@ BPS_EVT_INTM_CUFF_PRESS_NTF_ENABLED
The Intermediate Cuff Pressure notification has been enabled.
Definition: bps.h:108
BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED
@ BPS_EVT_INTM_CUFF_PRESS_NTF_DISABLED
The Intermediate Cuff Pressure notification has been disabled.
Definition: bps.h:109
BPS_EVT_BP_MEAS_INDICATION_DISABLED
@ BPS_EVT_BP_MEAS_INDICATION_DISABLED
The measurement indication has been disabled.
Definition: bps.h:107
ble_prf_utils.h
Profile/Service Utilities API.
BP_FEATURE_CUFF_FIT_BIT
@ BP_FEATURE_CUFF_FIT_BIT
Cuff Fit Detection Support bit.
Definition: bps.h:117
bps_meas_t::user_id
uint8_t user_id
User ID.
Definition: bps.h:157
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:139
bps_init_t
Blood Pressure Service init stucture.
Definition: bps.h:163
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
Measurement Status Flag, 0=not present, 1=present.
Definition: bps.h:151
BP_FEATURE_IRREGULAR_PULSE_BIT
@ BP_FEATURE_IRREGULAR_PULSE_BIT
Irregular Pulse Detection Support bit.
Definition: bps.h:118
bps_meas_t::meas_status
uint16_t meas_status
Measurement Status.
Definition: bps.h:158
bps_meas_t::user_id_present
uint8_t user_id_present
User ID Flag, 0=not present, 1=present.
Definition: bps.h:150
BP_FEATURE_MEASUREMENT_POSITION_BIT
@ BP_FEATURE_MEASUREMENT_POSITION_BIT
Measurement Position Detection Support bit.
Definition: bps.h:120