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