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

BroadcasterService.h

Committer:
alexanderlea
Date:
2015-03-12
Revision:
9:0ed64b14d46b
Parent:
8:3376f79e7d50
Child:
10:2c5c202c69a5

File content as of revision 9:0ed64b14d46b:

#ifndef __BLE_BROADCASTER_SERVICE_H__
#define __BLE_BROADCASTER_SERVICE_H__

#include "BLEDevice.h"

/**
* @class BroadcasterService
* @brief Based heavily on the BLE Battery Service, the aim is to send key, pair values <br>
*/
class BroadcasterService
{
public:
    /**
    * @param[ref] _ble
    *
    * @param[in]
    */
    
    const static uint16_t BROADCAST_SERVICE_UUID            = 0x2A67;
    const static uint16_t BROADCAST_CHARACTERISTIC_UUID     = 0x1817;
    
    BroadcasterService(BLEDevice &_ble) : //, uint8_t _command[8]
        ble(_ble),
        command(), //instead of command(_command);
        
        broadcasterCharacteristic(BROADCAST_CHARACTERISTIC_UUID, command, sizeof(command), sizeof(command),
                                  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
                                  // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE |
                                  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {

       
        static bool serviceAdded = false; /* We should only ever need to add the service once. */
        if (serviceAdded) {
            return;
        }

        GattCharacteristic *charTable[] = {&broadcasterCharacteristic};
        GattService         broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));

        ble.addService(broadcasterService);
        serviceAdded = true;
    }

    /**
     * @brief
     *
     * @param
     */
    void sendCommand(uint8_t _newCommand[8]) {
//        command = _newCommand;

        memcpy(command, _newCommand, sizeof(_newCommand));
        ble.updateCharacteristicValue(broadcasterCharacteristic.getValueAttribute().getHandle(), command, 8, false);
    }

private:
    BLEDevice               &ble;
    uint8_t                 command[8];    
    GattCharacteristic      broadcasterCharacteristic;
};

#endif