Workings and tests to create custom GATT services, for use as part of peripheral communication in cars

Dependencies:   BLE_API mbed nRF51822

Committer:
alexanderlea
Date:
Fri Mar 27 12:21:12 2015 +0000
Revision:
12:f5b12e8b6043
Parent:
11:35b63ab4c76c
Switch input and BLE working correctly :)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexanderlea 10:2c5c202c69a5 1 #ifndef __BLE_ERROR_SERVICE_H__
alexanderlea 10:2c5c202c69a5 2 #define __BLE_ERROR_SERVICE_H__
alexanderlea 10:2c5c202c69a5 3
alexanderlea 10:2c5c202c69a5 4 #include "BLEDevice.h"
alexanderlea 10:2c5c202c69a5 5
alexanderlea 10:2c5c202c69a5 6 /**
alexanderlea 10:2c5c202c69a5 7 * @class BroadcasterService
alexanderlea 12:f5b12e8b6043 8 * @brief Based heavily on the BLE Battery Services
alexanderlea 10:2c5c202c69a5 9 */
alexanderlea 10:2c5c202c69a5 10 class ErrorService
alexanderlea 10:2c5c202c69a5 11 {
alexanderlea 10:2c5c202c69a5 12
alexanderlea 10:2c5c202c69a5 13 public:
alexanderlea 10:2c5c202c69a5 14 enum {
alexanderlea 12:f5b12e8b6043 15 ERROR_SERVER_DISCONNECTION = 0x1234,
alexanderlea 12:f5b12e8b6043 16 ERROR_ELECTRONIC_DSICONNECTION = 0x1221,
alexanderlea 11:35b63ab4c76c 17 ERROR_GENERIC = 0x4321,
alexanderlea 10:2c5c202c69a5 18 };
alexanderlea 10:2c5c202c69a5 19 /**
alexanderlea 10:2c5c202c69a5 20 * @param[ref] _ble
alexanderlea 10:2c5c202c69a5 21 *
alexanderlea 10:2c5c202c69a5 22 * @param[in]
alexanderlea 10:2c5c202c69a5 23 */
alexanderlea 10:2c5c202c69a5 24
alexanderlea 10:2c5c202c69a5 25 const static uint16_t ERROR_SERVICE_UUID = 0x2A69;
alexanderlea 10:2c5c202c69a5 26 const static uint16_t ERROR_CHARACTERISTIC_UUID = 0x1819;
alexanderlea 10:2c5c202c69a5 27
alexanderlea 10:2c5c202c69a5 28 ErrorService(BLEDevice &_ble) : //, uint8_t _errorCode[8]
alexanderlea 10:2c5c202c69a5 29 ble(_ble),
alexanderlea 10:2c5c202c69a5 30 errorCode(), //instead of command(_command);
alexanderlea 10:2c5c202c69a5 31
alexanderlea 10:2c5c202c69a5 32 errorCharacteristic(ERROR_CHARACTERISTIC_UUID, &errorCode, sizeof(errorCode), sizeof(errorCode),
alexanderlea 10:2c5c202c69a5 33 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
alexanderlea 10:2c5c202c69a5 34 // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE |
alexanderlea 10:2c5c202c69a5 35 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
alexanderlea 10:2c5c202c69a5 36
alexanderlea 10:2c5c202c69a5 37 static bool serviceAdded = false; /* We should only ever need to add the service once. */
alexanderlea 10:2c5c202c69a5 38 if (serviceAdded) {
alexanderlea 10:2c5c202c69a5 39 return;
alexanderlea 10:2c5c202c69a5 40 }
alexanderlea 10:2c5c202c69a5 41
alexanderlea 10:2c5c202c69a5 42 GattCharacteristic *charTable[] = {&errorCharacteristic};
alexanderlea 10:2c5c202c69a5 43 GattService errorService(ErrorService::ERROR_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
alexanderlea 10:2c5c202c69a5 44
alexanderlea 10:2c5c202c69a5 45 ble.addService(errorService);
alexanderlea 10:2c5c202c69a5 46 serviceAdded = true;
alexanderlea 10:2c5c202c69a5 47 }
alexanderlea 10:2c5c202c69a5 48
alexanderlea 10:2c5c202c69a5 49 /**
alexanderlea 10:2c5c202c69a5 50 * @brief
alexanderlea 10:2c5c202c69a5 51 *
alexanderlea 10:2c5c202c69a5 52 * @param
alexanderlea 10:2c5c202c69a5 53 */
alexanderlea 10:2c5c202c69a5 54 void registerError(uint8_t _errorCode) {
alexanderlea 10:2c5c202c69a5 55 errorCode = _errorCode;
alexanderlea 10:2c5c202c69a5 56
alexanderlea 10:2c5c202c69a5 57 //memcpy(command, _newCommand, sizeof(_newCommand));
alexanderlea 10:2c5c202c69a5 58 ble.updateCharacteristicValue(errorCharacteristic.getValueAttribute().getHandle(), &errorCode, sizeof(errorCode), false);
alexanderlea 10:2c5c202c69a5 59 }
alexanderlea 10:2c5c202c69a5 60
alexanderlea 10:2c5c202c69a5 61 private:
alexanderlea 10:2c5c202c69a5 62 BLEDevice &ble;
alexanderlea 10:2c5c202c69a5 63 uint8_t errorCode;
alexanderlea 10:2c5c202c69a5 64 GattCharacteristic errorCharacteristic;
alexanderlea 10:2c5c202c69a5 65 };
alexanderlea 10:2c5c202c69a5 66
alexanderlea 10:2c5c202c69a5 67 #endif