ライントレースとうおーるぼっとチャレンジのコードです。 SW1で操作モードとライントレースモードを切り替えます。 操作モードの時にRCBControllerのSTARTボタンを押すとチャレンジが開始します。 チャレンジの時はiPhoneを傾けてハンドリングする操作しか効かなくなっています。
Dependencies: mbed
nRF51822/nRF51GattServer.cpp@0:76dfa9657d9d, 2014-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Wed Nov 12 02:40:34 2014 +0000
- Revision:
- 0:76dfa9657d9d
????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* mbed Microcontroller Library |
jksoft | 0:76dfa9657d9d | 2 | * Copyright (c) 2006-2013 ARM Limited |
jksoft | 0:76dfa9657d9d | 3 | * |
jksoft | 0:76dfa9657d9d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jksoft | 0:76dfa9657d9d | 5 | * you may not use this file except in compliance with the License. |
jksoft | 0:76dfa9657d9d | 6 | * You may obtain a copy of the License at |
jksoft | 0:76dfa9657d9d | 7 | * |
jksoft | 0:76dfa9657d9d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jksoft | 0:76dfa9657d9d | 9 | * |
jksoft | 0:76dfa9657d9d | 10 | * Unless required by applicable law or agreed to in writing, software |
jksoft | 0:76dfa9657d9d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jksoft | 0:76dfa9657d9d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jksoft | 0:76dfa9657d9d | 13 | * See the License for the specific language governing permissions and |
jksoft | 0:76dfa9657d9d | 14 | * limitations under the License. |
jksoft | 0:76dfa9657d9d | 15 | */ |
jksoft | 0:76dfa9657d9d | 16 | |
jksoft | 0:76dfa9657d9d | 17 | #include "nRF51GattServer.h" |
jksoft | 0:76dfa9657d9d | 18 | #include "mbed.h" |
jksoft | 0:76dfa9657d9d | 19 | |
jksoft | 0:76dfa9657d9d | 20 | #include "common/common.h" |
jksoft | 0:76dfa9657d9d | 21 | #include "btle/custom/custom_helper.h" |
jksoft | 0:76dfa9657d9d | 22 | |
jksoft | 0:76dfa9657d9d | 23 | #include "nRF51Gap.h" |
jksoft | 0:76dfa9657d9d | 24 | |
jksoft | 0:76dfa9657d9d | 25 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 26 | /*! |
jksoft | 0:76dfa9657d9d | 27 | @brief Adds a new service to the GATT table on the peripheral |
jksoft | 0:76dfa9657d9d | 28 | |
jksoft | 0:76dfa9657d9d | 29 | @returns ble_error_t |
jksoft | 0:76dfa9657d9d | 30 | |
jksoft | 0:76dfa9657d9d | 31 | @retval BLE_ERROR_NONE |
jksoft | 0:76dfa9657d9d | 32 | Everything executed properly |
jksoft | 0:76dfa9657d9d | 33 | |
jksoft | 0:76dfa9657d9d | 34 | @section EXAMPLE |
jksoft | 0:76dfa9657d9d | 35 | |
jksoft | 0:76dfa9657d9d | 36 | @code |
jksoft | 0:76dfa9657d9d | 37 | |
jksoft | 0:76dfa9657d9d | 38 | @endcode |
jksoft | 0:76dfa9657d9d | 39 | */ |
jksoft | 0:76dfa9657d9d | 40 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 41 | ble_error_t nRF51GattServer::addService(GattService &service) |
jksoft | 0:76dfa9657d9d | 42 | { |
jksoft | 0:76dfa9657d9d | 43 | /* ToDo: Make sure we don't overflow the array, etc. */ |
jksoft | 0:76dfa9657d9d | 44 | /* ToDo: Make sure this service UUID doesn't already exist (?) */ |
jksoft | 0:76dfa9657d9d | 45 | /* ToDo: Basic validation */ |
jksoft | 0:76dfa9657d9d | 46 | |
jksoft | 0:76dfa9657d9d | 47 | /* Add the service to the nRF51 */ |
jksoft | 0:76dfa9657d9d | 48 | ble_uuid_t nordicUUID; |
jksoft | 0:76dfa9657d9d | 49 | nordicUUID = custom_convert_to_nordic_uuid(service.getUUID()); |
jksoft | 0:76dfa9657d9d | 50 | |
jksoft | 0:76dfa9657d9d | 51 | uint16_t serviceHandle; |
jksoft | 0:76dfa9657d9d | 52 | ASSERT( ERROR_NONE == |
jksoft | 0:76dfa9657d9d | 53 | sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, |
jksoft | 0:76dfa9657d9d | 54 | &nordicUUID, |
jksoft | 0:76dfa9657d9d | 55 | &serviceHandle), |
jksoft | 0:76dfa9657d9d | 56 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 57 | service.setHandle(serviceHandle); |
jksoft | 0:76dfa9657d9d | 58 | |
jksoft | 0:76dfa9657d9d | 59 | /* Add characteristics to the service */ |
jksoft | 0:76dfa9657d9d | 60 | for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) { |
jksoft | 0:76dfa9657d9d | 61 | GattCharacteristic *p_char = service.getCharacteristic(i); |
jksoft | 0:76dfa9657d9d | 62 | |
jksoft | 0:76dfa9657d9d | 63 | /* Skip any incompletely defined, read-only characteristics. */ |
jksoft | 0:76dfa9657d9d | 64 | if ((p_char->getValueAttribute().getValuePtr() == NULL) && |
jksoft | 0:76dfa9657d9d | 65 | (p_char->getValueAttribute().getInitialLength() == 0) && |
jksoft | 0:76dfa9657d9d | 66 | (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) { |
jksoft | 0:76dfa9657d9d | 67 | continue; |
jksoft | 0:76dfa9657d9d | 68 | } |
jksoft | 0:76dfa9657d9d | 69 | |
jksoft | 0:76dfa9657d9d | 70 | nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID()); |
jksoft | 0:76dfa9657d9d | 71 | |
jksoft | 0:76dfa9657d9d | 72 | ASSERT ( ERROR_NONE == |
jksoft | 0:76dfa9657d9d | 73 | custom_add_in_characteristic(BLE_GATT_HANDLE_INVALID, |
jksoft | 0:76dfa9657d9d | 74 | &nordicUUID, |
jksoft | 0:76dfa9657d9d | 75 | p_char->getProperties(), |
jksoft | 0:76dfa9657d9d | 76 | p_char->getValueAttribute().getValuePtr(), |
jksoft | 0:76dfa9657d9d | 77 | p_char->getValueAttribute().getInitialLength(), |
jksoft | 0:76dfa9657d9d | 78 | p_char->getValueAttribute().getMaxLength(), |
jksoft | 0:76dfa9657d9d | 79 | &nrfCharacteristicHandles[characteristicCount]), |
jksoft | 0:76dfa9657d9d | 80 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 81 | |
jksoft | 0:76dfa9657d9d | 82 | /* Update the characteristic handle */ |
jksoft | 0:76dfa9657d9d | 83 | uint16_t charHandle = characteristicCount; |
jksoft | 0:76dfa9657d9d | 84 | p_characteristics[characteristicCount++] = p_char; |
jksoft | 0:76dfa9657d9d | 85 | |
jksoft | 0:76dfa9657d9d | 86 | p_char->getValueAttribute().setHandle(charHandle); |
jksoft | 0:76dfa9657d9d | 87 | |
jksoft | 0:76dfa9657d9d | 88 | /* Add optional descriptors if any */ |
jksoft | 0:76dfa9657d9d | 89 | /* ToDo: Make sure we don't overflow the array */ |
jksoft | 0:76dfa9657d9d | 90 | for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) { |
jksoft | 0:76dfa9657d9d | 91 | GattAttribute *p_desc = p_char->getDescriptor(j); |
jksoft | 0:76dfa9657d9d | 92 | |
jksoft | 0:76dfa9657d9d | 93 | nordicUUID = custom_convert_to_nordic_uuid(p_desc->getUUID()); |
jksoft | 0:76dfa9657d9d | 94 | |
jksoft | 0:76dfa9657d9d | 95 | ASSERT ( ERROR_NONE == |
jksoft | 0:76dfa9657d9d | 96 | custom_add_in_descriptor(BLE_GATT_HANDLE_INVALID, |
jksoft | 0:76dfa9657d9d | 97 | &nordicUUID, |
jksoft | 0:76dfa9657d9d | 98 | p_desc->getValuePtr(), |
jksoft | 0:76dfa9657d9d | 99 | p_desc->getInitialLength(), |
jksoft | 0:76dfa9657d9d | 100 | p_desc->getMaxLength(), |
jksoft | 0:76dfa9657d9d | 101 | &nrfDescriptorHandles[descriptorCount]), |
jksoft | 0:76dfa9657d9d | 102 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 103 | |
jksoft | 0:76dfa9657d9d | 104 | uint16_t descHandle = descriptorCount; |
jksoft | 0:76dfa9657d9d | 105 | p_descriptors[descriptorCount++] = p_desc; |
jksoft | 0:76dfa9657d9d | 106 | p_desc->setHandle(descHandle); |
jksoft | 0:76dfa9657d9d | 107 | } |
jksoft | 0:76dfa9657d9d | 108 | } |
jksoft | 0:76dfa9657d9d | 109 | |
jksoft | 0:76dfa9657d9d | 110 | serviceCount++; |
jksoft | 0:76dfa9657d9d | 111 | |
jksoft | 0:76dfa9657d9d | 112 | return BLE_ERROR_NONE; |
jksoft | 0:76dfa9657d9d | 113 | } |
jksoft | 0:76dfa9657d9d | 114 | |
jksoft | 0:76dfa9657d9d | 115 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 116 | /*! |
jksoft | 0:76dfa9657d9d | 117 | @brief Reads the value of a characteristic, based on the service |
jksoft | 0:76dfa9657d9d | 118 | and characteristic index fields |
jksoft | 0:76dfa9657d9d | 119 | |
jksoft | 0:76dfa9657d9d | 120 | @param[in] charHandle |
jksoft | 0:76dfa9657d9d | 121 | The handle of the GattCharacteristic to read from |
jksoft | 0:76dfa9657d9d | 122 | @param[in] buffer |
jksoft | 0:76dfa9657d9d | 123 | Buffer to hold the the characteristic's value |
jksoft | 0:76dfa9657d9d | 124 | (raw byte array in LSB format) |
jksoft | 0:76dfa9657d9d | 125 | @param[in] len |
jksoft | 0:76dfa9657d9d | 126 | The number of bytes read into the buffer |
jksoft | 0:76dfa9657d9d | 127 | |
jksoft | 0:76dfa9657d9d | 128 | @returns ble_error_t |
jksoft | 0:76dfa9657d9d | 129 | |
jksoft | 0:76dfa9657d9d | 130 | @retval BLE_ERROR_NONE |
jksoft | 0:76dfa9657d9d | 131 | Everything executed properly |
jksoft | 0:76dfa9657d9d | 132 | |
jksoft | 0:76dfa9657d9d | 133 | @section EXAMPLE |
jksoft | 0:76dfa9657d9d | 134 | |
jksoft | 0:76dfa9657d9d | 135 | @code |
jksoft | 0:76dfa9657d9d | 136 | |
jksoft | 0:76dfa9657d9d | 137 | @endcode |
jksoft | 0:76dfa9657d9d | 138 | */ |
jksoft | 0:76dfa9657d9d | 139 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 140 | ble_error_t nRF51GattServer::readValue(uint16_t charHandle, uint8_t buffer[], uint16_t *const lengthP) |
jksoft | 0:76dfa9657d9d | 141 | { |
jksoft | 0:76dfa9657d9d | 142 | ASSERT( ERROR_NONE == |
jksoft | 0:76dfa9657d9d | 143 | sd_ble_gatts_value_get(nrfCharacteristicHandles[charHandle].value_handle, 0, lengthP, buffer), |
jksoft | 0:76dfa9657d9d | 144 | BLE_ERROR_PARAM_OUT_OF_RANGE); |
jksoft | 0:76dfa9657d9d | 145 | |
jksoft | 0:76dfa9657d9d | 146 | return BLE_ERROR_NONE; |
jksoft | 0:76dfa9657d9d | 147 | } |
jksoft | 0:76dfa9657d9d | 148 | |
jksoft | 0:76dfa9657d9d | 149 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 150 | /*! |
jksoft | 0:76dfa9657d9d | 151 | @brief Updates the value of a characteristic, based on the service |
jksoft | 0:76dfa9657d9d | 152 | and characteristic index fields |
jksoft | 0:76dfa9657d9d | 153 | |
jksoft | 0:76dfa9657d9d | 154 | @param[in] charHandle |
jksoft | 0:76dfa9657d9d | 155 | The handle of the GattCharacteristic to write to |
jksoft | 0:76dfa9657d9d | 156 | @param[in] buffer |
jksoft | 0:76dfa9657d9d | 157 | Data to use when updating the characteristic's value |
jksoft | 0:76dfa9657d9d | 158 | (raw byte array in LSB format) |
jksoft | 0:76dfa9657d9d | 159 | @param[in] len |
jksoft | 0:76dfa9657d9d | 160 | The number of bytes in buffer |
jksoft | 0:76dfa9657d9d | 161 | |
jksoft | 0:76dfa9657d9d | 162 | @returns ble_error_t |
jksoft | 0:76dfa9657d9d | 163 | |
jksoft | 0:76dfa9657d9d | 164 | @retval BLE_ERROR_NONE |
jksoft | 0:76dfa9657d9d | 165 | Everything executed properly |
jksoft | 0:76dfa9657d9d | 166 | |
jksoft | 0:76dfa9657d9d | 167 | @section EXAMPLE |
jksoft | 0:76dfa9657d9d | 168 | |
jksoft | 0:76dfa9657d9d | 169 | @code |
jksoft | 0:76dfa9657d9d | 170 | |
jksoft | 0:76dfa9657d9d | 171 | @endcode |
jksoft | 0:76dfa9657d9d | 172 | */ |
jksoft | 0:76dfa9657d9d | 173 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 174 | ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly) |
jksoft | 0:76dfa9657d9d | 175 | { |
jksoft | 0:76dfa9657d9d | 176 | uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle(); |
jksoft | 0:76dfa9657d9d | 177 | |
jksoft | 0:76dfa9657d9d | 178 | if (localOnly) { |
jksoft | 0:76dfa9657d9d | 179 | /* Only update locally regardless of notify/indicate */ |
jksoft | 0:76dfa9657d9d | 180 | ASSERT_INT( ERROR_NONE, |
jksoft | 0:76dfa9657d9d | 181 | sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), |
jksoft | 0:76dfa9657d9d | 182 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 183 | return BLE_ERROR_NONE; |
jksoft | 0:76dfa9657d9d | 184 | } |
jksoft | 0:76dfa9657d9d | 185 | |
jksoft | 0:76dfa9657d9d | 186 | if ((p_characteristics[charHandle]->getProperties() & |
jksoft | 0:76dfa9657d9d | 187 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | |
jksoft | 0:76dfa9657d9d | 188 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) && |
jksoft | 0:76dfa9657d9d | 189 | (gapConnectionHandle != BLE_CONN_HANDLE_INVALID)) { |
jksoft | 0:76dfa9657d9d | 190 | /* HVX update for the characteristic value */ |
jksoft | 0:76dfa9657d9d | 191 | ble_gatts_hvx_params_t hvx_params; |
jksoft | 0:76dfa9657d9d | 192 | |
jksoft | 0:76dfa9657d9d | 193 | hvx_params.handle = nrfCharacteristicHandles[charHandle].value_handle; |
jksoft | 0:76dfa9657d9d | 194 | hvx_params.type = |
jksoft | 0:76dfa9657d9d | 195 | (p_characteristics[charHandle]->getProperties() & |
jksoft | 0:76dfa9657d9d | 196 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? |
jksoft | 0:76dfa9657d9d | 197 | BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION; |
jksoft | 0:76dfa9657d9d | 198 | hvx_params.offset = 0; |
jksoft | 0:76dfa9657d9d | 199 | hvx_params.p_data = buffer; |
jksoft | 0:76dfa9657d9d | 200 | hvx_params.p_len = &len; |
jksoft | 0:76dfa9657d9d | 201 | |
jksoft | 0:76dfa9657d9d | 202 | error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params); |
jksoft | 0:76dfa9657d9d | 203 | |
jksoft | 0:76dfa9657d9d | 204 | /* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and |
jksoft | 0:76dfa9657d9d | 205 | *ERROR_NO_TX_BUFFERS the ATT table has been updated. */ |
jksoft | 0:76dfa9657d9d | 206 | if ((error != ERROR_NONE) && (error != ERROR_INVALID_STATE) && |
jksoft | 0:76dfa9657d9d | 207 | (error != ERROR_BLE_NO_TX_BUFFERS) && (error != ERROR_BUSY) && |
jksoft | 0:76dfa9657d9d | 208 | (error != ERROR_BLEGATTS_SYS_ATTR_MISSING)) { |
jksoft | 0:76dfa9657d9d | 209 | ASSERT_INT( ERROR_NONE, |
jksoft | 0:76dfa9657d9d | 210 | sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), |
jksoft | 0:76dfa9657d9d | 211 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 212 | } |
jksoft | 0:76dfa9657d9d | 213 | } else { |
jksoft | 0:76dfa9657d9d | 214 | ASSERT_INT( ERROR_NONE, |
jksoft | 0:76dfa9657d9d | 215 | sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), |
jksoft | 0:76dfa9657d9d | 216 | BLE_ERROR_PARAM_OUT_OF_RANGE ); |
jksoft | 0:76dfa9657d9d | 217 | } |
jksoft | 0:76dfa9657d9d | 218 | |
jksoft | 0:76dfa9657d9d | 219 | return BLE_ERROR_NONE; |
jksoft | 0:76dfa9657d9d | 220 | } |
jksoft | 0:76dfa9657d9d | 221 | |
jksoft | 0:76dfa9657d9d | 222 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 223 | /*! |
jksoft | 0:76dfa9657d9d | 224 | @brief Callback handler for events getting pushed up from the SD |
jksoft | 0:76dfa9657d9d | 225 | */ |
jksoft | 0:76dfa9657d9d | 226 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 227 | void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt) |
jksoft | 0:76dfa9657d9d | 228 | { |
jksoft | 0:76dfa9657d9d | 229 | uint16_t handle_value; |
jksoft | 0:76dfa9657d9d | 230 | GattServerEvents::gattEvent_t eventType; |
jksoft | 0:76dfa9657d9d | 231 | const ble_gatts_evt_t *gattsEventP = &p_ble_evt->evt.gatts_evt; |
jksoft | 0:76dfa9657d9d | 232 | |
jksoft | 0:76dfa9657d9d | 233 | switch (p_ble_evt->header.evt_id) { |
jksoft | 0:76dfa9657d9d | 234 | case BLE_GATTS_EVT_WRITE: |
jksoft | 0:76dfa9657d9d | 235 | /* There are 2 use case here: Values being updated & CCCD (indicate/notify) enabled */ |
jksoft | 0:76dfa9657d9d | 236 | |
jksoft | 0:76dfa9657d9d | 237 | /* 1.) Handle CCCD changes */ |
jksoft | 0:76dfa9657d9d | 238 | handle_value = gattsEventP->params.write.handle; |
jksoft | 0:76dfa9657d9d | 239 | for (uint8_t i = 0; i<characteristicCount; i++) { |
jksoft | 0:76dfa9657d9d | 240 | if ((p_characteristics[i]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) && |
jksoft | 0:76dfa9657d9d | 241 | (nrfCharacteristicHandles[i].cccd_handle == handle_value)) { |
jksoft | 0:76dfa9657d9d | 242 | uint16_t cccd_value = |
jksoft | 0:76dfa9657d9d | 243 | (gattsEventP->params.write.data[1] << 8) | |
jksoft | 0:76dfa9657d9d | 244 | gattsEventP->params.write.data[0]; /* Little Endian but M0 may be mis-aligned */ |
jksoft | 0:76dfa9657d9d | 245 | |
jksoft | 0:76dfa9657d9d | 246 | if (((p_characteristics[i]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE) && (cccd_value & BLE_GATT_HVX_INDICATION)) || |
jksoft | 0:76dfa9657d9d | 247 | ((p_characteristics[i]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) && (cccd_value & BLE_GATT_HVX_NOTIFICATION))) { |
jksoft | 0:76dfa9657d9d | 248 | eventType = GattServerEvents::GATT_EVENT_UPDATES_ENABLED; |
jksoft | 0:76dfa9657d9d | 249 | } else { |
jksoft | 0:76dfa9657d9d | 250 | eventType = GattServerEvents::GATT_EVENT_UPDATES_DISABLED; |
jksoft | 0:76dfa9657d9d | 251 | } |
jksoft | 0:76dfa9657d9d | 252 | |
jksoft | 0:76dfa9657d9d | 253 | handleEvent(eventType, i); |
jksoft | 0:76dfa9657d9d | 254 | return; |
jksoft | 0:76dfa9657d9d | 255 | } |
jksoft | 0:76dfa9657d9d | 256 | } |
jksoft | 0:76dfa9657d9d | 257 | |
jksoft | 0:76dfa9657d9d | 258 | /* 2.) Changes to the characteristic value will be handled with other events below */ |
jksoft | 0:76dfa9657d9d | 259 | eventType = GattServerEvents::GATT_EVENT_DATA_WRITTEN; |
jksoft | 0:76dfa9657d9d | 260 | break; |
jksoft | 0:76dfa9657d9d | 261 | |
jksoft | 0:76dfa9657d9d | 262 | case BLE_GATTS_EVT_HVC: |
jksoft | 0:76dfa9657d9d | 263 | /* Indication confirmation received */ |
jksoft | 0:76dfa9657d9d | 264 | eventType = GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED; |
jksoft | 0:76dfa9657d9d | 265 | handle_value = gattsEventP->params.hvc.handle; |
jksoft | 0:76dfa9657d9d | 266 | break; |
jksoft | 0:76dfa9657d9d | 267 | |
jksoft | 0:76dfa9657d9d | 268 | case BLE_EVT_TX_COMPLETE: { |
jksoft | 0:76dfa9657d9d | 269 | handleDataSentEvent(p_ble_evt->evt.common_evt.params.tx_complete.count); |
jksoft | 0:76dfa9657d9d | 270 | return; |
jksoft | 0:76dfa9657d9d | 271 | } |
jksoft | 0:76dfa9657d9d | 272 | |
jksoft | 0:76dfa9657d9d | 273 | case BLE_GATTS_EVT_SYS_ATTR_MISSING: |
jksoft | 0:76dfa9657d9d | 274 | sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0); |
jksoft | 0:76dfa9657d9d | 275 | return; |
jksoft | 0:76dfa9657d9d | 276 | |
jksoft | 0:76dfa9657d9d | 277 | default: |
jksoft | 0:76dfa9657d9d | 278 | return; |
jksoft | 0:76dfa9657d9d | 279 | } |
jksoft | 0:76dfa9657d9d | 280 | |
jksoft | 0:76dfa9657d9d | 281 | /* Find index (charHandle) in the pool */ |
jksoft | 0:76dfa9657d9d | 282 | for (uint8_t i = 0; i<characteristicCount; i++) { |
jksoft | 0:76dfa9657d9d | 283 | if (nrfCharacteristicHandles[i].value_handle == handle_value) { |
jksoft | 0:76dfa9657d9d | 284 | switch (eventType) { |
jksoft | 0:76dfa9657d9d | 285 | case GattServerEvents::GATT_EVENT_DATA_WRITTEN: { |
jksoft | 0:76dfa9657d9d | 286 | GattCharacteristicWriteCBParams cbParams = { |
jksoft | 0:76dfa9657d9d | 287 | .charHandle = i, |
jksoft | 0:76dfa9657d9d | 288 | .op = static_cast<GattCharacteristicWriteCBParams::Type>(gattsEventP->params.write.op), |
jksoft | 0:76dfa9657d9d | 289 | .offset = gattsEventP->params.write.offset, |
jksoft | 0:76dfa9657d9d | 290 | .len = gattsEventP->params.write.len, |
jksoft | 0:76dfa9657d9d | 291 | .data = gattsEventP->params.write.data |
jksoft | 0:76dfa9657d9d | 292 | }; |
jksoft | 0:76dfa9657d9d | 293 | handleDataWrittenEvent(&cbParams); |
jksoft | 0:76dfa9657d9d | 294 | break; |
jksoft | 0:76dfa9657d9d | 295 | } |
jksoft | 0:76dfa9657d9d | 296 | default: |
jksoft | 0:76dfa9657d9d | 297 | handleEvent(eventType, i); |
jksoft | 0:76dfa9657d9d | 298 | break; |
jksoft | 0:76dfa9657d9d | 299 | } |
jksoft | 0:76dfa9657d9d | 300 | } |
jksoft | 0:76dfa9657d9d | 301 | } |
jksoft | 0:76dfa9657d9d | 302 | } |