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

Dependencies:   BLE_API mbed nRF51822

Revision:
10:2c5c202c69a5
Child:
11:35b63ab4c76c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ErrorService.h	Sun Mar 22 17:47:11 2015 +0000
@@ -0,0 +1,67 @@
+#ifndef __BLE_ERROR_SERVICE_H__
+#define __BLE_ERROR_SERVICE_H__
+
+#include "BLEDevice.h"
+
+/**
+* @class BroadcasterService
+* @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 
+*/
+class ErrorService
+{
+    
+public:
+    enum {
+        ERROR_DISCONNECTION = 0x0000,
+        ERROR_ELECTRONIC = 0x0000,
+        ERROR_GENERIC = 0x0000,
+    };
+    /**
+    * @param[ref] _ble
+    *
+    * @param[in]
+    */
+    
+    const static uint16_t ERROR_SERVICE_UUID            = 0x2A69;
+    const static uint16_t ERROR_CHARACTERISTIC_UUID     = 0x1819;
+    
+    ErrorService(BLEDevice &_ble) : //, uint8_t _errorCode[8]
+        ble(_ble),
+        errorCode(), //instead of command(_command);
+        
+        errorCharacteristic(ERROR_CHARACTERISTIC_UUID, &errorCode, sizeof(errorCode), sizeof(errorCode),
+                                  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[] = {&errorCharacteristic};
+        GattService         errorService(ErrorService::ERROR_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+
+        ble.addService(errorService);
+        serviceAdded = true;
+    }
+
+    /**
+     * @brief
+     *
+     * @param
+     */
+    void registerError(uint8_t _errorCode) {
+        errorCode = _errorCode;
+ 
+        //memcpy(command, _newCommand, sizeof(_newCommand));
+        ble.updateCharacteristicValue(errorCharacteristic.getValueAttribute().getHandle(), &errorCode, sizeof(errorCode), false);
+    }
+
+private:
+    BLEDevice               &ble;
+    uint8_t                 errorCode;    
+    GattCharacteristic      errorCharacteristic;
+};
+
+#endif
\ No newline at end of file