BLE lib
Fork of Nucleo_BLE_BlueNRG by
btle/src/btle.cpp@5:beb2c7544ce4, 2015-02-08 (annotated)
- Committer:
- vijaynvr
- Date:
- Sun Feb 08 14:25:58 2015 +0000
- Revision:
- 5:beb2c7544ce4
- Parent:
- 4:c8ed8022e996
working;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sjallouli | 0:a948f5f3904c | 1 | /* mbed Microcontroller Library |
sjallouli | 0:a948f5f3904c | 2 | * Copyright (c) 2006-2013 ARM Limited |
sjallouli | 0:a948f5f3904c | 3 | * |
sjallouli | 0:a948f5f3904c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sjallouli | 0:a948f5f3904c | 5 | * you may not use this file except in compliance with the License. |
sjallouli | 0:a948f5f3904c | 6 | * You may obtain a copy of the License at |
sjallouli | 0:a948f5f3904c | 7 | * |
sjallouli | 0:a948f5f3904c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sjallouli | 0:a948f5f3904c | 9 | * |
sjallouli | 0:a948f5f3904c | 10 | * Unless required by applicable law or agreed to in writing, software |
sjallouli | 0:a948f5f3904c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sjallouli | 0:a948f5f3904c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sjallouli | 0:a948f5f3904c | 13 | * See the License for the specific language governing permissions and |
sjallouli | 0:a948f5f3904c | 14 | * limitations under the License. |
sjallouli | 0:a948f5f3904c | 15 | */ |
sjallouli | 0:a948f5f3904c | 16 | |
sjallouli | 0:a948f5f3904c | 17 | |
sjallouli | 0:a948f5f3904c | 18 | #include "btle.h" |
sjallouli | 0:a948f5f3904c | 19 | #include "public/Gap.h" |
sjallouli | 0:a948f5f3904c | 20 | #include "public/GapEvents.h" |
sjallouli | 0:a948f5f3904c | 21 | #include "BlueNRGGap.h" |
sjallouli | 0:a948f5f3904c | 22 | #include "BlueNRGGattServer.h" |
sjallouli | 0:a948f5f3904c | 23 | #include "Utils.h" |
sjallouli | 0:a948f5f3904c | 24 | |
sjallouli | 0:a948f5f3904c | 25 | #ifdef __cplusplus |
sjallouli | 0:a948f5f3904c | 26 | extern "C" { |
sjallouli | 0:a948f5f3904c | 27 | #endif |
sjallouli | 0:a948f5f3904c | 28 | |
sjallouli | 0:a948f5f3904c | 29 | |
sjallouli | 0:a948f5f3904c | 30 | /* C File Includes ------------------------------------------------------------------*/ |
sjallouli | 0:a948f5f3904c | 31 | #include "hal_types.h" |
sjallouli | 0:a948f5f3904c | 32 | #include "hci.h" |
sjallouli | 0:a948f5f3904c | 33 | #include "bluenrg_hci.h" |
sjallouli | 0:a948f5f3904c | 34 | #include "gp_timer.h" |
sjallouli | 0:a948f5f3904c | 35 | #include "hal.h" |
sjallouli | 0:a948f5f3904c | 36 | #include "osal.h" |
sjallouli | 0:a948f5f3904c | 37 | #include "hci_internal.h" |
sjallouli | 0:a948f5f3904c | 38 | #include "bluenrg_hci_internal.h" |
sjallouli | 0:a948f5f3904c | 39 | #include "bluenrg_gap.h" |
sjallouli | 0:a948f5f3904c | 40 | #include "sm.h" |
sjallouli | 0:a948f5f3904c | 41 | #include <stdio.h> |
sjallouli | 0:a948f5f3904c | 42 | #include <string.h> |
sjallouli | 0:a948f5f3904c | 43 | #include "role_type.h" |
sjallouli | 0:a948f5f3904c | 44 | #include "debug.h" |
sjallouli | 0:a948f5f3904c | 45 | |
sjallouli | 0:a948f5f3904c | 46 | #ifdef __cplusplus |
sjallouli | 0:a948f5f3904c | 47 | } |
sjallouli | 0:a948f5f3904c | 48 | #endif |
sjallouli | 0:a948f5f3904c | 49 | |
fbd38 | 4:c8ed8022e996 | 50 | // Pas Beau du tout |
vijaynvr | 5:beb2c7544ce4 | 51 | extern int8_t ctrl_byte =0; //VJ |
sjallouli | 0:a948f5f3904c | 52 | |
sjallouli | 0:a948f5f3904c | 53 | static void btle_handler(/*ble_evt_t * p_ble_evt*/); |
sjallouli | 0:a948f5f3904c | 54 | void HCI_Input(tHciDataPacket * hciReadPacket); |
sjallouli | 0:a948f5f3904c | 55 | |
sjallouli | 0:a948f5f3904c | 56 | //#define BDADDR_SIZE 6 |
sjallouli | 0:a948f5f3904c | 57 | //tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02}; |
sjallouli | 0:a948f5f3904c | 58 | |
sjallouli | 0:a948f5f3904c | 59 | uint16_t g_gap_service_handle = 0; |
sjallouli | 0:a948f5f3904c | 60 | uint16_t g_appearance_char_handle = 0; |
sjallouli | 0:a948f5f3904c | 61 | uint16_t g_device_name_char_handle = 0; |
sjallouli | 0:a948f5f3904c | 62 | |
sjallouli | 0:a948f5f3904c | 63 | /* Private variables ---------------------------------------------------------*/ |
sjallouli | 0:a948f5f3904c | 64 | volatile uint8_t set_connectable = 1; |
sjallouli | 0:a948f5f3904c | 65 | |
sjallouli | 0:a948f5f3904c | 66 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 67 | /*! |
sjallouli | 0:a948f5f3904c | 68 | @brief Initialises BTLE and the underlying HW/Device |
sjallouli | 0:a948f5f3904c | 69 | |
sjallouli | 0:a948f5f3904c | 70 | @returns |
sjallouli | 0:a948f5f3904c | 71 | */ |
sjallouli | 0:a948f5f3904c | 72 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 73 | void btle_init(bool isSetAddress) |
sjallouli | 0:a948f5f3904c | 74 | { |
sjallouli | 0:a948f5f3904c | 75 | DEBUG("btle_init>>\n\r"); |
sjallouli | 0:a948f5f3904c | 76 | tHalUint8 *bleAddr; |
sjallouli | 0:a948f5f3904c | 77 | int ret; |
sjallouli | 0:a948f5f3904c | 78 | uint16_t service_handle, dev_name_char_handle, appearance_char_handle; |
sjallouli | 0:a948f5f3904c | 79 | |
sjallouli | 0:a948f5f3904c | 80 | //HAL_Init(); |
sjallouli | 0:a948f5f3904c | 81 | |
sjallouli | 0:a948f5f3904c | 82 | /* Configure the User Button in GPIO Mode */ |
sjallouli | 0:a948f5f3904c | 83 | //BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); |
sjallouli | 0:a948f5f3904c | 84 | |
sjallouli | 0:a948f5f3904c | 85 | /* Configure the system clock */ |
sjallouli | 0:a948f5f3904c | 86 | //SystemClock_Config(); |
sjallouli | 0:a948f5f3904c | 87 | |
sjallouli | 0:a948f5f3904c | 88 | /* Delay needed only to be able to acces the JTAG interface after reset |
sjallouli | 0:a948f5f3904c | 89 | if it will be disabled later. */ |
sjallouli | 0:a948f5f3904c | 90 | Clock_Wait(500); |
sjallouli | 0:a948f5f3904c | 91 | |
sjallouli | 0:a948f5f3904c | 92 | /* Initialize the BlueNRG SPI driver */ |
sjallouli | 0:a948f5f3904c | 93 | BNRG_SPI_Init(); |
sjallouli | 0:a948f5f3904c | 94 | |
sjallouli | 0:a948f5f3904c | 95 | /* Initialize the BlueNRG HCI */ |
sjallouli | 0:a948f5f3904c | 96 | HCI_Init(); |
sjallouli | 0:a948f5f3904c | 97 | |
sjallouli | 0:a948f5f3904c | 98 | /* Reset BlueNRG SPI interface */ |
sjallouli | 0:a948f5f3904c | 99 | BlueNRG_RST(); |
sjallouli | 0:a948f5f3904c | 100 | |
sjallouli | 0:a948f5f3904c | 101 | /* The Nucleo board must be configured as SERVER */ |
sjallouli | 0:a948f5f3904c | 102 | //check if issetAddress is set than set address. |
sjallouli | 0:a948f5f3904c | 103 | if(isSetAddress) |
sjallouli | 0:a948f5f3904c | 104 | { |
sjallouli | 0:a948f5f3904c | 105 | bleAddr = BlueNRGGap::getInstance().getAddress(); |
sjallouli | 0:a948f5f3904c | 106 | |
sjallouli | 0:a948f5f3904c | 107 | tHalUint8 bdaddr[BDADDR_SIZE]; |
sjallouli | 0:a948f5f3904c | 108 | Osal_MemCpy(bdaddr, bleAddr, BDADDR_SIZE); |
sjallouli | 0:a948f5f3904c | 109 | |
sjallouli | 0:a948f5f3904c | 110 | ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, |
sjallouli | 0:a948f5f3904c | 111 | CONFIG_DATA_PUBADDR_LEN, |
sjallouli | 0:a948f5f3904c | 112 | bdaddr); |
sjallouli | 0:a948f5f3904c | 113 | } |
sjallouli | 0:a948f5f3904c | 114 | |
sjallouli | 0:a948f5f3904c | 115 | ret = aci_gatt_init(); |
sjallouli | 0:a948f5f3904c | 116 | //GAP is always in PERIPHERAL _ROLE as mbed does not support Master role at the moment |
sjallouli | 0:a948f5f3904c | 117 | ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, &dev_name_char_handle, &appearance_char_handle); |
sjallouli | 0:a948f5f3904c | 118 | |
sjallouli | 0:a948f5f3904c | 119 | g_gap_service_handle = service_handle; |
sjallouli | 0:a948f5f3904c | 120 | g_appearance_char_handle = appearance_char_handle; |
sjallouli | 0:a948f5f3904c | 121 | g_device_name_char_handle = dev_name_char_handle; |
sjallouli | 0:a948f5f3904c | 122 | //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API |
sjallouli | 0:a948f5f3904c | 123 | /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, |
sjallouli | 0:a948f5f3904c | 124 | strlen(name), (tHalUint8 *)name);*/ |
sjallouli | 0:a948f5f3904c | 125 | |
sjallouli | 0:a948f5f3904c | 126 | return; |
sjallouli | 0:a948f5f3904c | 127 | } |
sjallouli | 0:a948f5f3904c | 128 | |
sjallouli | 0:a948f5f3904c | 129 | void User_Process() |
sjallouli | 0:a948f5f3904c | 130 | { |
sjallouli | 0:a948f5f3904c | 131 | if(set_connectable){ |
sjallouli | 0:a948f5f3904c | 132 | setConnectable(); |
sjallouli | 0:a948f5f3904c | 133 | set_connectable = FALSE; |
sjallouli | 0:a948f5f3904c | 134 | } |
sjallouli | 0:a948f5f3904c | 135 | } |
sjallouli | 0:a948f5f3904c | 136 | |
sjallouli | 0:a948f5f3904c | 137 | void setConnectable(void) |
sjallouli | 0:a948f5f3904c | 138 | { |
sjallouli | 0:a948f5f3904c | 139 | tBleStatus ret; |
sjallouli | 0:a948f5f3904c | 140 | |
sjallouli | 0:a948f5f3904c | 141 | const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G', '1', '2'}; |
sjallouli | 0:a948f5f3904c | 142 | |
sjallouli | 0:a948f5f3904c | 143 | /* disable scan response */ |
sjallouli | 0:a948f5f3904c | 144 | hci_le_set_scan_resp_data(0,NULL); |
sjallouli | 0:a948f5f3904c | 145 | |
sjallouli | 0:a948f5f3904c | 146 | |
sjallouli | 0:a948f5f3904c | 147 | ret = aci_gap_set_discoverable(ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE, |
sjallouli | 0:a948f5f3904c | 148 | 8, local_name, 0, NULL, 0, 0); |
sjallouli | 0:a948f5f3904c | 149 | |
sjallouli | 0:a948f5f3904c | 150 | } |
sjallouli | 0:a948f5f3904c | 151 | |
sjallouli | 0:a948f5f3904c | 152 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 153 | /*! |
sjallouli | 0:a948f5f3904c | 154 | @brief |
sjallouli | 0:a948f5f3904c | 155 | |
sjallouli | 0:a948f5f3904c | 156 | @param[in] p_ble_evt |
sjallouli | 0:a948f5f3904c | 157 | |
sjallouli | 0:a948f5f3904c | 158 | @returns |
sjallouli | 0:a948f5f3904c | 159 | */ |
sjallouli | 0:a948f5f3904c | 160 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 161 | static void btle_handler() |
sjallouli | 0:a948f5f3904c | 162 | { |
sjallouli | 0:a948f5f3904c | 163 | |
sjallouli | 0:a948f5f3904c | 164 | } |
sjallouli | 0:a948f5f3904c | 165 | |
sjallouli | 0:a948f5f3904c | 166 | |
sjallouli | 0:a948f5f3904c | 167 | void SPI_Poll(void) |
sjallouli | 0:a948f5f3904c | 168 | { |
sjallouli | 0:a948f5f3904c | 169 | //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); |
sjallouli | 0:a948f5f3904c | 170 | return; |
sjallouli | 0:a948f5f3904c | 171 | } |
sjallouli | 0:a948f5f3904c | 172 | |
sjallouli | 0:a948f5f3904c | 173 | #ifdef __cplusplus |
sjallouli | 0:a948f5f3904c | 174 | extern "C" { |
sjallouli | 0:a948f5f3904c | 175 | #endif |
sjallouli | 0:a948f5f3904c | 176 | |
sjallouli | 0:a948f5f3904c | 177 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 178 | /*! |
sjallouli | 0:a948f5f3904c | 179 | @brief Handle HCI Stack Event |
sjallouli | 0:a948f5f3904c | 180 | |
sjallouli | 0:a948f5f3904c | 181 | @param[in] pckt |
sjallouli | 0:a948f5f3904c | 182 | Event Packet sent by the stack to be decoded |
sjallouli | 0:a948f5f3904c | 183 | |
sjallouli | 0:a948f5f3904c | 184 | @returns |
sjallouli | 0:a948f5f3904c | 185 | */ |
sjallouli | 0:a948f5f3904c | 186 | /**************************************************************************/ |
sjallouli | 0:a948f5f3904c | 187 | extern void HCI_Event_CB(void *pckt) { |
sjallouli | 0:a948f5f3904c | 188 | |
sjallouli | 0:a948f5f3904c | 189 | hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; |
sjallouli | 0:a948f5f3904c | 190 | hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; |
sjallouli | 0:a948f5f3904c | 191 | |
sjallouli | 0:a948f5f3904c | 192 | if(hci_pckt->type != HCI_EVENT_PKT) |
sjallouli | 0:a948f5f3904c | 193 | return; |
sjallouli | 0:a948f5f3904c | 194 | |
fbd38 | 4:c8ed8022e996 | 195 | DEBUG("-->HCI Event %d\n\r", event_pckt->evt); |
fbd38 | 4:c8ed8022e996 | 196 | |
sjallouli | 0:a948f5f3904c | 197 | switch(event_pckt->evt){ |
sjallouli | 0:a948f5f3904c | 198 | |
sjallouli | 0:a948f5f3904c | 199 | case EVT_DISCONN_COMPLETE: |
sjallouli | 0:a948f5f3904c | 200 | { |
sjallouli | 0:a948f5f3904c | 201 | evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt; |
sjallouli | 0:a948f5f3904c | 202 | |
sjallouli | 0:a948f5f3904c | 203 | BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, BlueNRGGap::REMOTE_USER_TERMINATED_CONNECTION); |
sjallouli | 0:a948f5f3904c | 204 | } |
sjallouli | 0:a948f5f3904c | 205 | break; |
sjallouli | 0:a948f5f3904c | 206 | |
sjallouli | 0:a948f5f3904c | 207 | case EVT_LE_META_EVENT: |
sjallouli | 0:a948f5f3904c | 208 | { |
sjallouli | 0:a948f5f3904c | 209 | evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; |
sjallouli | 0:a948f5f3904c | 210 | |
sjallouli | 0:a948f5f3904c | 211 | switch(evt->subevent){ |
sjallouli | 0:a948f5f3904c | 212 | case EVT_LE_CONN_COMPLETE: |
sjallouli | 0:a948f5f3904c | 213 | { |
sjallouli | 0:a948f5f3904c | 214 | evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; |
sjallouli | 0:a948f5f3904c | 215 | |
sjallouli | 0:a948f5f3904c | 216 | BlueNRGGap::getInstance().setConnectionHandle(cc->handle); |
sjallouli | 0:a948f5f3904c | 217 | BlueNRGGap::ConnectionParams_t connectionParams; |
sjallouli | 0:a948f5f3904c | 218 | BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams); |
sjallouli | 0:a948f5f3904c | 219 | BlueNRGGap::getInstance().processConnectionEvent(cc->handle, (const BlueNRGGap::ConnectionParams_t *)&connectionParams); |
sjallouli | 0:a948f5f3904c | 220 | } |
sjallouli | 0:a948f5f3904c | 221 | break; |
sjallouli | 0:a948f5f3904c | 222 | } |
sjallouli | 0:a948f5f3904c | 223 | } |
sjallouli | 0:a948f5f3904c | 224 | break; |
sjallouli | 0:a948f5f3904c | 225 | |
sjallouli | 0:a948f5f3904c | 226 | case EVT_VENDOR: |
sjallouli | 0:a948f5f3904c | 227 | { |
sjallouli | 0:a948f5f3904c | 228 | evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; |
sjallouli | 0:a948f5f3904c | 229 | switch(blue_evt->ecode){ |
sjallouli | 0:a948f5f3904c | 230 | |
sjallouli | 0:a948f5f3904c | 231 | case EVT_BLUE_GATT_READ_PERMIT_REQ: |
sjallouli | 0:a948f5f3904c | 232 | { |
sjallouli | 0:a948f5f3904c | 233 | DEBUG("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); |
sjallouli | 0:a948f5f3904c | 234 | evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; |
sjallouli | 0:a948f5f3904c | 235 | BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle); |
sjallouli | 0:a948f5f3904c | 236 | } |
sjallouli | 0:a948f5f3904c | 237 | break; |
sjallouli | 0:a948f5f3904c | 238 | |
sjallouli | 0:a948f5f3904c | 239 | case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: |
sjallouli | 0:a948f5f3904c | 240 | { |
sjallouli | 0:a948f5f3904c | 241 | /* this callback is invoked when a GATT attribute is modified |
sjallouli | 0:a948f5f3904c | 242 | extract callback data and pass to suitable handler function */ |
sjallouli | 0:a948f5f3904c | 243 | evt_gatt_attr_modified *evt = (evt_gatt_attr_modified*)blue_evt->data; |
sjallouli | 0:a948f5f3904c | 244 | DEBUG("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); |
sjallouli | 0:a948f5f3904c | 245 | //DEBUG("CharHandle 0x%x, length: 0x%x, Data: 0x%x\n\r",evt->attr_handle, evt->data_length, (uint16_t)evt->att_data[0]); |
fbd38 | 4:c8ed8022e996 | 246 | DEBUG(" CharHandle %d, length: %d, Data: %d\n\r",evt->attr_handle, evt->data_length, (uint16_t)evt->att_data[0]); |
sjallouli | 0:a948f5f3904c | 247 | |
sjallouli | 0:a948f5f3904c | 248 | //Extract the GattCharacteristic from p_characteristics[] and find the properties mask |
sjallouli | 0:a948f5f3904c | 249 | GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(evt->attr_handle); |
sjallouli | 0:a948f5f3904c | 250 | if(p_char!=NULL) { |
fbd38 | 4:c8ed8022e996 | 251 | DEBUG(" getProperties 0x%x\n\r",p_char->getProperties()); |
sjallouli | 0:a948f5f3904c | 252 | if((p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
sjallouli | 0:a948f5f3904c | 253 | | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) { |
sjallouli | 0:a948f5f3904c | 254 | |
sjallouli | 0:a948f5f3904c | 255 | //Now Check if data written in Enable or Disable |
sjallouli | 0:a948f5f3904c | 256 | if((uint16_t)evt->att_data[0]==1) { |
sjallouli | 0:a948f5f3904c | 257 | //DEBUG("Notify ENABLED\n\r"); |
sjallouli | 0:a948f5f3904c | 258 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, evt->attr_handle); |
sjallouli | 0:a948f5f3904c | 259 | } |
sjallouli | 0:a948f5f3904c | 260 | else { |
sjallouli | 0:a948f5f3904c | 261 | //DEBUG("Notify DISABLED\n\r"); |
sjallouli | 0:a948f5f3904c | 262 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, evt->attr_handle); |
sjallouli | 0:a948f5f3904c | 263 | } |
sjallouli | 0:a948f5f3904c | 264 | } |
sjallouli | 0:a948f5f3904c | 265 | |
sjallouli | 0:a948f5f3904c | 266 | //Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event |
fbd38 | 4:c8ed8022e996 | 267 | |
fbd38 | 4:c8ed8022e996 | 268 | // if(( p_char->getProperties() & |
fbd38 | 4:c8ed8022e996 | 269 | // (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE| |
fbd38 | 4:c8ed8022e996 | 270 | // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE))) { |
fbd38 | 4:c8ed8022e996 | 271 | // DEBUG(" BLE WRITABLE !\n\r"); |
fbd38 | 3:89230b3e003b | 272 | |
fbd38 | 3:89230b3e003b | 273 | // Copy the Data to the Buffer |
fbd38 | 3:89230b3e003b | 274 | if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() >= evt->data_length)) { |
fbd38 | 4:c8ed8022e996 | 275 | uint8_t *dst, *src; |
fbd38 | 4:c8ed8022e996 | 276 | DEBUG("--> Copy SRC to DST\n\r"); |
fbd38 | 3:89230b3e003b | 277 | dst= p_char->getValueAttribute().getValuePtr(); |
fbd38 | 3:89230b3e003b | 278 | src = evt->att_data; |
fbd38 | 3:89230b3e003b | 279 | for(int i=0;i<evt->data_length;i++) dst[i]=src[i]; |
fbd38 | 4:c8ed8022e996 | 280 | // ---Pas Beau du tout |
fbd38 | 4:c8ed8022e996 | 281 | ctrl_byte = dst[0]; |
fbd38 | 3:89230b3e003b | 282 | } |
sjallouli | 0:a948f5f3904c | 283 | |
sjallouli | 0:a948f5f3904c | 284 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle); |
sjallouli | 0:a948f5f3904c | 285 | //Write the actual Data to the Attr Handle? (uint8_1[])evt->att_data contains the data |
sjallouli | 0:a948f5f3904c | 286 | if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() > 0)) { |
sjallouli | 0:a948f5f3904c | 287 | BlueNRGGattServer::getInstance().updateValue(p_char->getValueAttribute().getHandle(), |
sjallouli | 0:a948f5f3904c | 288 | p_char->getValueAttribute().getValuePtr(), p_char->getValueAttribute().getInitialLength(), false /* localOnly */); |
sjallouli | 0:a948f5f3904c | 289 | } |
fbd38 | 4:c8ed8022e996 | 290 | // } |
sjallouli | 0:a948f5f3904c | 291 | } |
sjallouli | 0:a948f5f3904c | 292 | } |
sjallouli | 0:a948f5f3904c | 293 | break; |
sjallouli | 0:a948f5f3904c | 294 | |
sjallouli | 0:a948f5f3904c | 295 | //Any cases for Data Sent Notifications? |
sjallouli | 0:a948f5f3904c | 296 | case EVT_BLUE_GATT_NOTIFICATION: |
sjallouli | 0:a948f5f3904c | 297 | //This is only relevant for Client Side Event |
sjallouli | 0:a948f5f3904c | 298 | DEBUG("EVT_BLUE_GATT_NOTIFICATION"); |
sjallouli | 0:a948f5f3904c | 299 | break; |
sjallouli | 0:a948f5f3904c | 300 | case EVT_BLUE_GATT_INDICATION: |
sjallouli | 0:a948f5f3904c | 301 | //This is only relevant for Client Side Event |
sjallouli | 0:a948f5f3904c | 302 | DEBUG("EVT_BLUE_GATT_INDICATION"); |
sjallouli | 0:a948f5f3904c | 303 | break; |
sjallouli | 0:a948f5f3904c | 304 | |
sjallouli | 0:a948f5f3904c | 305 | case EVT_BLUE_GATT_PROCEDURE_COMPLETE: |
sjallouli | 0:a948f5f3904c | 306 | DEBUG("EVT_BLUE_GATT_PROCEDURE_COMPLETE"); |
sjallouli | 0:a948f5f3904c | 307 | break; |
sjallouli | 0:a948f5f3904c | 308 | } |
sjallouli | 0:a948f5f3904c | 309 | } |
sjallouli | 0:a948f5f3904c | 310 | break; |
sjallouli | 0:a948f5f3904c | 311 | } |
sjallouli | 0:a948f5f3904c | 312 | |
sjallouli | 0:a948f5f3904c | 313 | return ; |
sjallouli | 0:a948f5f3904c | 314 | } |
sjallouli | 0:a948f5f3904c | 315 | |
sjallouli | 0:a948f5f3904c | 316 | |
sjallouli | 0:a948f5f3904c | 317 | #ifdef __cplusplus |
sjallouli | 0:a948f5f3904c | 318 | } |
sjallouli | 0:a948f5f3904c | 319 | #endif |