Nordic stack and drivers for the mbed BLE API Modified for HRM1017 for library 0.1.0
Fork of nRF51822 by
ble_sc_ctrlpt.h
00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 /** @file 00014 * 00015 * @defgroup ble_sdk_srv_sc_ctrlpt Speed and Cadence Control Point 00016 * @{ 00017 * @ingroup ble_sdk_srv 00018 * @brief Speed and Cadence Control Point module. 00019 * 00020 * @details This module implements the Speed and Cadence control point behavior. It is used 00021 * by the @ref ble_sdk_srv_csc module and the ble_sdk_srv_rsc module for control point 00022 * mechanisms like setting a cumulative value, Start an automatic calibration, 00023 * Update the sensor location or request the supported locations. 00024 * 00025 * @note Attention! 00026 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile 00027 * qualification listings, this section of source code must not be modified. 00028 */ 00029 00030 #ifndef BLE_SC_CTRLPT_H__ 00031 #define BLE_SC_CTRLPT_H__ 00032 00033 #include <stdint.h> 00034 #include <stdbool.h> 00035 #include "ble.h" 00036 #include "ble_srv_common.h " 00037 #include "ble_sensor_location.h" 00038 00039 #define BLE_SC_CTRLPT_MAX_LEN 19 /**< maximum lenght for Speed and cadence control point characteristic value. */ 00040 #define BLE_SC_CTRLPT_MIN_LEN 1 /**< minimum length for Speed and cadence control point characteristic value. */ 00041 00042 // Forward declaration of the ble_sc_ctrlpt_t type. 00043 typedef struct ble_sc_ctrlpt_s ble_sc_ctrlpt_t; 00044 00045 00046 /**@brief Speed and Cadence Control Point event type. */ 00047 typedef enum 00048 { 00049 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). */ 00050 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. */ 00051 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. */ 00052 } ble_sc_ctrlpt_evt_type_t; 00053 00054 00055 /**@brief Speed and Cadence Control point event. */ 00056 typedef struct 00057 { 00058 ble_sc_ctrlpt_evt_type_t evt_type; /**< Type of event. */ 00059 union 00060 { 00061 ble_sensor_location_t update_location; 00062 uint32_t cumulative_value; 00063 }params; 00064 } ble_sc_ctrlpt_evt_t; 00065 00066 00067 /** Speed and Cadence Control Point operator code (see RSC service specification)*/ 00068 typedef enum { 00069 BLE_SCPT_SET_CUMULATIVE_VALUE = 0x01, /**< Operator to set a given cumulative value. */ 00070 BLE_SCPT_START_AUTOMATIC_CALIBRATION = 0x02, /**< Operator to start automatic calibration. */ 00071 BLE_SCPT_UPDATE_SENSOR_LOCATION = 0x03, /**< Operator to update the sensor location. */ 00072 BLE_SCPT_REQUEST_SUPPORTED_SENSOR_LOCATIONS = 0x04, /**< Operator to request the supported sensor locations. */ 00073 BLE_SCPT_RESPONSE_CODE = 0x10, /**< Response Code. */ 00074 } ble_scpt_operator_t; 00075 00076 00077 /** Speed and Cadence Control Point response parameter (see RSC service specification)*/ 00078 typedef enum { 00079 BLE_SCPT_SUCCESS = 0x01, /**< Sucess Response. */ 00080 BLE_SCPT_OP_CODE_NOT_SUPPORTED = 0x02, /**< Error Response received opcode not supported. */ 00081 BLE_SCPT_INVALID_PARAMETER = 0x03, /**< Error Response received parameter invalid. */ 00082 BLE_SCPT_OPERATION_FAILED = 0x04, /**< Error Response operation failed. */ 00083 } ble_scpt_response_t; 00084 00085 00086 /** Speed and Cadence Control Point procedure status (indicates is a procedure is in progress or not and which procedure is in progress*/ 00087 typedef enum { 00088 BLE_SCPT_NO_PROC_IN_PROGRESS = 0x00, /**< No procedure in progress. */ 00089 BLE_SCPT_AUTOMATIC_CALIB_IN_PROGRESS = 0x01, /**< Automatic Calibration is in progress. */ 00090 BLE_SCPT_INDICATION_PENDING = 0x02, /**< Control Point Indication is pending. */ 00091 BLE_SCPT_IND_CONFIRM_PENDING = 0x03, /**< Waiting for the indication confirmation. */ 00092 }ble_scpt_procedure_status_t; 00093 00094 /**@brief Speed and Cadence Control point event handler type. */ 00095 typedef ble_scpt_response_t (*ble_sc_ctrlpt_evt_handler_t) (ble_sc_ctrlpt_t * p_sc_ctrlpt, 00096 ble_sc_ctrlpt_evt_t * p_evt); 00097 00098 00099 typedef struct{ 00100 ble_scpt_operator_t opcode; 00101 uint32_t cumulative_value; 00102 ble_sensor_location_t location; 00103 }ble_sc_ctrlpt_val_t; 00104 00105 00106 typedef struct{ 00107 ble_scpt_operator_t opcode; 00108 ble_scpt_response_t status; 00109 ble_sensor_location_t location_list[BLE_NB_MAX_SENSOR_LOCATIONS]; 00110 }ble_sc_ctrlpt_rsp_t; 00111 00112 00113 00114 #define BLE_SRV_SC_CTRLPT_SENSOR_LOCATIONS_OP_SUPPORTED 0x01 /**< Support for sensor location related operations */ 00115 #define BLE_SRV_SC_CTRLPT_CUM_VAL_OP_SUPPORTED 0x02 /**< Support for setting cumulative value related operations */ 00116 #define BLE_SRV_SC_CTRLPT_START_CALIB_OP_SUPPORTED 0x04 /**< Support for starting calibration related operations */ 00117 00118 00119 /**@brief Speed and Cadence Control Point init structure. This contains all options and data 00120 * needed for initialization of the Speed and Cadence Control Point module. */ 00121 typedef struct 00122 { 00123 ble_srv_cccd_security_mode_t sc_ctrlpt_attr_md; /**< Initial security level for cycling speed and cadence control point attribute */ 00124 uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */ 00125 uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */ 00126 ble_sc_ctrlpt_evt_handler_t evt_handler; /**< event handler */ 00127 ble_sensor_location_t *list_supported_locations; /**< list of supported sensor locations.*/ 00128 uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/ 00129 uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/ 00130 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 00131 } ble_cs_ctrlpt_init_t; 00132 00133 00134 /**@brief Speed and Cadence Control Point response indication structure. */ 00135 typedef struct 00136 { 00137 ble_scpt_response_t status; /**< control point response status .*/ 00138 uint8_t len; /**< control point response length .*/ 00139 uint8_t encoded_ctrl_rsp[BLE_SC_CTRLPT_MAX_LEN]; /**< control point encoded response.*/ 00140 }ble_sc_ctrlpt_resp_t; 00141 00142 00143 /**@brief Speed and Cadence Control Point structure. This contains various status information for 00144 * the Speed and Cadence Control Point behavior. */ 00145 typedef struct ble_sc_ctrlpt_s 00146 { 00147 uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */ 00148 uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */ 00149 ble_gatts_char_handles_t sc_ctrlpt_handles; /**< Handles related to the Speed and Cadence Control Point characteristic. */ 00150 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). */ 00151 ble_sensor_location_t list_supported_locations[BLE_NB_MAX_SENSOR_LOCATIONS]; /**< list of supported sensor locations.*/ 00152 uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/ 00153 ble_sc_ctrlpt_evt_handler_t evt_handler; /**< Handle of the parent service (as provided by the BLE stack). */ 00154 uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/ 00155 ble_scpt_procedure_status_t procedure_status; /**< status of possible procedure*/ 00156 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 00157 ble_sc_ctrlpt_resp_t response; /**< pending response data.*/ 00158 } ble_sc_ctrlpt_t; 00159 00160 #define SCPT_OPCODE_POS 0 /**< Request opcode position. */ 00161 #define SCPT_PARAMETER_POS 1 /**< Request parameter position. */ 00162 00163 #define SCPT_RESPONSE_REQUEST_OPCODE_POS 1 /**< Response position of requested opcode. */ 00164 #define SCPT_RESPONSE_CODE_POS 2 /**< Response position of response code. */ 00165 #define SCPT_RESPONSE_PARAMETER 3 /**< Response position of response parameter. */ 00166 00167 #define SCPT_MIN_RESPONSE_SIZE 3 /**< Minimum size for control point response. */ 00168 #define SCPT_MAX_RESPONSE_SIZE (SCPT_MIN_RESPONSE_SIZE + NB_MAX_SENSOR_LOCATIONS) /**< Maximum size for control point response. */ 00169 00170 00171 /**@brief Function for Initializing the Speed and Cadence Control Point. 00172 * 00173 * @details Function for Initializing the Speed and Cadence Control Point. 00174 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. 00175 * @param[in] p_cscs_init Information needed to initialize the control point behavior. 00176 * 00177 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. 00178 */ 00179 uint32_t ble_sc_ctrlpt_init(ble_sc_ctrlpt_t * p_sc_ctrlpt, 00180 const ble_cs_ctrlpt_init_t * p_sc_ctrlpt_init); 00181 00182 00183 /**@brief Function for sending a control point response. 00184 * 00185 * @details Function for sending a control point response when the control point received was 00186 * BLE_SCPT_START_AUTOMATIC_CALIBRATION. To be called after the calibration procedure is finished. 00187 * 00188 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. 00189 * @param[in] response_status status to include in the control point response. 00190 */ 00191 uint32_t ble_sc_ctrlpt_rsp_send(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_scpt_response_t response_status); 00192 00193 00194 /**@brief Speed and Cadence Control Point BLE stack event handler. 00195 * 00196 * @details Handles all events from the BLE stack of interest to the Speed and Cadence Control Point. 00197 * 00198 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure. 00199 * @param[in] p_ble_evt Event received from the BLE stack. 00200 */ 00201 void ble_sc_ctrlpt_on_ble_evt(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_evt_t * p_ble_evt); 00202 00203 00204 #endif // BLE_SC_CTRLPT_H__ 00205 00206 /** @} */
Generated on Tue Jul 12 2022 14:11:55 by 1.7.2