• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdint.h>
74 #include <stdbool.h>
75 #include "gr55xx_sys.h"
76 #include "ble_prf_utils.h"
77 #include "custom_config.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     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     BP_FEATURE_BODY_MOVEMENT_BIT        = (0x01 << 0),    /**< Body Movement Detection Support bit. */
115     BP_FEATURE_CUFF_FIT_BIT             = (0x01 << 1),    /**< Cuff Fit Detection Support bit. */
116     BP_FEATURE_IRREGULAR_PULSE_BIT      = (0x01 << 2),    /**< Irregular Pulse Detection Support bit. */
117     BP_FEATURE_PULSE_RATE_RANGE_BIT     = (0x01 << 3),    /**< Pulse Rate Range Detection Support bit. */
118     BP_FEATURE_MEASUREMENT_POSITION_BIT = (0x01 << 4),    /**< Measurement Position Detection Support bit. */
119     BP_FEATURE_MULTIPLE_BOND_BIT        = (0x01 << 5),    /**< Multiple Bond Support bit. */
120 };
121 /** @} */
122 
123 /**
124  * @defgroup BPS_TYPEDEF Typedefs
125  * @{
126  */
127 /**@brief Blood Pressure Service event handler type. */
128 typedef void (*bps_evt_handler_t)(uint8_t conn_idx, bps_evt_type_t event);
129 /** @} */
130 
131 /**
132  * @defgroup BPS_STRUCT Structures
133  * @{
134  */
135 /**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit value with 12-bit mantissa and 4-bit exponent. */
136 typedef struct {
137     int8_t  exponent;     /**< Base 10 exponent, only 4 bits */
138     int16_t mantissa;     /**< Mantissa, only 12 bits */
139 } ieee_float16_t;
140 
141 /**@brief Blood Pressure measurement structure. */
142 typedef struct {
143     uint8_t         bl_unit_in_kpa;         /**< Blood Pressure Units Flag, 0=mmHg, 1=kPa */
144     uint8_t         time_stamp_present;     /**< Time Stamp Flag, 0=not present, 1=present. */
145     uint8_t         pulse_rate_present;     /**< Pulse Rate Flag, 0=not present, 1=present. */
146     uint8_t         user_id_present;        /**< User ID Flag, 0=not present, 1=present. */
147     uint8_t         meas_status_present;    /**< Measurement Status Flag, 0=not present, 1=present. */
148     ieee_float16_t  systolic;               /**< Blood Pressure Measurement Compound Value - Systolic. */
149     ieee_float16_t  diastolic;              /**< Blood Pressure Measurement Compound Value - Diastolic . */
150     ieee_float16_t  mean_arterial_pr;       /**< Blood Pressure Measurement Compound Value - Mean Arterial Pressure. */
151     prf_date_time_t time_stamp;             /**< Time Stamp. */
152     ieee_float16_t  pulse_rate;             /**< Pulse Rate. */
153     uint8_t         user_id;                /**< User ID. */
154     uint16_t        meas_status;            /**< Measurement Status. */
155 } bps_meas_t;
156 
157 /**@brief Blood Pressure Service init stucture.
158  * This contains all option and data needed for initialization of the service. */
159 typedef struct {
160     bps_evt_handler_t evt_handler;                    /**< Blood Pressure Service event handler. */
161     uint16_t
162     char_mask;                      /**< Mask of Supported characteristics, and configured with \ref BPS_CHAR_MASK */
163     uint16_t          bp_feature;                     /**< Value of Blood Pressure Feature characteristic. */
164 } bps_init_t;
165 /** @} */
166 
167 /**
168  * @defgroup BPS_FUNCTION Functions
169  * @{
170  */
171 /**
172  *****************************************************************************************
173  * @brief Initialize a Blood Pressure Service instance and add in the DB.
174  *
175  * @param[in] p_bps_init: Pointer to Blood Pressure Service initialization variable
176  *
177  * @return Result of service initialization.
178  *****************************************************************************************
179  */
180 sdk_err_t bps_service_init(bps_init_t *p_bps_init);
181 
182 /**
183  *****************************************************************************************
184  * @brief Send Blood Pressure Measurement indication.
185  *
186  * @param[in] conn_idx: Connection index.
187  * @param[in] p_meas:   Pointer to the Blood Pressure measurement.
188  *
189  * @return Result of sending indication.
190  *****************************************************************************************
191  */
192 sdk_err_t bps_measurement_send(uint8_t conn_idx, bps_meas_t *p_meas);
193 /** @} */
194 
195 #endif
196 /** @} */
197 /** @} */
198