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