prova invio BLE
Dependents: BLE_HeartRate_IDB04A1
Fork of BLE_API by
ble/services/DeviceInformationService.h@1179:4ab722f8dca0, 2016-04-06 (annotated)
- Committer:
- vcoubard
- Date:
- Wed Apr 06 19:15:30 2016 +0100
- Revision:
- 1179:4ab722f8dca0
- Parent:
- 1156:e1ea38b576c6
- Child:
- 1183:1589830dbdb7
Synchronized with git rev ca632aaf
Author: Andres Amaya Garcia
Update Gap state after advertising times out
The BLE API was not updating the Gap internal state when the advertising stops
because of a user timeout. This commit fixes the issue by updating the internal
state structure in Gap just before the registered callbacks are notified of the
advertising timeout.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1151:575efbdcc905 | 1 | /* mbed Microcontroller Library |
vcoubard | 1151:575efbdcc905 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 1151:575efbdcc905 | 3 | * |
vcoubard | 1151:575efbdcc905 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1151:575efbdcc905 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1151:575efbdcc905 | 6 | * You may obtain a copy of the License at |
vcoubard | 1151:575efbdcc905 | 7 | * |
vcoubard | 1151:575efbdcc905 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1151:575efbdcc905 | 9 | * |
vcoubard | 1151:575efbdcc905 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1151:575efbdcc905 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1151:575efbdcc905 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1151:575efbdcc905 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1151:575efbdcc905 | 14 | * limitations under the License. |
vcoubard | 1151:575efbdcc905 | 15 | */ |
vcoubard | 1151:575efbdcc905 | 16 | |
vcoubard | 1151:575efbdcc905 | 17 | #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ |
vcoubard | 1151:575efbdcc905 | 18 | #define __BLE_DEVICE_INFORMATION_SERVICE_H__ |
vcoubard | 1151:575efbdcc905 | 19 | |
vcoubard | 1151:575efbdcc905 | 20 | #include "ble/BLE.h" |
vcoubard | 1151:575efbdcc905 | 21 | |
vcoubard | 1151:575efbdcc905 | 22 | /** |
vcoubard | 1151:575efbdcc905 | 23 | * @class DeviceInformationService |
vcoubard | 1151:575efbdcc905 | 24 | * @brief BLE Device Information Service |
vcoubard | 1151:575efbdcc905 | 25 | * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml |
vcoubard | 1151:575efbdcc905 | 26 | * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml |
vcoubard | 1151:575efbdcc905 | 27 | */ |
vcoubard | 1151:575efbdcc905 | 28 | class DeviceInformationService { |
vcoubard | 1151:575efbdcc905 | 29 | public: |
vcoubard | 1151:575efbdcc905 | 30 | /** |
vcoubard | 1179:4ab722f8dca0 | 31 | * @brief Device Information Service Constructor: copies device-specific information |
vcoubard | 1151:575efbdcc905 | 32 | * into the BLE stack. |
vcoubard | 1151:575efbdcc905 | 33 | * |
vcoubard | 1179:4ab722f8dca0 | 34 | * @param[ref] _ble |
vcoubard | 1179:4ab722f8dca0 | 35 | * BLE object for the underlying controller. |
vcoubard | 1151:575efbdcc905 | 36 | * @param[in] manufacturersName |
vcoubard | 1151:575efbdcc905 | 37 | * The name of the manufacturer of the device. |
vcoubard | 1151:575efbdcc905 | 38 | * @param[in] modelNumber |
vcoubard | 1151:575efbdcc905 | 39 | * The model number that is assigned by the device vendor. |
vcoubard | 1151:575efbdcc905 | 40 | * @param[in] serialNumber |
vcoubard | 1179:4ab722f8dca0 | 41 | * The serial number for a particular instance of the device. |
vcoubard | 1151:575efbdcc905 | 42 | * @param[in] hardwareRevision |
vcoubard | 1151:575efbdcc905 | 43 | * The hardware revision for the hardware within the device. |
vcoubard | 1151:575efbdcc905 | 44 | * @param[in] firmwareRevision |
vcoubard | 1179:4ab722f8dca0 | 45 | * The device's firmware version. |
vcoubard | 1151:575efbdcc905 | 46 | * @param[in] softwareRevision |
vcoubard | 1151:575efbdcc905 | 47 | * The device's software version. |
vcoubard | 1151:575efbdcc905 | 48 | */ |
vcoubard | 1151:575efbdcc905 | 49 | DeviceInformationService(BLE &_ble, |
vcoubard | 1151:575efbdcc905 | 50 | const char *manufacturersName = NULL, |
vcoubard | 1151:575efbdcc905 | 51 | const char *modelNumber = NULL, |
vcoubard | 1151:575efbdcc905 | 52 | const char *serialNumber = NULL, |
vcoubard | 1151:575efbdcc905 | 53 | const char *hardwareRevision = NULL, |
vcoubard | 1151:575efbdcc905 | 54 | const char *firmwareRevision = NULL, |
vcoubard | 1151:575efbdcc905 | 55 | const char *softwareRevision = NULL) : |
vcoubard | 1151:575efbdcc905 | 56 | ble(_ble), |
vcoubard | 1151:575efbdcc905 | 57 | manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 58 | (uint8_t *)manufacturersName, |
vcoubard | 1151:575efbdcc905 | 59 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 60 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 61 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
vcoubard | 1151:575efbdcc905 | 62 | modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 63 | (uint8_t *)modelNumber, |
vcoubard | 1151:575efbdcc905 | 64 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 65 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 66 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
vcoubard | 1151:575efbdcc905 | 67 | serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 68 | (uint8_t *)serialNumber, |
vcoubard | 1151:575efbdcc905 | 69 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 70 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 71 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
vcoubard | 1151:575efbdcc905 | 72 | hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 73 | (uint8_t *)hardwareRevision, |
vcoubard | 1151:575efbdcc905 | 74 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 75 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 76 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
vcoubard | 1151:575efbdcc905 | 77 | firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 78 | (uint8_t *)firmwareRevision, |
vcoubard | 1151:575efbdcc905 | 79 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 80 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 81 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
vcoubard | 1151:575efbdcc905 | 82 | softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, |
vcoubard | 1151:575efbdcc905 | 83 | (uint8_t *)softwareRevision, |
vcoubard | 1151:575efbdcc905 | 84 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Min length */ |
vcoubard | 1151:575efbdcc905 | 85 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Max length */ |
vcoubard | 1151:575efbdcc905 | 86 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) |
vcoubard | 1151:575efbdcc905 | 87 | { |
vcoubard | 1151:575efbdcc905 | 88 | static bool serviceAdded = false; /* We only add the information service once. */ |
vcoubard | 1151:575efbdcc905 | 89 | if (serviceAdded) { |
vcoubard | 1151:575efbdcc905 | 90 | return; |
vcoubard | 1151:575efbdcc905 | 91 | } |
vcoubard | 1151:575efbdcc905 | 92 | |
vcoubard | 1151:575efbdcc905 | 93 | GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, |
vcoubard | 1151:575efbdcc905 | 94 | &modelNumberStringCharacteristic, |
vcoubard | 1151:575efbdcc905 | 95 | &serialNumberStringCharacteristic, |
vcoubard | 1151:575efbdcc905 | 96 | &hardwareRevisionStringCharacteristic, |
vcoubard | 1151:575efbdcc905 | 97 | &firmwareRevisionStringCharacteristic, |
vcoubard | 1151:575efbdcc905 | 98 | &softwareRevisionStringCharacteristic}; |
vcoubard | 1151:575efbdcc905 | 99 | GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, |
vcoubard | 1151:575efbdcc905 | 100 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
vcoubard | 1151:575efbdcc905 | 101 | |
vcoubard | 1151:575efbdcc905 | 102 | ble.addService(deviceInformationService); |
vcoubard | 1151:575efbdcc905 | 103 | serviceAdded = true; |
vcoubard | 1151:575efbdcc905 | 104 | } |
vcoubard | 1151:575efbdcc905 | 105 | |
vcoubard | 1151:575efbdcc905 | 106 | protected: |
vcoubard | 1151:575efbdcc905 | 107 | BLE &ble; |
vcoubard | 1151:575efbdcc905 | 108 | GattCharacteristic manufacturersNameStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 109 | GattCharacteristic modelNumberStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 110 | GattCharacteristic serialNumberStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 111 | GattCharacteristic hardwareRevisionStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 112 | GattCharacteristic firmwareRevisionStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 113 | GattCharacteristic softwareRevisionStringCharacteristic; |
vcoubard | 1151:575efbdcc905 | 114 | }; |
vcoubard | 1151:575efbdcc905 | 115 | |
rgrover1 | 712:b04b5db36865 | 116 | #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/ |