Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
nordic/nrf-sdk/ble/ble_services/ble_hts.h@69:d9f51b65a3c8, 2014-11-02 (annotated)
- Committer:
- antoniorohit
- Date:
- Sun Nov 02 20:43:14 2014 +0000
- Revision:
- 69:d9f51b65a3c8
- Parent:
- 37:c29c330d942c
First rev of BLE program for nRF51822 which provides BLE connectivity for team mediCAL's PILLar;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Rohit Grover |
37:c29c330d942c | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
| Rohit Grover |
37:c29c330d942c | 2 | * |
| Rohit Grover |
37:c29c330d942c | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
| Rohit Grover |
37:c29c330d942c | 4 | * Terms and conditions of usage are described in detail in NORDIC |
| Rohit Grover |
37:c29c330d942c | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
| Rohit Grover |
37:c29c330d942c | 6 | * |
| Rohit Grover |
37:c29c330d942c | 7 | * Licensees are granted free, non-transferable use of the information. NO |
| Rohit Grover |
37:c29c330d942c | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
| Rohit Grover |
37:c29c330d942c | 9 | * the file. |
| Rohit Grover |
37:c29c330d942c | 10 | */ |
| Rohit Grover |
37:c29c330d942c | 11 | |
| Rohit Grover |
37:c29c330d942c | 12 | /** @file |
| Rohit Grover |
37:c29c330d942c | 13 | * |
| Rohit Grover |
37:c29c330d942c | 14 | * @defgroup ble_sdk_srv_hts Health Thermometer Service |
| Rohit Grover |
37:c29c330d942c | 15 | * @{ |
| Rohit Grover |
37:c29c330d942c | 16 | * @ingroup ble_sdk_srv |
| Rohit Grover |
37:c29c330d942c | 17 | * @brief Health Thermometer Service module. |
| Rohit Grover |
37:c29c330d942c | 18 | * |
| Rohit Grover |
37:c29c330d942c | 19 | * @details This module implements the Health Thermometer Service. |
| Rohit Grover |
37:c29c330d942c | 20 | * |
| Rohit Grover |
37:c29c330d942c | 21 | * If an event handler is supplied by the application, the Health Thermometer |
| Rohit Grover |
37:c29c330d942c | 22 | * Service will generate Health Thermometer Service events to the application. |
| Rohit Grover |
37:c29c330d942c | 23 | * |
| Rohit Grover |
37:c29c330d942c | 24 | * @note The application must propagate BLE stack events to the Health Thermometer Service |
| Rohit Grover |
37:c29c330d942c | 25 | * module by calling ble_hts_on_ble_evt() from the from the @ref ble_stack_handler function. |
| Rohit Grover |
37:c29c330d942c | 26 | * |
| Rohit Grover |
37:c29c330d942c | 27 | * @note Attention! |
| Rohit Grover |
37:c29c330d942c | 28 | * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile |
| Rohit Grover |
37:c29c330d942c | 29 | * qualification listings, this section of source code must not be modified. |
| Rohit Grover |
37:c29c330d942c | 30 | */ |
| Rohit Grover |
37:c29c330d942c | 31 | |
| Rohit Grover |
37:c29c330d942c | 32 | #ifndef BLE_HTS_H__ |
| Rohit Grover |
37:c29c330d942c | 33 | #define BLE_HTS_H__ |
| Rohit Grover |
37:c29c330d942c | 34 | |
| Rohit Grover |
37:c29c330d942c | 35 | #include <stdint.h> |
| Rohit Grover |
37:c29c330d942c | 36 | #include <stdbool.h> |
| Rohit Grover |
37:c29c330d942c | 37 | #include "ble.h" |
| Rohit Grover |
37:c29c330d942c | 38 | #include "ble_srv_common.h" |
| Rohit Grover |
37:c29c330d942c | 39 | #include "ble_date_time.h" |
| Rohit Grover |
37:c29c330d942c | 40 | |
| Rohit Grover |
37:c29c330d942c | 41 | // Temperature Type measurement locations |
| Rohit Grover |
37:c29c330d942c | 42 | #define BLE_HTS_TEMP_TYPE_ARMPIT 1 |
| Rohit Grover |
37:c29c330d942c | 43 | #define BLE_HTS_TEMP_TYPE_BODY 2 |
| Rohit Grover |
37:c29c330d942c | 44 | #define BLE_HTS_TEMP_TYPE_EAR 3 |
| Rohit Grover |
37:c29c330d942c | 45 | #define BLE_HTS_TEMP_TYPE_FINGER 4 |
| Rohit Grover |
37:c29c330d942c | 46 | #define BLE_HTS_TEMP_TYPE_GI_TRACT 5 |
| Rohit Grover |
37:c29c330d942c | 47 | #define BLE_HTS_TEMP_TYPE_MOUTH 6 |
| Rohit Grover |
37:c29c330d942c | 48 | #define BLE_HTS_TEMP_TYPE_RECTUM 7 |
| Rohit Grover |
37:c29c330d942c | 49 | #define BLE_HTS_TEMP_TYPE_TOE 8 |
| Rohit Grover |
37:c29c330d942c | 50 | #define BLE_HTS_TEMP_TYPE_EAR_DRUM 9 |
| Rohit Grover |
37:c29c330d942c | 51 | |
| Rohit Grover |
37:c29c330d942c | 52 | /**@brief Health Thermometer Service event type. */ |
| Rohit Grover |
37:c29c330d942c | 53 | typedef enum |
| Rohit Grover |
37:c29c330d942c | 54 | { |
| Rohit Grover |
37:c29c330d942c | 55 | BLE_HTS_EVT_INDICATION_ENABLED, /**< Health Thermometer value indication enabled event. */ |
| Rohit Grover |
37:c29c330d942c | 56 | BLE_HTS_EVT_INDICATION_DISABLED, /**< Health Thermometer value indication disabled event. */ |
| Rohit Grover |
37:c29c330d942c | 57 | BLE_HTS_EVT_INDICATION_CONFIRMED /**< Confirmation of a temperature measurement indication has been received. */ |
| Rohit Grover |
37:c29c330d942c | 58 | } ble_hts_evt_type_t; |
| Rohit Grover |
37:c29c330d942c | 59 | |
| Rohit Grover |
37:c29c330d942c | 60 | /**@brief Health Thermometer Service event. */ |
| Rohit Grover |
37:c29c330d942c | 61 | typedef struct |
| Rohit Grover |
37:c29c330d942c | 62 | { |
| Rohit Grover |
37:c29c330d942c | 63 | ble_hts_evt_type_t evt_type; /**< Type of event. */ |
| Rohit Grover |
37:c29c330d942c | 64 | } ble_hts_evt_t; |
| Rohit Grover |
37:c29c330d942c | 65 | |
| Rohit Grover |
37:c29c330d942c | 66 | // Forward declaration of the ble_hts_t type. |
| Rohit Grover |
37:c29c330d942c | 67 | typedef struct ble_hts_s ble_hts_t; |
| Rohit Grover |
37:c29c330d942c | 68 | |
| Rohit Grover |
37:c29c330d942c | 69 | /**@brief Health Thermometer Service event handler type. */ |
| Rohit Grover |
37:c29c330d942c | 70 | typedef void (*ble_hts_evt_handler_t) (ble_hts_t * p_hts, ble_hts_evt_t * p_evt); |
| Rohit Grover |
37:c29c330d942c | 71 | |
| Rohit Grover |
37:c29c330d942c | 72 | /**@brief FLOAT format (IEEE-11073 32-bit FLOAT, defined as a 32-bit value with a 24-bit mantissa |
| Rohit Grover |
37:c29c330d942c | 73 | * and an 8-bit exponent. */ |
| Rohit Grover |
37:c29c330d942c | 74 | typedef struct |
| Rohit Grover |
37:c29c330d942c | 75 | { |
| Rohit Grover |
37:c29c330d942c | 76 | int8_t exponent; /**< Base 10 exponent */ |
| Rohit Grover |
37:c29c330d942c | 77 | int32_t mantissa; /**< Mantissa, should be using only 24 bits */ |
| Rohit Grover |
37:c29c330d942c | 78 | } ieee_float32_t; |
| Rohit Grover |
37:c29c330d942c | 79 | |
| Rohit Grover |
37:c29c330d942c | 80 | /**@brief Health Thermometer Service init structure. This contains all options and data |
| Rohit Grover |
37:c29c330d942c | 81 | * needed for initialization of the service. */ |
| Rohit Grover |
37:c29c330d942c | 82 | typedef struct |
| Rohit Grover |
37:c29c330d942c | 83 | { |
| Rohit Grover |
37:c29c330d942c | 84 | ble_hts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Health Thermometer Service. */ |
| Rohit Grover |
37:c29c330d942c | 85 | ble_srv_cccd_security_mode_t hts_meas_attr_md; /**< Initial security level for health thermometer measurement attribute */ |
| Rohit Grover |
37:c29c330d942c | 86 | ble_srv_security_mode_t hts_temp_type_attr_md; /**< Initial security level for health thermometer tempearture type attribute */ |
| Rohit Grover |
37:c29c330d942c | 87 | uint8_t temp_type_as_characteristic; /**< Set non-zero if temp type given as characteristic */ |
| Rohit Grover |
37:c29c330d942c | 88 | uint8_t temp_type; /**< Temperature type if temperature characteristic is used */ |
| Rohit Grover |
37:c29c330d942c | 89 | } ble_hts_init_t; |
| Rohit Grover |
37:c29c330d942c | 90 | |
| Rohit Grover |
37:c29c330d942c | 91 | /**@brief Health Thermometer Service structure. This contains various status information for |
| Rohit Grover |
37:c29c330d942c | 92 | * the service. */ |
| Rohit Grover |
37:c29c330d942c | 93 | typedef struct ble_hts_s |
| Rohit Grover |
37:c29c330d942c | 94 | { |
| Rohit Grover |
37:c29c330d942c | 95 | ble_hts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Health Thermometer Service. */ |
| Rohit Grover |
37:c29c330d942c | 96 | uint16_t service_handle; /**< Handle of Health Thermometer Service (as provided by the BLE stack). */ |
| Rohit Grover |
37:c29c330d942c | 97 | ble_gatts_char_handles_t meas_handles; /**< Handles related to the Health Thermometer Measurement characteristic. */ |
| Rohit Grover |
37:c29c330d942c | 98 | ble_gatts_char_handles_t temp_type_handles; /**< Handles related to the Health Thermometer Temperature Type characteristic. */ |
| Rohit Grover |
37:c29c330d942c | 99 | 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). */ |
| Rohit Grover |
37:c29c330d942c | 100 | uint8_t temp_type; /**< Temperature type indicates where the measurement was taken. */ |
| Rohit Grover |
37:c29c330d942c | 101 | } ble_hts_t; |
| Rohit Grover |
37:c29c330d942c | 102 | |
| Rohit Grover |
37:c29c330d942c | 103 | /**@brief Health Thermometer Service measurement structure. This contains a Health Thermometer |
| Rohit Grover |
37:c29c330d942c | 104 | * measurement. */ |
| Rohit Grover |
37:c29c330d942c | 105 | typedef struct ble_hts_meas_s |
| Rohit Grover |
37:c29c330d942c | 106 | { |
| Rohit Grover |
37:c29c330d942c | 107 | bool temp_in_fahr_units; /**< True if Temperature is in Fahrenheit units, Celcius otherwise. */ |
| Rohit Grover |
37:c29c330d942c | 108 | bool time_stamp_present; /**< True if Time Stamp is present. */ |
| Rohit Grover |
37:c29c330d942c | 109 | bool temp_type_present; /**< True if Temperature Type is present. */ |
| Rohit Grover |
37:c29c330d942c | 110 | ieee_float32_t temp_in_celcius; /**< Temperature Measurement Value (Celcius). */ |
| Rohit Grover |
37:c29c330d942c | 111 | ieee_float32_t temp_in_fahr; /**< Temperature Measurement Value (Fahrenheit). */ |
| Rohit Grover |
37:c29c330d942c | 112 | ble_date_time_t time_stamp; /**< Time Stamp. */ |
| Rohit Grover |
37:c29c330d942c | 113 | uint8_t temp_type; /**< Temperature Type. */ |
| Rohit Grover |
37:c29c330d942c | 114 | } ble_hts_meas_t; |
| Rohit Grover |
37:c29c330d942c | 115 | |
| Rohit Grover |
37:c29c330d942c | 116 | /**@brief Function for initializing the Health Thermometer Service. |
| Rohit Grover |
37:c29c330d942c | 117 | * |
| Rohit Grover |
37:c29c330d942c | 118 | * @param[out] p_hts Health Thermometer Service structure. This structure will have to |
| Rohit Grover |
37:c29c330d942c | 119 | * be supplied by the application. It will be initialized by this function, |
| Rohit Grover |
37:c29c330d942c | 120 | * and will later be used to identify this particular service instance. |
| Rohit Grover |
37:c29c330d942c | 121 | * @param[in] p_hts_init Information needed to initialize the service. |
| Rohit Grover |
37:c29c330d942c | 122 | * |
| Rohit Grover |
37:c29c330d942c | 123 | * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. |
| Rohit Grover |
37:c29c330d942c | 124 | */ |
| Rohit Grover |
37:c29c330d942c | 125 | uint32_t ble_hts_init(ble_hts_t * p_hts, const ble_hts_init_t * p_hts_init); |
| Rohit Grover |
37:c29c330d942c | 126 | |
| Rohit Grover |
37:c29c330d942c | 127 | /**@brief Function for handling the Application's BLE Stack events. |
| Rohit Grover |
37:c29c330d942c | 128 | * |
| Rohit Grover |
37:c29c330d942c | 129 | * @details Handles all events from the BLE stack of interest to the Health Thermometer Service. |
| Rohit Grover |
37:c29c330d942c | 130 | * |
| Rohit Grover |
37:c29c330d942c | 131 | * @param[in] p_hts Health Thermometer Service structure. |
| Rohit Grover |
37:c29c330d942c | 132 | * @param[in] p_ble_evt Event received from the BLE stack. |
| Rohit Grover |
37:c29c330d942c | 133 | */ |
| Rohit Grover |
37:c29c330d942c | 134 | void ble_hts_on_ble_evt(ble_hts_t * p_hts, ble_evt_t * p_ble_evt); |
| Rohit Grover |
37:c29c330d942c | 135 | |
| Rohit Grover |
37:c29c330d942c | 136 | /**@brief Function for sending health thermometer measurement if indication has been enabled. |
| Rohit Grover |
37:c29c330d942c | 137 | * |
| Rohit Grover |
37:c29c330d942c | 138 | * @details The application calls this function after having performed a Health Thermometer |
| Rohit Grover |
37:c29c330d942c | 139 | * measurement. If indication has been enabled, the measurement data is encoded and |
| Rohit Grover |
37:c29c330d942c | 140 | * sent to the client. |
| Rohit Grover |
37:c29c330d942c | 141 | * |
| Rohit Grover |
37:c29c330d942c | 142 | * @param[in] p_hts Health Thermometer Service structure. |
| Rohit Grover |
37:c29c330d942c | 143 | * @param[in] p_hts_meas Pointer to new health thermometer measurement. |
| Rohit Grover |
37:c29c330d942c | 144 | * |
| Rohit Grover |
37:c29c330d942c | 145 | * @return NRF_SUCCESS on success, otherwise an error code. |
| Rohit Grover |
37:c29c330d942c | 146 | */ |
| Rohit Grover |
37:c29c330d942c | 147 | uint32_t ble_hts_measurement_send(ble_hts_t * p_hts, ble_hts_meas_t * p_hts_meas); |
| Rohit Grover |
37:c29c330d942c | 148 | |
| Rohit Grover |
37:c29c330d942c | 149 | /**@brief Function for checking if indication of Temperature Measurement is currently enabled. |
| Rohit Grover |
37:c29c330d942c | 150 | * |
| Rohit Grover |
37:c29c330d942c | 151 | * @param[in] p_hts Health Thermometer Service structure. |
| Rohit Grover |
37:c29c330d942c | 152 | * @param[out] p_indication_enabled TRUE if indication is enabled, FALSE otherwise. |
| Rohit Grover |
37:c29c330d942c | 153 | * |
| Rohit Grover |
37:c29c330d942c | 154 | * @return NRF_SUCCESS on success, otherwise an error code. |
| Rohit Grover |
37:c29c330d942c | 155 | */ |
| Rohit Grover |
37:c29c330d942c | 156 | uint32_t ble_hts_is_indication_enabled(ble_hts_t * p_hts, bool * p_indication_enabled); |
| Rohit Grover |
37:c29c330d942c | 157 | |
| Rohit Grover |
37:c29c330d942c | 158 | #endif // BLE_HTS_H__ |
| Rohit Grover |
37:c29c330d942c | 159 | |
| Rohit Grover |
37:c29c330d942c | 160 | /** @} */ |
