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