Workings and tests to create custom GATT services, for use as part of peripheral communication in cars
Dependencies: BLE_API mbed nRF51822
BroadcasterService.h@10:2c5c202c69a5, 2015-03-22 (annotated)
- Committer:
- alexanderlea
- Date:
- Sun Mar 22 17:47:11 2015 +0000
- Revision:
- 10:2c5c202c69a5
- Parent:
- 9:0ed64b14d46b
- Child:
- 12:f5b12e8b6043
Added error service :)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexanderlea | 7:5c983cf3c352 | 1 | #ifndef __BLE_BROADCASTER_SERVICE_H__ |
alexanderlea | 7:5c983cf3c352 | 2 | #define __BLE_BROADCASTER_SERVICE_H__ |
alexanderlea | 0:af868ad47854 | 3 | |
alexanderlea | 0:af868ad47854 | 4 | #include "BLEDevice.h" |
alexanderlea | 0:af868ad47854 | 5 | |
alexanderlea | 0:af868ad47854 | 6 | /** |
alexanderlea | 7:5c983cf3c352 | 7 | * @class BroadcasterService |
alexanderlea | 10:2c5c202c69a5 | 8 | * @brief Based heavily on the BLE Battery Service, the aim is to send key, pair values <br>. UPDATE: Should now be sending 8-byte string - 4 bytes for |
alexanderlea | 0:af868ad47854 | 9 | */ |
alexanderlea | 7:5c983cf3c352 | 10 | class BroadcasterService |
alexanderlea | 7:5c983cf3c352 | 11 | { |
alexanderlea | 0:af868ad47854 | 12 | public: |
alexanderlea | 0:af868ad47854 | 13 | /** |
alexanderlea | 0:af868ad47854 | 14 | * @param[ref] _ble |
alexanderlea | 7:5c983cf3c352 | 15 | * |
alexanderlea | 7:5c983cf3c352 | 16 | * @param[in] |
alexanderlea | 0:af868ad47854 | 17 | */ |
alexanderlea | 8:3376f79e7d50 | 18 | |
alexanderlea | 8:3376f79e7d50 | 19 | const static uint16_t BROADCAST_SERVICE_UUID = 0x2A67; |
alexanderlea | 8:3376f79e7d50 | 20 | const static uint16_t BROADCAST_CHARACTERISTIC_UUID = 0x1817; |
alexanderlea | 8:3376f79e7d50 | 21 | |
alexanderlea | 9:0ed64b14d46b | 22 | BroadcasterService(BLEDevice &_ble) : //, uint8_t _command[8] |
alexanderlea | 0:af868ad47854 | 23 | ble(_ble), |
alexanderlea | 9:0ed64b14d46b | 24 | command(), //instead of command(_command); |
alexanderlea | 8:3376f79e7d50 | 25 | |
alexanderlea | 9:0ed64b14d46b | 26 | broadcasterCharacteristic(BROADCAST_CHARACTERISTIC_UUID, command, sizeof(command), sizeof(command), |
alexanderlea | 7:5c983cf3c352 | 27 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | |
alexanderlea | 7:5c983cf3c352 | 28 | // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | |
alexanderlea | 7:5c983cf3c352 | 29 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { |
alexanderlea | 10:2c5c202c69a5 | 30 | |
alexanderlea | 0:af868ad47854 | 31 | static bool serviceAdded = false; /* We should only ever need to add the service once. */ |
alexanderlea | 0:af868ad47854 | 32 | if (serviceAdded) { |
alexanderlea | 0:af868ad47854 | 33 | return; |
alexanderlea | 0:af868ad47854 | 34 | } |
alexanderlea | 0:af868ad47854 | 35 | |
alexanderlea | 4:ac0ee88ea0ed | 36 | GattCharacteristic *charTable[] = {&broadcasterCharacteristic}; |
alexanderlea | 8:3376f79e7d50 | 37 | GattService broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
alexanderlea | 0:af868ad47854 | 38 | |
alexanderlea | 4:ac0ee88ea0ed | 39 | ble.addService(broadcasterService); |
alexanderlea | 0:af868ad47854 | 40 | serviceAdded = true; |
alexanderlea | 0:af868ad47854 | 41 | } |
alexanderlea | 0:af868ad47854 | 42 | |
alexanderlea | 0:af868ad47854 | 43 | /** |
alexanderlea | 7:5c983cf3c352 | 44 | * @brief |
alexanderlea | 0:af868ad47854 | 45 | * |
alexanderlea | 7:5c983cf3c352 | 46 | * @param |
alexanderlea | 0:af868ad47854 | 47 | */ |
alexanderlea | 9:0ed64b14d46b | 48 | void sendCommand(uint8_t _newCommand[8]) { |
alexanderlea | 9:0ed64b14d46b | 49 | // command = _newCommand; |
alexanderlea | 10:2c5c202c69a5 | 50 | |
alexanderlea | 9:0ed64b14d46b | 51 | memcpy(command, _newCommand, sizeof(_newCommand)); |
alexanderlea | 10:2c5c202c69a5 | 52 | ble.updateCharacteristicValue(broadcasterCharacteristic.getValueAttribute().getHandle(), command, sizeof(command), false); |
alexanderlea | 0:af868ad47854 | 53 | } |
alexanderlea | 0:af868ad47854 | 54 | |
alexanderlea | 0:af868ad47854 | 55 | private: |
alexanderlea | 9:0ed64b14d46b | 56 | BLEDevice &ble; |
alexanderlea | 9:0ed64b14d46b | 57 | uint8_t command[8]; |
alexanderlea | 9:0ed64b14d46b | 58 | GattCharacteristic broadcasterCharacteristic; |
alexanderlea | 0:af868ad47854 | 59 | }; |
alexanderlea | 0:af868ad47854 | 60 | |
alexanderlea | 7:5c983cf3c352 | 61 | #endif |