For with fix for disconnection notifications
Fork of nRF51822 by
nordic/nrf-sdk/ble/ble_services/ble_sc_ctrlpt.h@61:057be2a0cd38, 2014-09-03 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rohit Grover |
37:c29c330d942c | 1 | /* Copyright (c) 2013 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_sc_ctrlpt Speed and Cadence Control Point |
Rohit Grover |
37:c29c330d942c | 16 | * @{ |
Rohit Grover |
37:c29c330d942c | 17 | * @ingroup ble_sdk_srv |
Rohit Grover |
37:c29c330d942c | 18 | * @brief Speed and Cadence Control Point module. |
Rohit Grover |
37:c29c330d942c | 19 | * |
Rohit Grover |
37:c29c330d942c | 20 | * @details This module implements the Speed and Cadence control point behavior. It is used |
Rohit Grover |
37:c29c330d942c | 21 | * by the @ref ble_sdk_srv_csc module and the ble_sdk_srv_rsc module for control point |
Rohit Grover |
37:c29c330d942c | 22 | * mechanisms like setting a cumulative value, Start an automatic calibration, |
Rohit Grover |
37:c29c330d942c | 23 | * Update the sensor location or request the supported locations. |
Rohit Grover |
37:c29c330d942c | 24 | * |
Rohit Grover |
37:c29c330d942c | 25 | * @note Attention! |
Rohit Grover |
37:c29c330d942c | 26 | * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile |
Rohit Grover |
37:c29c330d942c | 27 | * qualification listings, this section of source code must not be modified. |
Rohit Grover |
37:c29c330d942c | 28 | */ |
Rohit Grover |
37:c29c330d942c | 29 | |
Rohit Grover |
37:c29c330d942c | 30 | #ifndef BLE_SC_CTRLPT_H__ |
Rohit Grover |
37:c29c330d942c | 31 | #define BLE_SC_CTRLPT_H__ |
Rohit Grover |
37:c29c330d942c | 32 | |
Rohit Grover |
37:c29c330d942c | 33 | #include <stdint.h> |
Rohit Grover |
37:c29c330d942c | 34 | #include <stdbool.h> |
Rohit Grover |
37:c29c330d942c | 35 | #include "ble.h" |
Rohit Grover |
37:c29c330d942c | 36 | #include "ble_srv_common.h" |
Rohit Grover |
37:c29c330d942c | 37 | #include "ble_sensor_location.h" |
Rohit Grover |
37:c29c330d942c | 38 | |
Rohit Grover |
37:c29c330d942c | 39 | #define BLE_SC_CTRLPT_MAX_LEN 19 /**< maximum lenght for Speed and cadence control point characteristic value. */ |
Rohit Grover |
37:c29c330d942c | 40 | #define BLE_SC_CTRLPT_MIN_LEN 1 /**< minimum length for Speed and cadence control point characteristic value. */ |
Rohit Grover |
37:c29c330d942c | 41 | |
Rohit Grover |
37:c29c330d942c | 42 | // Forward declaration of the ble_sc_ctrlpt_t type. |
Rohit Grover |
37:c29c330d942c | 43 | typedef struct ble_sc_ctrlpt_s ble_sc_ctrlpt_t; |
Rohit Grover |
37:c29c330d942c | 44 | |
Rohit Grover |
37:c29c330d942c | 45 | |
Rohit Grover |
37:c29c330d942c | 46 | /**@brief Speed and Cadence Control Point event type. */ |
Rohit Grover |
37:c29c330d942c | 47 | typedef enum |
Rohit Grover |
37:c29c330d942c | 48 | { |
Rohit Grover |
37:c29c330d942c | 49 | BLE_SC_CTRLPT_EVT_UPDATE_LOCATION, /**< rcvd update location opcode (the control point handles the change of location automatically, the event just informs the application in case it needs to adjust its algorithm). */ |
Rohit Grover |
37:c29c330d942c | 50 | BLE_SC_CTRLPT_EVT_SET_CUMUL_VALUE, /**< rcvd set cumulative value opcode, it is then up to the application to use the new cumulative value. */ |
Rohit Grover |
37:c29c330d942c | 51 | BLE_SC_CTRLPT_EVT_START_CALIBRATION, /**< rcvd start calibration opcode, the application needs, at the end ot the calibration to call ble_sc_ctrlpt_send_rsp. */ |
Rohit Grover |
37:c29c330d942c | 52 | } ble_sc_ctrlpt_evt_type_t; |
Rohit Grover |
37:c29c330d942c | 53 | |
Rohit Grover |
37:c29c330d942c | 54 | |
Rohit Grover |
37:c29c330d942c | 55 | /**@brief Speed and Cadence Control point event. */ |
Rohit Grover |
37:c29c330d942c | 56 | typedef struct |
Rohit Grover |
37:c29c330d942c | 57 | { |
Rohit Grover |
37:c29c330d942c | 58 | ble_sc_ctrlpt_evt_type_t evt_type; /**< Type of event. */ |
Rohit Grover |
37:c29c330d942c | 59 | union |
Rohit Grover |
37:c29c330d942c | 60 | { |
Rohit Grover |
37:c29c330d942c | 61 | ble_sensor_location_t update_location; |
Rohit Grover |
37:c29c330d942c | 62 | uint32_t cumulative_value; |
Rohit Grover |
37:c29c330d942c | 63 | }params; |
Rohit Grover |
37:c29c330d942c | 64 | } ble_sc_ctrlpt_evt_t; |
Rohit Grover |
37:c29c330d942c | 65 | |
Rohit Grover |
37:c29c330d942c | 66 | |
Rohit Grover |
37:c29c330d942c | 67 | /** Speed and Cadence Control Point operator code (see RSC service specification)*/ |
Rohit Grover |
37:c29c330d942c | 68 | typedef enum { |
Rohit Grover |
37:c29c330d942c | 69 | BLE_SCPT_SET_CUMULATIVE_VALUE = 0x01, /**< Operator to set a given cumulative value. */ |
Rohit Grover |
37:c29c330d942c | 70 | BLE_SCPT_START_AUTOMATIC_CALIBRATION = 0x02, /**< Operator to start automatic calibration. */ |
Rohit Grover |
37:c29c330d942c | 71 | BLE_SCPT_UPDATE_SENSOR_LOCATION = 0x03, /**< Operator to update the sensor location. */ |
Rohit Grover |
37:c29c330d942c | 72 | BLE_SCPT_REQUEST_SUPPORTED_SENSOR_LOCATIONS = 0x04, /**< Operator to request the supported sensor locations. */ |
Rohit Grover |
37:c29c330d942c | 73 | BLE_SCPT_RESPONSE_CODE = 0x10, /**< Response Code. */ |
Rohit Grover |
37:c29c330d942c | 74 | } ble_scpt_operator_t; |
Rohit Grover |
37:c29c330d942c | 75 | |
Rohit Grover |
37:c29c330d942c | 76 | |
Rohit Grover |
37:c29c330d942c | 77 | /** Speed and Cadence Control Point response parameter (see RSC service specification)*/ |
Rohit Grover |
37:c29c330d942c | 78 | typedef enum { |
Rohit Grover |
37:c29c330d942c | 79 | BLE_SCPT_SUCCESS = 0x01, /**< Sucess Response. */ |
Rohit Grover |
37:c29c330d942c | 80 | BLE_SCPT_OP_CODE_NOT_SUPPORTED = 0x02, /**< Error Response received opcode not supported. */ |
Rohit Grover |
37:c29c330d942c | 81 | BLE_SCPT_INVALID_PARAMETER = 0x03, /**< Error Response received parameter invalid. */ |
Rohit Grover |
37:c29c330d942c | 82 | BLE_SCPT_OPERATION_FAILED = 0x04, /**< Error Response operation failed. */ |
Rohit Grover |
37:c29c330d942c | 83 | } ble_scpt_response_t; |
Rohit Grover |
37:c29c330d942c | 84 | |
Rohit Grover |
37:c29c330d942c | 85 | |
Rohit Grover |
37:c29c330d942c | 86 | /** Speed and Cadence Control Point procedure status (indicates is a procedure is in progress or not and which procedure is in progress*/ |
Rohit Grover |
37:c29c330d942c | 87 | typedef enum { |
Rohit Grover |
37:c29c330d942c | 88 | BLE_SCPT_NO_PROC_IN_PROGRESS = 0x00, /**< No procedure in progress. */ |
Rohit Grover |
37:c29c330d942c | 89 | BLE_SCPT_AUTOMATIC_CALIB_IN_PROGRESS = 0x01, /**< Automatic Calibration is in progress. */ |
Rohit Grover |
37:c29c330d942c | 90 | BLE_SCPT_INDICATION_PENDING = 0x02, /**< Control Point Indication is pending. */ |
Rohit Grover |
37:c29c330d942c | 91 | BLE_SCPT_IND_CONFIRM_PENDING = 0x03, /**< Waiting for the indication confirmation. */ |
Rohit Grover |
37:c29c330d942c | 92 | }ble_scpt_procedure_status_t; |
Rohit Grover |
37:c29c330d942c | 93 | |
Rohit Grover |
37:c29c330d942c | 94 | /**@brief Speed and Cadence Control point event handler type. */ |
Rohit Grover |
37:c29c330d942c | 95 | typedef ble_scpt_response_t (*ble_sc_ctrlpt_evt_handler_t) (ble_sc_ctrlpt_t * p_sc_ctrlpt, |
Rohit Grover |
37:c29c330d942c | 96 | ble_sc_ctrlpt_evt_t * p_evt); |
Rohit Grover |
37:c29c330d942c | 97 | |
Rohit Grover |
37:c29c330d942c | 98 | |
Rohit Grover |
37:c29c330d942c | 99 | typedef struct{ |
Rohit Grover |
37:c29c330d942c | 100 | ble_scpt_operator_t opcode; |
Rohit Grover |
37:c29c330d942c | 101 | uint32_t cumulative_value; |
Rohit Grover |
37:c29c330d942c | 102 | ble_sensor_location_t location; |
Rohit Grover |
37:c29c330d942c | 103 | }ble_sc_ctrlpt_val_t; |
Rohit Grover |
37:c29c330d942c | 104 | |
Rohit Grover |
37:c29c330d942c | 105 | |
Rohit Grover |
37:c29c330d942c | 106 | typedef struct{ |
Rohit Grover |
37:c29c330d942c | 107 | ble_scpt_operator_t opcode; |
Rohit Grover |
37:c29c330d942c | 108 | ble_scpt_response_t status; |
Rohit Grover |
37:c29c330d942c | 109 | ble_sensor_location_t location_list[BLE_NB_MAX_SENSOR_LOCATIONS]; |
Rohit Grover |
37:c29c330d942c | 110 | }ble_sc_ctrlpt_rsp_t; |
Rohit Grover |
37:c29c330d942c | 111 | |
Rohit Grover |
37:c29c330d942c | 112 | |
Rohit Grover |
37:c29c330d942c | 113 | |
Rohit Grover |
37:c29c330d942c | 114 | #define BLE_SRV_SC_CTRLPT_SENSOR_LOCATIONS_OP_SUPPORTED 0x01 /**< Support for sensor location related operations */ |
Rohit Grover |
37:c29c330d942c | 115 | #define BLE_SRV_SC_CTRLPT_CUM_VAL_OP_SUPPORTED 0x02 /**< Support for setting cumulative value related operations */ |
Rohit Grover |
37:c29c330d942c | 116 | #define BLE_SRV_SC_CTRLPT_START_CALIB_OP_SUPPORTED 0x04 /**< Support for starting calibration related operations */ |
Rohit Grover |
37:c29c330d942c | 117 | |
Rohit Grover |
37:c29c330d942c | 118 | |
Rohit Grover |
37:c29c330d942c | 119 | /**@brief Speed and Cadence Control Point init structure. This contains all options and data |
Rohit Grover |
37:c29c330d942c | 120 | * needed for initialization of the Speed and Cadence Control Point module. */ |
Rohit Grover |
37:c29c330d942c | 121 | typedef struct |
Rohit Grover |
37:c29c330d942c | 122 | { |
Rohit Grover |
37:c29c330d942c | 123 | ble_srv_cccd_security_mode_t sc_ctrlpt_attr_md; /**< Initial security level for cycling speed and cadence control point attribute */ |
Rohit Grover |
37:c29c330d942c | 124 | uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */ |
Rohit Grover |
37:c29c330d942c | 125 | uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */ |
Rohit Grover |
37:c29c330d942c | 126 | ble_sc_ctrlpt_evt_handler_t evt_handler; /**< event handler */ |
Rohit Grover |
37:c29c330d942c | 127 | ble_sensor_location_t *list_supported_locations; /**< list of supported sensor locations.*/ |
Rohit Grover |
37:c29c330d942c | 128 | uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/ |
Rohit Grover |
37:c29c330d942c | 129 | uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/ |
Rohit Grover |
37:c29c330d942c | 130 | ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ |
Rohit Grover |
37:c29c330d942c | 131 | } ble_cs_ctrlpt_init_t; |
Rohit Grover |
37:c29c330d942c | 132 | |
Rohit Grover |
37:c29c330d942c | 133 | |
Rohit Grover |
37:c29c330d942c | 134 | /**@brief Speed and Cadence Control Point response indication structure. */ |
Rohit Grover |
37:c29c330d942c | 135 | typedef struct |
Rohit Grover |
37:c29c330d942c | 136 | { |
Rohit Grover |
37:c29c330d942c | 137 | ble_scpt_response_t status; /**< control point response status .*/ |
Rohit Grover |
37:c29c330d942c | 138 | uint8_t len; /**< control point response length .*/ |
Rohit Grover |
37:c29c330d942c | 139 | uint8_t encoded_ctrl_rsp[BLE_SC_CTRLPT_MAX_LEN]; /**< control point encoded response.*/ |
Rohit Grover |
37:c29c330d942c | 140 | }ble_sc_ctrlpt_resp_t; |
Rohit Grover |
37:c29c330d942c | 141 | |
Rohit Grover |
37:c29c330d942c | 142 | |
Rohit Grover |
37:c29c330d942c | 143 | /**@brief Speed and Cadence Control Point structure. This contains various status information for |
Rohit Grover |
37:c29c330d942c | 144 | * the Speed and Cadence Control Point behavior. */ |
Rohit Grover |
37:c29c330d942c | 145 | typedef struct ble_sc_ctrlpt_s |
Rohit Grover |
37:c29c330d942c | 146 | { |
Rohit Grover |
37:c29c330d942c | 147 | uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */ |
Rohit Grover |
37:c29c330d942c | 148 | uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */ |
Rohit Grover |
37:c29c330d942c | 149 | ble_gatts_char_handles_t sc_ctrlpt_handles; /**< Handles related to the Speed and Cadence Control Point characteristic. */ |
Rohit Grover |
37:c29c330d942c | 150 | 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 | 151 | ble_sensor_location_t list_supported_locations[BLE_NB_MAX_SENSOR_LOCATIONS]; /**< list of supported sensor locations.*/ |
Rohit Grover |
37:c29c330d942c | 152 | uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/ |
Rohit Grover |
37:c29c330d942c | 153 | ble_sc_ctrlpt_evt_handler_t evt_handler; /**< Handle of the parent service (as provided by the BLE stack). */ |
Rohit Grover |
37:c29c330d942c | 154 | uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/ |
Rohit Grover |
37:c29c330d942c | 155 | ble_scpt_procedure_status_t procedure_status; /**< status of possible procedure*/ |
Rohit Grover |
37:c29c330d942c | 156 | ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ |
Rohit Grover |
37:c29c330d942c | 157 | ble_sc_ctrlpt_resp_t response; /**< pending response data.*/ |
Rohit Grover |
37:c29c330d942c | 158 | } ble_sc_ctrlpt_t; |
Rohit Grover |
37:c29c330d942c | 159 | |
Rohit Grover |
37:c29c330d942c | 160 | #define SCPT_OPCODE_POS 0 /**< Request opcode position. */ |
Rohit Grover |
37:c29c330d942c | 161 | #define SCPT_PARAMETER_POS 1 /**< Request parameter position. */ |
Rohit Grover |
37:c29c330d942c | 162 | |
Rohit Grover |
37:c29c330d942c | 163 | #define SCPT_RESPONSE_REQUEST_OPCODE_POS 1 /**< Response position of requested opcode. */ |
Rohit Grover |
37:c29c330d942c | 164 | #define SCPT_RESPONSE_CODE_POS 2 /**< Response position of response code. */ |
Rohit Grover |
37:c29c330d942c | 165 | #define SCPT_RESPONSE_PARAMETER 3 /**< Response position of response parameter. */ |
Rohit Grover |
37:c29c330d942c | 166 | |
Rohit Grover |
37:c29c330d942c | 167 | #define SCPT_MIN_RESPONSE_SIZE 3 /**< Minimum size for control point response. */ |
Rohit Grover |
37:c29c330d942c | 168 | #define SCPT_MAX_RESPONSE_SIZE (SCPT_MIN_RESPONSE_SIZE + NB_MAX_SENSOR_LOCATIONS) /**< Maximum size for control point response. */ |
Rohit Grover |
37:c29c330d942c | 169 | |
Rohit Grover |
37:c29c330d942c | 170 | |
Rohit Grover |
37:c29c330d942c | 171 | /**@brief Function for Initializing the Speed and Cadence Control Point. |
Rohit Grover |
37:c29c330d942c | 172 | * |
Rohit Grover |
37:c29c330d942c | 173 | * @details Function for Initializing the Speed and Cadence Control Point. |
Rohit Grover |
37:c29c330d942c | 174 | * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. |
Rohit Grover |
37:c29c330d942c | 175 | * @param[in] p_cscs_init Information needed to initialize the control point behavior. |
Rohit Grover |
37:c29c330d942c | 176 | * |
Rohit Grover |
37:c29c330d942c | 177 | * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. |
Rohit Grover |
37:c29c330d942c | 178 | */ |
Rohit Grover |
37:c29c330d942c | 179 | uint32_t ble_sc_ctrlpt_init(ble_sc_ctrlpt_t * p_sc_ctrlpt, |
Rohit Grover |
37:c29c330d942c | 180 | const ble_cs_ctrlpt_init_t * p_sc_ctrlpt_init); |
Rohit Grover |
37:c29c330d942c | 181 | |
Rohit Grover |
37:c29c330d942c | 182 | |
Rohit Grover |
37:c29c330d942c | 183 | /**@brief Function for sending a control point response. |
Rohit Grover |
37:c29c330d942c | 184 | * |
Rohit Grover |
37:c29c330d942c | 185 | * @details Function for sending a control point response when the control point received was |
Rohit Grover |
37:c29c330d942c | 186 | * BLE_SCPT_START_AUTOMATIC_CALIBRATION. To be called after the calibration procedure is finished. |
Rohit Grover |
37:c29c330d942c | 187 | * |
Rohit Grover |
37:c29c330d942c | 188 | * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. |
Rohit Grover |
37:c29c330d942c | 189 | * @param[in] response_status status to include in the control point response. |
Rohit Grover |
37:c29c330d942c | 190 | */ |
Rohit Grover |
37:c29c330d942c | 191 | uint32_t ble_sc_ctrlpt_rsp_send(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_scpt_response_t response_status); |
Rohit Grover |
37:c29c330d942c | 192 | |
Rohit Grover |
37:c29c330d942c | 193 | |
Rohit Grover |
37:c29c330d942c | 194 | /**@brief Speed and Cadence Control Point BLE stack event handler. |
Rohit Grover |
37:c29c330d942c | 195 | * |
Rohit Grover |
37:c29c330d942c | 196 | * @details Handles all events from the BLE stack of interest to the Speed and Cadence Control Point. |
Rohit Grover |
37:c29c330d942c | 197 | * |
Rohit Grover |
37:c29c330d942c | 198 | * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. |
Rohit Grover |
37:c29c330d942c | 199 | * @param[in] p_ble_evt Event received from the BLE stack. |
Rohit Grover |
37:c29c330d942c | 200 | */ |
Rohit Grover |
37:c29c330d942c | 201 | void ble_sc_ctrlpt_on_ble_evt(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_evt_t * p_ble_evt); |
Rohit Grover |
37:c29c330d942c | 202 | |
Rohit Grover |
37:c29c330d942c | 203 | |
Rohit Grover |
37:c29c330d942c | 204 | #endif // BLE_SC_CTRLPT_H__ |
Rohit Grover |
37:c29c330d942c | 205 | |
Rohit Grover |
37:c29c330d942c | 206 | /** @} */ |