Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_test1 by
BroadcasterService.h
00001 #ifndef __BLE_BROADCASTER_SERVICE_H__ 00002 #define __BLE_BROADCASTER_SERVICE_H__ 00003 00004 #include "BLEDevice.h" 00005 using namespace std; 00006 //http://ble-intros.readthedocs.org/en/latest/InDepth/BLEInDepth/ 00007 00008 00009 /** 00010 * @class BroadcasterService 00011 * @brief Based heavily on the BLE Battery Service, the aim is to send key, pair values <br>. 00012 * UPDATE: Should now be sending 8-byte string - 4 bytes for Type, 4 for command 00013 */ 00014 class BroadcasterService 00015 { 00016 public: 00017 00018 enum { 00019 ERROR_SERVER_DISCONNECTION = 0x1111, 00020 ERROR_ELECTRONIC_DSICONNECTION = 0x1222, 00021 ERROR_GENERIC = 0x1234, 00022 }; 00023 00024 const static uint16_t BROADCAST_SERVICE_UUID = 0x2A67; 00025 const static uint16_t BROADCAST_CHARACTERISTIC_UUID = 0x1817; 00026 const static uint16_t ERROR_CHARACTERISTIC_UUID = 0x1818; 00027 00028 BroadcasterService(BLEDevice &_ble) : 00029 ble(_ble), 00030 //define characteristics 00031 broadcasterCharacteristic(BROADCAST_CHARACTERISTIC_UUID, command, sizeof(command), sizeof(command), 00032 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | 00033 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00034 errorCharacteristic(ERROR_CHARACTERISTIC_UUID, &errorCode, sizeof(errorCode), sizeof(errorCode), 00035 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | 00036 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { 00037 00038 static bool serviceAdded = false; /* We should only ever need to add the service once. */ 00039 if (!serviceAdded) { 00040 00041 GattCharacteristic *charTable[] = {&broadcasterCharacteristic, &errorCharacteristic}; 00042 GattService broadcasterService(BroadcasterService::BROADCAST_SERVICE_UUID, charTable, 00043 sizeof(charTable) / sizeof(GattCharacteristic *)); 00044 00045 ble.addService(broadcasterService); 00046 serviceAdded = true; 00047 } 00048 } 00049 00050 /** 00051 * @brief 00052 * 00053 * @param 00054 */ 00055 void sendCommand (uint8_t _newCommand[8]) { 00056 memcpy(&command, &_newCommand, sizeof(_newCommand)); 00057 00058 ble.updateCharacteristicValue(broadcasterCharacteristic.getValueAttribute().getHandle(), command, sizeof(command), false); 00059 } 00060 00061 void registerError(uint8_t _errorCode) { 00062 errorCode = _errorCode; 00063 00064 ble.updateCharacteristicValue(errorCharacteristic.getValueAttribute().getHandle(), &errorCode, sizeof(errorCode), false); 00065 } 00066 00067 private: 00068 BLEDevice &ble; 00069 uint8_t command[8]; 00070 uint8_t errorCode; 00071 GattCharacteristic broadcasterCharacteristic; 00072 GattCharacteristic errorCharacteristic; 00073 }; 00074 00075 #endif
Generated on Sun Jul 17 2022 08:25:34 by
1.7.2
