テスト用です。

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_hts Health Thermometer Service
jksoft 0:8468a4403fea 15 * @{
jksoft 0:8468a4403fea 16 * @ingroup ble_sdk_srv
jksoft 0:8468a4403fea 17 * @brief Health Thermometer Service module.
jksoft 0:8468a4403fea 18 *
jksoft 0:8468a4403fea 19 * @details This module implements the Health Thermometer Service.
jksoft 0:8468a4403fea 20 *
jksoft 0:8468a4403fea 21 * If an event handler is supplied by the application, the Health Thermometer
jksoft 0:8468a4403fea 22 * Service will generate Health Thermometer Service events to the application.
jksoft 0:8468a4403fea 23 *
jksoft 0:8468a4403fea 24 * @note The application must propagate BLE stack events to the Health Thermometer Service
jksoft 0:8468a4403fea 25 * module by calling ble_hts_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_HTS_H__
jksoft 0:8468a4403fea 33 #define BLE_HTS_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 // Temperature Type measurement locations
jksoft 0:8468a4403fea 42 #define BLE_HTS_TEMP_TYPE_ARMPIT 1
jksoft 0:8468a4403fea 43 #define BLE_HTS_TEMP_TYPE_BODY 2
jksoft 0:8468a4403fea 44 #define BLE_HTS_TEMP_TYPE_EAR 3
jksoft 0:8468a4403fea 45 #define BLE_HTS_TEMP_TYPE_FINGER 4
jksoft 0:8468a4403fea 46 #define BLE_HTS_TEMP_TYPE_GI_TRACT 5
jksoft 0:8468a4403fea 47 #define BLE_HTS_TEMP_TYPE_MOUTH 6
jksoft 0:8468a4403fea 48 #define BLE_HTS_TEMP_TYPE_RECTUM 7
jksoft 0:8468a4403fea 49 #define BLE_HTS_TEMP_TYPE_TOE 8
jksoft 0:8468a4403fea 50 #define BLE_HTS_TEMP_TYPE_EAR_DRUM 9
jksoft 0:8468a4403fea 51
jksoft 0:8468a4403fea 52 /**@brief Health Thermometer Service event type. */
jksoft 0:8468a4403fea 53 typedef enum
jksoft 0:8468a4403fea 54 {
jksoft 0:8468a4403fea 55 BLE_HTS_EVT_INDICATION_ENABLED, /**< Health Thermometer value indication enabled event. */
jksoft 0:8468a4403fea 56 BLE_HTS_EVT_INDICATION_DISABLED, /**< Health Thermometer value indication disabled event. */
jksoft 0:8468a4403fea 57 BLE_HTS_EVT_INDICATION_CONFIRMED /**< Confirmation of a temperature measurement indication has been received. */
jksoft 0:8468a4403fea 58 } ble_hts_evt_type_t;
jksoft 0:8468a4403fea 59
jksoft 0:8468a4403fea 60 /**@brief Health Thermometer Service event. */
jksoft 0:8468a4403fea 61 typedef struct
jksoft 0:8468a4403fea 62 {
jksoft 0:8468a4403fea 63 ble_hts_evt_type_t evt_type; /**< Type of event. */
jksoft 0:8468a4403fea 64 } ble_hts_evt_t;
jksoft 0:8468a4403fea 65
jksoft 0:8468a4403fea 66 // Forward declaration of the ble_hts_t type.
jksoft 0:8468a4403fea 67 typedef struct ble_hts_s ble_hts_t;
jksoft 0:8468a4403fea 68
jksoft 0:8468a4403fea 69 /**@brief Health Thermometer Service event handler type. */
jksoft 0:8468a4403fea 70 typedef void (*ble_hts_evt_handler_t) (ble_hts_t * p_hts, ble_hts_evt_t * p_evt);
jksoft 0:8468a4403fea 71
jksoft 0:8468a4403fea 72 /**@brief FLOAT format (IEEE-11073 32-bit FLOAT, defined as a 32-bit value with a 24-bit mantissa
jksoft 0:8468a4403fea 73 * and an 8-bit exponent. */
jksoft 0:8468a4403fea 74 typedef struct
jksoft 0:8468a4403fea 75 {
jksoft 0:8468a4403fea 76 int8_t exponent; /**< Base 10 exponent */
jksoft 0:8468a4403fea 77 int32_t mantissa; /**< Mantissa, should be using only 24 bits */
jksoft 0:8468a4403fea 78 } ieee_float32_t;
jksoft 0:8468a4403fea 79
jksoft 0:8468a4403fea 80 /**@brief Health Thermometer Service init structure. This contains all options and data
jksoft 0:8468a4403fea 81 * needed for initialization of the service. */
jksoft 0:8468a4403fea 82 typedef struct
jksoft 0:8468a4403fea 83 {
jksoft 0:8468a4403fea 84 ble_hts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Health Thermometer Service. */
jksoft 0:8468a4403fea 85 ble_srv_cccd_security_mode_t hts_meas_attr_md; /**< Initial security level for health thermometer measurement attribute */
jksoft 0:8468a4403fea 86 ble_srv_security_mode_t hts_temp_type_attr_md; /**< Initial security level for health thermometer tempearture type attribute */
jksoft 0:8468a4403fea 87 uint8_t temp_type_as_characteristic; /**< Set non-zero if temp type given as characteristic */
jksoft 0:8468a4403fea 88 uint8_t temp_type; /**< Temperature type if temperature characteristic is used */
jksoft 0:8468a4403fea 89 } ble_hts_init_t;
jksoft 0:8468a4403fea 90
jksoft 0:8468a4403fea 91 /**@brief Health Thermometer Service structure. This contains various status information for
jksoft 0:8468a4403fea 92 * the service. */
jksoft 0:8468a4403fea 93 typedef struct ble_hts_s
jksoft 0:8468a4403fea 94 {
jksoft 0:8468a4403fea 95 ble_hts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Health Thermometer Service. */
jksoft 0:8468a4403fea 96 uint16_t service_handle; /**< Handle of Health Thermometer Service (as provided by the BLE stack). */
jksoft 0:8468a4403fea 97 ble_gatts_char_handles_t meas_handles; /**< Handles related to the Health Thermometer Measurement characteristic. */
jksoft 0:8468a4403fea 98 ble_gatts_char_handles_t temp_type_handles; /**< Handles related to the Health Thermometer Temperature Type characteristic. */
jksoft 0:8468a4403fea 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). */
jksoft 0:8468a4403fea 100 uint8_t temp_type; /**< Temperature type indicates where the measurement was taken. */
jksoft 0:8468a4403fea 101 } ble_hts_t;
jksoft 0:8468a4403fea 102
jksoft 0:8468a4403fea 103 /**@brief Health Thermometer Service measurement structure. This contains a Health Thermometer
jksoft 0:8468a4403fea 104 * measurement. */
jksoft 0:8468a4403fea 105 typedef struct ble_hts_meas_s
jksoft 0:8468a4403fea 106 {
jksoft 0:8468a4403fea 107 bool temp_in_fahr_units; /**< True if Temperature is in Fahrenheit units, Celcius otherwise. */
jksoft 0:8468a4403fea 108 bool time_stamp_present; /**< True if Time Stamp is present. */
jksoft 0:8468a4403fea 109 bool temp_type_present; /**< True if Temperature Type is present. */
jksoft 0:8468a4403fea 110 ieee_float32_t temp_in_celcius; /**< Temperature Measurement Value (Celcius). */
jksoft 0:8468a4403fea 111 ieee_float32_t temp_in_fahr; /**< Temperature Measurement Value (Fahrenheit). */
jksoft 0:8468a4403fea 112 ble_date_time_t time_stamp; /**< Time Stamp. */
jksoft 0:8468a4403fea 113 uint8_t temp_type; /**< Temperature Type. */
jksoft 0:8468a4403fea 114 } ble_hts_meas_t;
jksoft 0:8468a4403fea 115
jksoft 0:8468a4403fea 116 /**@brief Function for initializing the Health Thermometer Service.
jksoft 0:8468a4403fea 117 *
jksoft 0:8468a4403fea 118 * @param[out] p_hts Health Thermometer Service structure. This structure will have to
jksoft 0:8468a4403fea 119 * be supplied by the application. It will be initialized by this function,
jksoft 0:8468a4403fea 120 * and will later be used to identify this particular service instance.
jksoft 0:8468a4403fea 121 * @param[in] p_hts_init Information needed to initialize the service.
jksoft 0:8468a4403fea 122 *
jksoft 0:8468a4403fea 123 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
jksoft 0:8468a4403fea 124 */
jksoft 0:8468a4403fea 125 uint32_t ble_hts_init(ble_hts_t * p_hts, const ble_hts_init_t * p_hts_init);
jksoft 0:8468a4403fea 126
jksoft 0:8468a4403fea 127 /**@brief Function for handling the Application's BLE Stack events.
jksoft 0:8468a4403fea 128 *
jksoft 0:8468a4403fea 129 * @details Handles all events from the BLE stack of interest to the Health Thermometer Service.
jksoft 0:8468a4403fea 130 *
jksoft 0:8468a4403fea 131 * @param[in] p_hts Health Thermometer Service structure.
jksoft 0:8468a4403fea 132 * @param[in] p_ble_evt Event received from the BLE stack.
jksoft 0:8468a4403fea 133 */
jksoft 0:8468a4403fea 134 void ble_hts_on_ble_evt(ble_hts_t * p_hts, ble_evt_t * p_ble_evt);
jksoft 0:8468a4403fea 135
jksoft 0:8468a4403fea 136 /**@brief Function for sending health thermometer measurement if indication has been enabled.
jksoft 0:8468a4403fea 137 *
jksoft 0:8468a4403fea 138 * @details The application calls this function after having performed a Health Thermometer
jksoft 0:8468a4403fea 139 * measurement. If indication has been enabled, the measurement data is encoded and
jksoft 0:8468a4403fea 140 * sent to the client.
jksoft 0:8468a4403fea 141 *
jksoft 0:8468a4403fea 142 * @param[in] p_hts Health Thermometer Service structure.
jksoft 0:8468a4403fea 143 * @param[in] p_hts_meas Pointer to new health thermometer measurement.
jksoft 0:8468a4403fea 144 *
jksoft 0:8468a4403fea 145 * @return NRF_SUCCESS on success, otherwise an error code.
jksoft 0:8468a4403fea 146 */
jksoft 0:8468a4403fea 147 uint32_t ble_hts_measurement_send(ble_hts_t * p_hts, ble_hts_meas_t * p_hts_meas);
jksoft 0:8468a4403fea 148
jksoft 0:8468a4403fea 149 /**@brief Function for checking if indication of Temperature Measurement is currently enabled.
jksoft 0:8468a4403fea 150 *
jksoft 0:8468a4403fea 151 * @param[in] p_hts Health Thermometer Service structure.
jksoft 0:8468a4403fea 152 * @param[out] p_indication_enabled TRUE if indication is enabled, FALSE otherwise.
jksoft 0:8468a4403fea 153 *
jksoft 0:8468a4403fea 154 * @return NRF_SUCCESS on success, otherwise an error code.
jksoft 0:8468a4403fea 155 */
jksoft 0:8468a4403fea 156 uint32_t ble_hts_is_indication_enabled(ble_hts_t * p_hts, bool * p_indication_enabled);
jksoft 0:8468a4403fea 157
jksoft 0:8468a4403fea 158 #endif // BLE_HTS_H__
jksoft 0:8468a4403fea 159
jksoft 0:8468a4403fea 160 /** @} */