For with fix for disconnection notifications

Fork of nRF51822 by Nordic Semiconductor

Committer:
janekm
Date:
Wed Sep 03 17:19:53 2014 +0000
Revision:
61:057be2a0cd38
Parent:
37:c29c330d942c
Fix disconnection notification to application (used to only notify on locally initiated disconnection)

Who changed what in which revision?

UserRevisionLine numberNew 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
Rohit Grover 37:c29c330d942c 13 /** @file
Rohit Grover 37:c29c330d942c 14 *
Rohit Grover 37:c29c330d942c 15 * @defgroup ble_sdk_srv_rsc Running Speed and Cadence Service
Rohit Grover 37:c29c330d942c 16 * @{
Rohit Grover 37:c29c330d942c 17 * @ingroup ble_sdk_srv
Rohit Grover 37:c29c330d942c 18 * @brief Running Speed and Cadence Service module.
Rohit Grover 37:c29c330d942c 19 *
Rohit Grover 37:c29c330d942c 20 * @details This module implements the Running Speed and Cadence Service. If enabled, notification
Rohit Grover 37:c29c330d942c 21 * of the Running Speead and Candence Measurement is performed when the application
Rohit Grover 37:c29c330d942c 22 * calls ble_rscs_measurement_send().
Rohit Grover 37:c29c330d942c 23 *
Rohit Grover 37:c29c330d942c 24 * If an event handler is supplied by the application, the Running Speed and Cadence
Rohit Grover 37:c29c330d942c 25 * Service will generate Running Speed and Cadence Service events to the application.
Rohit Grover 37:c29c330d942c 26 *
Rohit Grover 37:c29c330d942c 27 * @note The application must propagate BLE stack events to the Running Speead and Candence Service
Rohit Grover 37:c29c330d942c 28 * module by calling ble_rscs_on_ble_evt() from the from the @ref ble_stack_handler function.
Rohit Grover 37:c29c330d942c 29 *
Rohit Grover 37:c29c330d942c 30 * @note Attention!
Rohit Grover 37:c29c330d942c 31 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
Rohit Grover 37:c29c330d942c 32 * qualification listings, this section of source code must not be modified.
Rohit Grover 37:c29c330d942c 33 */
Rohit Grover 37:c29c330d942c 34
Rohit Grover 37:c29c330d942c 35 #ifndef BLE_RSCS_H__
Rohit Grover 37:c29c330d942c 36 #define BLE_RSCS_H__
Rohit Grover 37:c29c330d942c 37
Rohit Grover 37:c29c330d942c 38 #include <stdint.h>
Rohit Grover 37:c29c330d942c 39 #include <stdbool.h>
Rohit Grover 37:c29c330d942c 40 #include "ble.h"
Rohit Grover 37:c29c330d942c 41 #include "ble_srv_common.h"
Rohit Grover 37:c29c330d942c 42
Rohit Grover 37:c29c330d942c 43 /**@brief Running Speed and Cadence Service feature bits. */
Rohit Grover 37:c29c330d942c 44 #define BLE_RSCS_FEATURE_INSTANT_STRIDE_LEN_BIT (0x01 << 0) /**< Instantaneous Stride Length Measurement Supported bit. */
Rohit Grover 37:c29c330d942c 45 #define BLE_RSCS_FEATURE_TOTAL_DISTANCE_BIT (0x01 << 1) /**< Total Distance Measurement Supported bit. */
Rohit Grover 37:c29c330d942c 46 #define BLE_RSCS_FEATURE_WALKING_OR_RUNNING_STATUS_BIT (0x01 << 2) /**< Walking or Running Status Supported bit. */
Rohit Grover 37:c29c330d942c 47 #define BLE_RSCS_FEATURE_CALIBRATION_PROCEDURE_BIT (0x01 << 3) /**< Calibration Procedure Supported bit. */
Rohit Grover 37:c29c330d942c 48 #define BLE_RSCS_FEATURE_MULTIPLE_SENSORS_BIT (0x01 << 4) /**< Multiple Sensor Locations Supported bit. */
Rohit Grover 37:c29c330d942c 49
Rohit Grover 37:c29c330d942c 50 /**@brief Running Speed and Cadence Service event type. */
Rohit Grover 37:c29c330d942c 51 typedef enum
Rohit Grover 37:c29c330d942c 52 {
Rohit Grover 37:c29c330d942c 53 BLE_RSCS_EVT_NOTIFICATION_ENABLED, /**< Running Speed and Cadence value notification enabled event. */
Rohit Grover 37:c29c330d942c 54 BLE_RSCS_EVT_NOTIFICATION_DISABLED /**< Running Speed and Cadence value notification disabled event. */
Rohit Grover 37:c29c330d942c 55 } ble_rscs_evt_type_t;
Rohit Grover 37:c29c330d942c 56
Rohit Grover 37:c29c330d942c 57 /**@brief Running Speed and Cadence Service event. */
Rohit Grover 37:c29c330d942c 58 typedef struct
Rohit Grover 37:c29c330d942c 59 {
Rohit Grover 37:c29c330d942c 60 ble_rscs_evt_type_t evt_type; /**< Type of event. */
Rohit Grover 37:c29c330d942c 61 } ble_rscs_evt_t;
Rohit Grover 37:c29c330d942c 62
Rohit Grover 37:c29c330d942c 63 // Forward declaration of the ble_rsc_t type.
Rohit Grover 37:c29c330d942c 64 typedef struct ble_rscs_s ble_rscs_t;
Rohit Grover 37:c29c330d942c 65
Rohit Grover 37:c29c330d942c 66 /**@brief Running Speed and Cadence Service event handler type. */
Rohit Grover 37:c29c330d942c 67 typedef void (*ble_rscs_evt_handler_t) (ble_rscs_t * p_rscs, ble_rscs_evt_t * p_evt);
Rohit Grover 37:c29c330d942c 68
Rohit Grover 37:c29c330d942c 69 /**@brief Running Speed and Cadence Service init structure. This contains all options and data
Rohit Grover 37:c29c330d942c 70 * needed for initialization of the service. */
Rohit Grover 37:c29c330d942c 71 typedef struct
Rohit Grover 37:c29c330d942c 72 {
Rohit Grover 37:c29c330d942c 73 ble_rscs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Running Speed and Cadence Service. */
Rohit Grover 37:c29c330d942c 74 ble_srv_cccd_security_mode_t rsc_meas_attr_md; /**< Initial security level for running speed and cadence measurement attribute */
Rohit Grover 37:c29c330d942c 75 ble_srv_security_mode_t rsc_feature_attr_md; /**< Initial security level for feature attribute */
Rohit Grover 37:c29c330d942c 76 uint16_t feature; /**< Initial value for features of sensor. */
Rohit Grover 37:c29c330d942c 77 } ble_rscs_init_t;
Rohit Grover 37:c29c330d942c 78
Rohit Grover 37:c29c330d942c 79 /**@brief Running Speed and Cadence Service structure. This contains various status information for
Rohit Grover 37:c29c330d942c 80 * the service. */
Rohit Grover 37:c29c330d942c 81 typedef struct ble_rscs_s
Rohit Grover 37:c29c330d942c 82 {
Rohit Grover 37:c29c330d942c 83 ble_rscs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Running Speed and Cadence Service. */
Rohit Grover 37:c29c330d942c 84 uint16_t service_handle; /**< Handle of Running Speed and Cadence Service (as provided by the BLE stack). */
Rohit Grover 37:c29c330d942c 85 ble_gatts_char_handles_t meas_handles; /**< Handles related to the Running Speed and Cadence Measurement characteristic. */
Rohit Grover 37:c29c330d942c 86 ble_gatts_char_handles_t feature_handles; /**< Handles related to the Running Speed and Cadence feature characteristic. */
Rohit Grover 37:c29c330d942c 87 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 88 uint16_t feature; /**< Bit mask of features available on sensor. */
Rohit Grover 37:c29c330d942c 89 } ble_rscs_t;
Rohit Grover 37:c29c330d942c 90
Rohit Grover 37:c29c330d942c 91 /**@brief Running Speed and Cadence Service measurement structure. This contains a Running Speed and
Rohit Grover 37:c29c330d942c 92 * Cadence measurement. */
Rohit Grover 37:c29c330d942c 93 typedef struct ble_rscs_meas_s
Rohit Grover 37:c29c330d942c 94 {
Rohit Grover 37:c29c330d942c 95 bool is_inst_stride_len_present; /**< True if Instantaneous Stride Length is present in the measurement. */
Rohit Grover 37:c29c330d942c 96 bool is_total_distance_present; /**< True if Total Distance is present in the measurement. */
Rohit Grover 37:c29c330d942c 97 bool is_running; /**< True if running, False if walking. */
Rohit Grover 37:c29c330d942c 98 uint16_t inst_speed; /**< Instantaneous Speed. */
Rohit Grover 37:c29c330d942c 99 uint8_t inst_cadence; /**< Instantaneous Cadence. */
Rohit Grover 37:c29c330d942c 100 uint16_t inst_stride_length; /**< Instantaneous Stride Length. */
Rohit Grover 37:c29c330d942c 101 uint32_t total_distance; /**< Total Distance. */
Rohit Grover 37:c29c330d942c 102 } ble_rscs_meas_t;
Rohit Grover 37:c29c330d942c 103
Rohit Grover 37:c29c330d942c 104 /**@brief Function for initializing the Running Speed and Cadence Service.
Rohit Grover 37:c29c330d942c 105 *
Rohit Grover 37:c29c330d942c 106 * @param[out] p_rscs Running Speed and Cadence Service structure. This structure will have to
Rohit Grover 37:c29c330d942c 107 * be supplied by the application. It will be initialized by this function,
Rohit Grover 37:c29c330d942c 108 * and will later be used to identify this particular service instance.
Rohit Grover 37:c29c330d942c 109 * @param[in] p_rscs_init Information needed to initialize the service.
Rohit Grover 37:c29c330d942c 110 *
Rohit Grover 37:c29c330d942c 111 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
Rohit Grover 37:c29c330d942c 112 */
Rohit Grover 37:c29c330d942c 113 uint32_t ble_rscs_init(ble_rscs_t * p_rscs, const ble_rscs_init_t * p_rscs_init);
Rohit Grover 37:c29c330d942c 114
Rohit Grover 37:c29c330d942c 115 /**@brief Function for handling the Application's BLE Stack events.
Rohit Grover 37:c29c330d942c 116 *
Rohit Grover 37:c29c330d942c 117 * @details Handles all events from the BLE stack of interest to the Running Speed and Cadence
Rohit Grover 37:c29c330d942c 118 * Service.
Rohit Grover 37:c29c330d942c 119 *
Rohit Grover 37:c29c330d942c 120 * @param[in] p_rscs Running Speed and Cadence Service structure.
Rohit Grover 37:c29c330d942c 121 * @param[in] p_ble_evt Event received from the BLE stack.
Rohit Grover 37:c29c330d942c 122 */
Rohit Grover 37:c29c330d942c 123 void ble_rscs_on_ble_evt(ble_rscs_t * p_rscs, ble_evt_t * p_ble_evt);
Rohit Grover 37:c29c330d942c 124
Rohit Grover 37:c29c330d942c 125 /**@brief Function for sending running speed and cadence measurement if notification has been enabled.
Rohit Grover 37:c29c330d942c 126 *
Rohit Grover 37:c29c330d942c 127 * @details The application calls this function after having performed a Running Speed and Cadence
Rohit Grover 37:c29c330d942c 128 * measurement. If notification has been enabled, the measurement data is encoded and sent
Rohit Grover 37:c29c330d942c 129 * to the client.
Rohit Grover 37:c29c330d942c 130 *
Rohit Grover 37:c29c330d942c 131 * @param[in] p_rscs Running Speed and Cadence Service structure.
Rohit Grover 37:c29c330d942c 132 * @param[in] p_measurement Pointer to new running speed and cadence measurement.
Rohit Grover 37:c29c330d942c 133 *
Rohit Grover 37:c29c330d942c 134 * @return NRF_SUCCESS on success, otherwise an error code.
Rohit Grover 37:c29c330d942c 135 */
Rohit Grover 37:c29c330d942c 136 uint32_t ble_rscs_measurement_send(ble_rscs_t * p_rscs, ble_rscs_meas_t * p_measurement);
Rohit Grover 37:c29c330d942c 137
Rohit Grover 37:c29c330d942c 138 #endif // BLE_RSCS_H__
Rohit Grover 37:c29c330d942c 139
Rohit Grover 37:c29c330d942c 140 /** @} */