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
Diff: BroadcasterService.h
- Revision:
- 15:ad1d37e51a26
- Parent:
- 14:7225b50aaaf7
- Child:
- 18:867625bb5000
--- a/BroadcasterService.h Thu Apr 09 14:48:35 2015 +0000 +++ b/BroadcasterService.h Tue Apr 14 15:57:47 2015 +0000 @@ -12,33 +12,37 @@ class BroadcasterService { public: - /** - * @param[ref] _ble - * - * @param[in] - */ + + enum { + ERROR_SERVER_DISCONNECTION = 0x1234, + ERROR_ELECTRONIC_DSICONNECTION = 0x1221, + ERROR_GENERIC = 0x4321, + }; + const static uint16_t BROADCAST_SERVICE_UUID = 0x2A67; const static uint16_t BROADCAST_CHARACTERISTIC_UUID = 0x1817; + const static uint16_t ERROR_CHARACTERISTIC_UUID = 0x1818; BroadcasterService(BLEDevice &_ble) : ble(_ble), - //command(), //instead of command(_command); - + //define characteristics broadcasterCharacteristic(BROADCAST_CHARACTERISTIC_UUID, command, sizeof(command), sizeof(command), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + errorCharacteristic(ERROR_CHARACTERISTIC_UUID, &errorCode, sizeof(errorCode), sizeof(errorCode), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { static bool serviceAdded = false; /* We should only ever need to add the service once. */ - if (serviceAdded) { - return; + if (!serviceAdded) { + + GattCharacteristic *charTable[] = {&broadcasterCharacteristic, &errorCharacteristic}; + GattService broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, + sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(broadcasterService); + serviceAdded = true; } - - GattCharacteristic *charTable[] = {&broadcasterCharacteristic}; - GattService broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, - sizeof(charTable) / sizeof(GattCharacteristic *)); - - ble.addService(broadcasterService); - serviceAdded = true; } /** @@ -47,16 +51,23 @@ * @param */ void sendCommand(uint8_t _newCommand[8]) { -// command = _newCommand; - //std::copy_n(_newCommand, sizeof(_newCommand), command); memcpy(&command, &_newCommand, sizeof(_newCommand)); + ble.updateCharacteristicValue(broadcasterCharacteristic.getValueAttribute().getHandle(), command, sizeof(command), false); } + + void registerError(uint8_t _errorCode) { + errorCode = _errorCode; + + ble.updateCharacteristicValue(errorCharacteristic.getValueAttribute().getHandle(), &errorCode, sizeof(errorCode), false); + } private: BLEDevice &ble; uint8_t command[8]; + uint8_t errorCode; GattCharacteristic broadcasterCharacteristic; + GattCharacteristic errorCharacteristic; }; #endif \ No newline at end of file