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