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.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_test1 by
TestGattService.h@3:f3d20b36b7ea, 2015-02-17 (annotated)
- Committer:
- alexanderlea
- Date:
- Tue Feb 17 13:57:28 2015 +0000
- Revision:
- 3:f3d20b36b7ea
- Parent:
- 1:ebdf445c4bcc
Working as pretend battery status node
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| alexanderlea | 0:af868ad47854 | 1 | #ifndef __BLE_TEST_SERVICE_H__ | 
| alexanderlea | 0:af868ad47854 | 2 | #define __BLE_TEST_SERVICE_H__ | 
| alexanderlea | 0:af868ad47854 | 3 | |
| alexanderlea | 0:af868ad47854 | 4 | #include "BLEDevice.h" | 
| alexanderlea | 0:af868ad47854 | 5 | |
| alexanderlea | 0:af868ad47854 | 6 | /** | 
| alexanderlea | 0:af868ad47854 | 7 | * @class BatteryService | 
| alexanderlea | 0:af868ad47854 | 8 | * @brief BLE Battery Service. This service displays the battery level from 0%->100% represented as a 8bit number.<br> | 
| alexanderlea | 0:af868ad47854 | 9 | * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml <br> | 
| alexanderlea | 0:af868ad47854 | 10 | * Battery Level Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.battery_level.xml | 
| alexanderlea | 0:af868ad47854 | 11 | */ | 
| alexanderlea | 0:af868ad47854 | 12 | class TestGattService { | 
| alexanderlea | 0:af868ad47854 | 13 | public: | 
| alexanderlea | 0:af868ad47854 | 14 | /** | 
| alexanderlea | 0:af868ad47854 | 15 | * @param[ref] _ble | 
| alexanderlea | 1:ebdf445c4bcc | 16 | * | 
| alexanderlea | 1:ebdf445c4bcc | 17 | * @param[in] | 
| alexanderlea | 0:af868ad47854 | 18 | */ | 
| alexanderlea | 1:ebdf445c4bcc | 19 | TestGattService(BLEDevice &_ble, uint8_t _command) : | 
| alexanderlea | 0:af868ad47854 | 20 | ble(_ble), | 
| alexanderlea | 1:ebdf445c4bcc | 21 | command(_command), | 
| alexanderlea | 1:ebdf445c4bcc | 22 | testCharacteristic(0x2A67, &command, sizeof(command), sizeof(command), | 
| alexanderlea | 1:ebdf445c4bcc | 23 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | | 
| alexanderlea | 3:f3d20b36b7ea | 24 | // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | | 
| alexanderlea | 1:ebdf445c4bcc | 25 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { | 
| alexanderlea | 0:af868ad47854 | 26 | |
| alexanderlea | 0:af868ad47854 | 27 | static bool serviceAdded = false; /* We should only ever need to add the service once. */ | 
| alexanderlea | 0:af868ad47854 | 28 | if (serviceAdded) { | 
| alexanderlea | 0:af868ad47854 | 29 | return; | 
| alexanderlea | 0:af868ad47854 | 30 | } | 
| alexanderlea | 0:af868ad47854 | 31 | |
| alexanderlea | 0:af868ad47854 | 32 | GattCharacteristic *charTable[] = {&testCharacteristic}; | 
| alexanderlea | 0:af868ad47854 | 33 | GattService testService(0x1817, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); | 
| alexanderlea | 0:af868ad47854 | 34 | |
| alexanderlea | 0:af868ad47854 | 35 | ble.addService(testService); | 
| alexanderlea | 0:af868ad47854 | 36 | serviceAdded = true; | 
| alexanderlea | 0:af868ad47854 | 37 | } | 
| alexanderlea | 0:af868ad47854 | 38 | |
| alexanderlea | 0:af868ad47854 | 39 | /** | 
| alexanderlea | 1:ebdf445c4bcc | 40 | * @brief | 
| alexanderlea | 0:af868ad47854 | 41 | * | 
| alexanderlea | 1:ebdf445c4bcc | 42 | * @param | 
| alexanderlea | 0:af868ad47854 | 43 | */ | 
| alexanderlea | 1:ebdf445c4bcc | 44 | void sendCommand(uint8_t _newCommand) { | 
| alexanderlea | 1:ebdf445c4bcc | 45 | command = _newCommand; | 
| alexanderlea | 1:ebdf445c4bcc | 46 | ble.updateCharacteristicValue(testCharacteristic.getValueAttribute().getHandle(), &command, 1); | 
| alexanderlea | 0:af868ad47854 | 47 | } | 
| alexanderlea | 0:af868ad47854 | 48 | |
| alexanderlea | 0:af868ad47854 | 49 | private: | 
| alexanderlea | 0:af868ad47854 | 50 | BLEDevice &ble; | 
| alexanderlea | 1:ebdf445c4bcc | 51 | uint8_t command; | 
| alexanderlea | 0:af868ad47854 | 52 | GattCharacteristic testCharacteristic; | 
| alexanderlea | 0:af868ad47854 | 53 | }; | 
| alexanderlea | 0:af868ad47854 | 54 | |
| alexanderlea | 0:af868ad47854 | 55 | #endif /* #ifndef __BLE_TEST_SERVICE_H__*/ | 
