Dissertation project, looking at BLE communication in cars. This project is BLE peripheral acting as car indicator stalk

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_GATT_test1 by Alexander Lea

Committer:
alexanderlea
Date:
Thu Mar 12 12:52:26 2015 +0000
Revision:
9:0ed64b14d46b
Parent:
8:3376f79e7d50
Child:
10:2c5c202c69a5
Changed to deal with int arrays rather than int values :)

Who changed what in which revision?

UserRevisionLine numberNew 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 7:5c983cf3c352 8 * @brief Based heavily on the BLE Battery Service, the aim is to send key, pair values <br>
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 0:af868ad47854 30
alexanderlea 8:3376f79e7d50 31
alexanderlea 0:af868ad47854 32 static bool serviceAdded = false; /* We should only ever need to add the service once. */
alexanderlea 0:af868ad47854 33 if (serviceAdded) {
alexanderlea 0:af868ad47854 34 return;
alexanderlea 0:af868ad47854 35 }
alexanderlea 0:af868ad47854 36
alexanderlea 4:ac0ee88ea0ed 37 GattCharacteristic *charTable[] = {&broadcasterCharacteristic};
alexanderlea 8:3376f79e7d50 38 GattService broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
alexanderlea 0:af868ad47854 39
alexanderlea 4:ac0ee88ea0ed 40 ble.addService(broadcasterService);
alexanderlea 0:af868ad47854 41 serviceAdded = true;
alexanderlea 0:af868ad47854 42 }
alexanderlea 0:af868ad47854 43
alexanderlea 0:af868ad47854 44 /**
alexanderlea 7:5c983cf3c352 45 * @brief
alexanderlea 0:af868ad47854 46 *
alexanderlea 7:5c983cf3c352 47 * @param
alexanderlea 0:af868ad47854 48 */
alexanderlea 9:0ed64b14d46b 49 void sendCommand(uint8_t _newCommand[8]) {
alexanderlea 9:0ed64b14d46b 50 // command = _newCommand;
alexanderlea 9:0ed64b14d46b 51
alexanderlea 9:0ed64b14d46b 52 memcpy(command, _newCommand, sizeof(_newCommand));
alexanderlea 9:0ed64b14d46b 53 ble.updateCharacteristicValue(broadcasterCharacteristic.getValueAttribute().getHandle(), command, 8, false);
alexanderlea 0:af868ad47854 54 }
alexanderlea 0:af868ad47854 55
alexanderlea 0:af868ad47854 56 private:
alexanderlea 9:0ed64b14d46b 57 BLEDevice &ble;
alexanderlea 9:0ed64b14d46b 58 uint8_t command[8];
alexanderlea 9:0ed64b14d46b 59 GattCharacteristic broadcasterCharacteristic;
alexanderlea 0:af868ad47854 60 };
alexanderlea 0:af868ad47854 61
alexanderlea 7:5c983cf3c352 62 #endif