Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_BlueNRG by
BlueNRGGattServer.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "BlueNRGGattServer.h" 00018 #include "mbed.h" 00019 #include "BlueNRGGap.h" 00020 00021 #define STORE_LE_16(buf, val) ( ((buf)[0] = (tHalUint8) (val) ) , \ 00022 ((buf)[1] = (tHalUint8) (val>>8) ) ) 00023 00024 #define STORE_LE_32(buf, val) ( ((buf)[0] = (tHalUint8) (val) ) , \ 00025 ((buf)[1] = (tHalUint8) (val>>8) ) , \ 00026 ((buf)[2] = (tHalUint8) (val>>16) ) , \ 00027 ((buf)[3] = (tHalUint8) (val>>24) ) ) 00028 00029 /**************************************************************************/ 00030 /*! 00031 @brief Adds a new service to the GATT table on the peripheral 00032 00033 @returns ble_error_t 00034 00035 @retval BLE_ERROR_NONE 00036 Everything executed properly 00037 00038 @section EXAMPLE 00039 00040 @code 00041 00042 @endcode 00043 */ 00044 /**************************************************************************/ 00045 ble_error_t BlueNRGGattServer::addService(GattService &service) 00046 { 00047 /* ToDo: Make sure we don't overflow the array, etc. */ 00048 /* ToDo: Make sure this service UUID doesn't already exist (?) */ 00049 /* ToDo: Basic validation */ 00050 00051 tBleStatus ret; 00052 00053 00054 /* Add the service to the BlueNRG */ 00055 uint16_t primary_uuid = (service.getUUID()).getShortUUID(); 00056 00057 ret = aci_gatt_add_serv(UUID_TYPE_16, (const uint8_t*)primary_uuid, PRIMARY_SERVICE, 7, 00058 &hrmServHandle); 00059 service.setHandle(hrmServHandle); 00060 00061 GattCharacteristic *p_char = service.getCharacteristic(0); 00062 uint16_t char_uuid = (p_char->getUUID()).getShortUUID(); 00063 ret = aci_gatt_add_char(service.getHandle(), UUID_TYPE_16, (const uint8_t*)char_uuid, 1, 00064 CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0, 00065 16, 0, &hrmCharHandle); 00066 00067 p_characteristics[characteristicCount++] = p_char; 00068 p_char->setHandle(hrmCharHandle); 00069 serviceCount++; 00070 00071 if ((p_char->getValuePtr() != NULL) && (p_char->getInitialLength() > 0)) { 00072 updateValue(hrmCharHandle, p_char->getValuePtr(), p_char->getInitialLength(), false /* localOnly */); 00073 } 00074 00075 return BLE_ERROR_NONE; 00076 } 00077 00078 /**************************************************************************/ 00079 /*! 00080 @brief Reads the value of a characteristic, based on the service 00081 and characteristic index fields 00082 00083 @param[in] charHandle 00084 The handle of the GattCharacteristic to read from 00085 @param[in] buffer 00086 Buffer to hold the the characteristic's value 00087 (raw byte array in LSB format) 00088 @param[in] len 00089 The number of bytes read into the buffer 00090 00091 @returns ble_error_t 00092 00093 @retval BLE_ERROR_NONE 00094 Everything executed properly 00095 00096 @section EXAMPLE 00097 00098 @code 00099 00100 @endcode 00101 */ 00102 /**************************************************************************/ 00103 ble_error_t BlueNRGGattServer::readValue(uint16_t charHandle, uint8_t buffer[], uint16_t *const lengthP) 00104 { 00105 00106 return BLE_ERROR_NONE; 00107 } 00108 00109 /**************************************************************************/ 00110 /*! 00111 @brief Updates the value of a characteristic, based on the service 00112 and characteristic index fields 00113 00114 @param[in] charHandle 00115 The handle of the GattCharacteristic to write to 00116 @param[in] buffer 00117 Data to use when updating the characteristic's value 00118 (raw byte array in LSB format) 00119 @param[in] len 00120 The number of bytes in buffer 00121 00122 @returns ble_error_t 00123 00124 @retval BLE_ERROR_NONE 00125 Everything executed properly 00126 00127 @section EXAMPLE 00128 00129 @code 00130 00131 @endcode 00132 */ 00133 /**************************************************************************/ 00134 ble_error_t BlueNRGGattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly) 00135 { 00136 tBleStatus ret; 00137 tHalUint8 buff[6]; 00138 00139 STORE_LE_16(buff,125); 00140 STORE_LE_16(buff+2,145); 00141 STORE_LE_16(buff+4,543); 00142 00143 ret = aci_gatt_update_char_value(hrmServHandle, charHandle, 0, 6, buff); 00144 00145 return BLE_ERROR_NONE; 00146 }
Generated on Tue Jul 12 2022 16:24:20 by
1.7.2
